From 51d569de7d8b45749286a3eb09061f312b472c83 Mon Sep 17 00:00:00 2001 From: Philipp Dobrigkeit Date: Wed, 23 Apr 2014 13:59:58 +0200 Subject: [PATCH] Bump dependancy to ZfcUser to 1.* Prepare Refactorings to be able to add tests --- README.md | 6 +-- config/goalioforgotpassword.global.php.dist | 2 +- config/module.config.php | 4 +- .../Form/ForgotFilter.php | 2 +- .../Form/Service/ForgotFactory.php | 26 ++++++++++++ .../Form/Service/ResetFactory.php | 18 +++++++++ .../Mapper/Service/PasswordFactory.php | 21 ++++++++++ src/GoalioForgotPassword/Module.php | 40 +++---------------- .../Options/Service/ModuleOptionsFactory.php | 15 +++++++ .../Util/ServiceManagerFactory.php | 40 +++++++++++++++++++ tests/bootstrap.php | 20 ++++++++++ tests/configuration.php.dist | 12 ++++++ tests/phpunit.xml | 26 ++++++++++++ tests/testing.config.php | 14 +++++++ 14 files changed, 203 insertions(+), 43 deletions(-) create mode 100644 src/GoalioForgotPassword/Form/Service/ForgotFactory.php create mode 100644 src/GoalioForgotPassword/Form/Service/ResetFactory.php create mode 100644 src/GoalioForgotPassword/Mapper/Service/PasswordFactory.php create mode 100644 src/GoalioForgotPassword/Options/Service/ModuleOptionsFactory.php create mode 100644 tests/GoalioForgotPasswordTest/Util/ServiceManagerFactory.php create mode 100644 tests/bootstrap.php create mode 100644 tests/configuration.php.dist create mode 100644 tests/phpunit.xml create mode 100644 tests/testing.config.php diff --git a/README.md b/README.md index 714d3c1..4bfca59 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ GoalioForgotPassword ==================== -Version 0.1.3 Created by the goalio UG (haftungsbeschränkt) +Version 1.0.0 Created by the goalio UG (haftungsbeschränkt) Introduction ------------ @@ -39,11 +39,11 @@ Installation ```json "require": { - "goalio/goalio-forgotpassword": "0.*" + "goalio/goalio-forgotpassword": "1.*" } ``` -2. Now tell composer to download ZfcUser by running the command: +2. Now tell composer to download GoalioForgotPassword by running the command: ```bash $ php composer.phar update diff --git a/config/goalioforgotpassword.global.php.dist b/config/goalioforgotpassword.global.php.dist index b2a73d8..dd86a81 100644 --- a/config/goalioforgotpassword.global.php.dist +++ b/config/goalioforgotpassword.global.php.dist @@ -57,7 +57,7 @@ $settings = array( * Accepted values: the number of seconds the user should be allowed to change his password */ //'reset_expire' => 86400, - + /** * Validate that given e-mail exists in db * diff --git a/config/module.config.php b/config/module.config.php index 7f3c8ad..8d1bc49 100644 --- a/config/module.config.php +++ b/config/module.config.php @@ -13,10 +13,8 @@ 'goalioforgotpassword_forgot' => 'GoalioForgotPassword\Controller\ForgotController', ), ), + 'translator' => array( - // Change you locale here if needed, and uncomment line below with 'locale' setting. - // Don't forget to create your own translation! See ../language directory. - // 'locale' => 'en_US', 'translation_file_patterns' => array( array( 'type' => 'gettext', diff --git a/src/GoalioForgotPassword/Form/ForgotFilter.php b/src/GoalioForgotPassword/Form/ForgotFilter.php index 3bce89c..93067cd 100644 --- a/src/GoalioForgotPassword/Form/ForgotFilter.php +++ b/src/GoalioForgotPassword/Form/ForgotFilter.php @@ -40,7 +40,7 @@ public function __construct( $emailValidator, ForgotOptionsInterface $options) /** * set options * - * @param RegistrationOptionsInterface $options + * @param ForgotOptionsInterface $options */ public function setOptions(ForgotOptionsInterface $options) { diff --git a/src/GoalioForgotPassword/Form/Service/ForgotFactory.php b/src/GoalioForgotPassword/Form/Service/ForgotFactory.php new file mode 100644 index 0000000..dc9a716 --- /dev/null +++ b/src/GoalioForgotPassword/Form/Service/ForgotFactory.php @@ -0,0 +1,26 @@ +get('goalioforgotpassword_module_options'); + $form = new Forgot(null, $options); + $validator = new \ZfcUser\Validator\RecordExists(array( + 'mapper' => $serviceLocator->get('zfcuser_user_mapper'), + 'key' => 'email' + )); + + $translator = $serviceLocator->get('Translator'); + + $validator->setMessage($translator->translate('The email address you entered was not found.')); + $form->setInputFilter(new ForgotFilter($validator,$options)); + return $form; + } + +} \ No newline at end of file diff --git a/src/GoalioForgotPassword/Form/Service/ResetFactory.php b/src/GoalioForgotPassword/Form/Service/ResetFactory.php new file mode 100644 index 0000000..1032522 --- /dev/null +++ b/src/GoalioForgotPassword/Form/Service/ResetFactory.php @@ -0,0 +1,18 @@ +get('goalioforgotpassword_module_options'); + $form = new Reset(null, $options); + $form->setInputFilter(new ResetFilter($options)); + return $form; + } + +} \ No newline at end of file diff --git a/src/GoalioForgotPassword/Mapper/Service/PasswordFactory.php b/src/GoalioForgotPassword/Mapper/Service/PasswordFactory.php new file mode 100644 index 0000000..0d14ea5 --- /dev/null +++ b/src/GoalioForgotPassword/Mapper/Service/PasswordFactory.php @@ -0,0 +1,21 @@ +get('goalioforgotpassword_module_options'); + $mapper = new Password(); + $mapper->setDbAdapter($serviceLocator->get('zfcuser_zend_db_adapter')); + $entityClass = $options->getPasswordEntityClass(); + $mapper->setEntityPrototype(new $entityClass); + $mapper->setHydrator(new PasswordHydrator()); + return $mapper; + } + +} \ No newline at end of file diff --git a/src/GoalioForgotPassword/Module.php b/src/GoalioForgotPassword/Module.php index 6f0ff48..f90ff74 100644 --- a/src/GoalioForgotPassword/Module.php +++ b/src/GoalioForgotPassword/Module.php @@ -22,7 +22,7 @@ public function getConfig() { } public function getModuleDependencies() { - return array('ZfcUser', 'ZfcBase'); + return array('ZfcUser', 'ZfcBase'); } public function getServiceConfig() { @@ -32,40 +32,10 @@ public function getServiceConfig() { ), 'factories' => array( - - 'goalioforgotpassword_module_options' => function ($sm) { - $config = $sm->get('Config'); - return new Options\ModuleOptions(isset($config['goalioforgotpassword']) ? $config['goalioforgotpassword'] : array()); - }, - - 'goalioforgotpassword_forgot_form' => function($sm) { - $options = $sm->get('goalioforgotpassword_module_options'); - $form = new Form\Forgot(null, $options); - $validator = new \ZfcUser\Validator\RecordExists(array( - 'mapper' => $sm->get('zfcuser_user_mapper'), - 'key' => 'email' - )); - $validator->setMessage('The email address you entered was not found.'); - $form->setInputFilter(new Form\ForgotFilter($validator,$options)); - return $form; - }, - - 'goalioforgotpassword_reset_form' => function($sm) { - $options = $sm->get('goalioforgotpassword_module_options'); - $form = new Form\Reset(null, $options); - $form->setInputFilter(new Form\ResetFilter($options)); - return $form; - }, - - 'goalioforgotpassword_password_mapper' => function ($sm) { - $options = $sm->get('goalioforgotpassword_module_options'); - $mapper = new Mapper\Password; - $mapper->setDbAdapter($sm->get('zfcuser_zend_db_adapter')); - $entityClass = $options->getPasswordEntityClass(); - $mapper->setEntityPrototype(new $entityClass); - $mapper->setHydrator(new Mapper\PasswordHydrator()); - return $mapper; - }, + 'goalioforgotpassword_module_options' => 'GoalioForgotPassword\Options\Service\ModuleOptionsFactory', + 'goalioforgotpassword_forgot_form' => 'GoalioForgotPassword\Form\Service\ForgotFactory', + 'goalioforgotpassword_reset_form' => 'GoalioForgotPassword\Form\Service\ResetFactory', + 'goalioforgotpassword_password_mapper' => 'GoalioForgotPassword\Mapper\Service\PasswordFactory', ), ); } diff --git a/src/GoalioForgotPassword/Options/Service/ModuleOptionsFactory.php b/src/GoalioForgotPassword/Options/Service/ModuleOptionsFactory.php new file mode 100644 index 0000000..ccb1b24 --- /dev/null +++ b/src/GoalioForgotPassword/Options/Service/ModuleOptionsFactory.php @@ -0,0 +1,15 @@ +get('Config'); + return new ModuleOptions(isset($config['goalioforgotpassword']) ? $config['goalioforgotpassword'] : array()); + } + +} \ No newline at end of file diff --git a/tests/GoalioForgotPasswordTest/Util/ServiceManagerFactory.php b/tests/GoalioForgotPasswordTest/Util/ServiceManagerFactory.php new file mode 100644 index 0000000..8638b58 --- /dev/null +++ b/tests/GoalioForgotPasswordTest/Util/ServiceManagerFactory.php @@ -0,0 +1,40 @@ +setService('ApplicationConfig', static::$config); + $serviceManager->setFactory('ServiceListener', 'Zend\Mvc\Service\ServiceListenerFactory'); + + /** @var $moduleManager \Zend\ModuleManager\ModuleManager */ + $moduleManager = $serviceManager->get('ModuleManager'); + $moduleManager->loadModules(); + //$serviceManager->setAllowOverride(true); + return $serviceManager; + } +} \ No newline at end of file diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 0000000..d07ab3e --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,20 @@ +add('GoalioForgotPasswordTest', __DIR__); + +if (!$config = @include 'configuration.php') { + $config = require 'configuration.php.dist'; +} + +\GoalioForgotPasswordTest\Util\ServiceManagerFactory::setConfig($config); diff --git a/tests/configuration.php.dist b/tests/configuration.php.dist new file mode 100644 index 0000000..e33db91 --- /dev/null +++ b/tests/configuration.php.dist @@ -0,0 +1,12 @@ + array( + 'GoalioMailService' + ), + 'module_listener_options' => array( + 'config_glob_paths' => array( + __DIR__ . '/testing.config.php', + ), + 'module_paths' => array(), + ), +); \ No newline at end of file diff --git a/tests/phpunit.xml b/tests/phpunit.xml new file mode 100644 index 0000000..3b295d6 --- /dev/null +++ b/tests/phpunit.xml @@ -0,0 +1,26 @@ + + + ./GoalioForgotPasswordTest + + + + + ../src + + + + + + + + diff --git a/tests/testing.config.php b/tests/testing.config.php new file mode 100644 index 0000000..a6b56be --- /dev/null +++ b/tests/testing.config.php @@ -0,0 +1,14 @@ + array( + 'invokables' => array( + 'goalioforgotpassword_password_service' => 'GoalioForgotPassword\Service\Password', + ), + 'factories' => array( + 'goalioforgotpassword_module_options' => 'GoalioForgotPassword\Options\Service\ModuleOptionsFactory', + 'goalioforgotpassword_forgot_form' => 'GoalioForgotPassword\Form\Service\ForgotFactory', + 'goalioforgotpassword_reset_form' => 'GoalioForgotPassword\Form\Service\ResetFactory', + 'goalioforgotpassword_password_mapper' => 'GoalioForgotPassword\Mapper\Service\PasswordFactory', + ), + ), +); \ No newline at end of file