Skip to content

Commit

Permalink
Bump dependancy to ZfcUser to 1.*
Browse files Browse the repository at this point in the history
Prepare Refactorings to be able to add tests
  • Loading branch information
pdobrigkeit committed Apr 23, 2014
1 parent 138cf97 commit 51d569d
Show file tree
Hide file tree
Showing 14 changed files with 203 additions and 43 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
------------
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion config/goalioforgotpassword.global.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
4 changes: 1 addition & 3 deletions config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion src/GoalioForgotPassword/Form/ForgotFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function __construct( $emailValidator, ForgotOptionsInterface $options)
/**
* set options
*
* @param RegistrationOptionsInterface $options
* @param ForgotOptionsInterface $options
*/
public function setOptions(ForgotOptionsInterface $options)
{
Expand Down
26 changes: 26 additions & 0 deletions src/GoalioForgotPassword/Form/Service/ForgotFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
namespace GoalioForgotPassword\Form\Service;

use GoalioForgotPassword\Form\Forgot;
use GoalioForgotPassword\Form\ForgotFilter;
use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\ServiceManager\FactoryInterface;

class ForgotFactory implements FactoryInterface {

public function createService(ServiceLocatorInterface $serviceLocator) {
$options = $serviceLocator->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;
}

}
18 changes: 18 additions & 0 deletions src/GoalioForgotPassword/Form/Service/ResetFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
namespace GoalioForgotPassword\Form\Service;

use GoalioForgotPassword\Form\Reset;
use GoalioForgotPassword\Form\ResetFilter;
use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\ServiceManager\FactoryInterface;

class ForgotFactory implements FactoryInterface {

public function createService(ServiceLocatorInterface $serviceLocator) {
$options = $serviceLocator->get('goalioforgotpassword_module_options');
$form = new Reset(null, $options);
$form->setInputFilter(new ResetFilter($options));
return $form;
}

}
21 changes: 21 additions & 0 deletions src/GoalioForgotPassword/Mapper/Service/PasswordFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
namespace GoalioForgotPassword\Mapper\Service;

use GoalioForgotPassword\Mapper\Password;
use GoalioForgotPassword\Mapper\PasswordHydrator;
use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\ServiceManager\FactoryInterface;

class PasswordFactory implements FactoryInterface {

public function createService(ServiceLocatorInterface $serviceLocator) {
$options = $serviceLocator->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;
}

}
40 changes: 5 additions & 35 deletions src/GoalioForgotPassword/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function getConfig() {
}

public function getModuleDependencies() {
return array('ZfcUser', 'ZfcBase');
return array('ZfcUser', 'ZfcBase');
}

public function getServiceConfig() {
Expand All @@ -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',
),
);
}
Expand Down
15 changes: 15 additions & 0 deletions src/GoalioForgotPassword/Options/Service/ModuleOptionsFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
namespace GoalioForgotPassword\Options\Service;

use GoalioForgotPassword\Options\ModuleOptions;
use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\ServiceManager\FactoryInterface;

class ModuleOptionsFactory implements FactoryInterface {

public function createService(ServiceLocatorInterface $serviceLocator) {
$config = $serviceLocator->get('Config');
return new ModuleOptions(isset($config['goalioforgotpassword']) ? $config['goalioforgotpassword'] : array());
}

}
40 changes: 40 additions & 0 deletions tests/GoalioForgotPasswordTest/Util/ServiceManagerFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace GoalioForgotPasswordTest\Util;

use Zend\ServiceManager\ServiceManager;
use Zend\Mvc\Service\ServiceManagerConfig;

class ServiceManagerFactory
{
/**
* @var array
*/
protected static $config;

/**
* @param array $config
*/
public static function setConfig(array $config)
{
static::$config = $config;
}

/**
* Builds a new service manager
*/
public static function getServiceManager()
{
$serviceManager = new ServiceManager(new ServiceManagerConfig(
isset(static::$config['service_manager']) ? static::$config['service_manager'] : array()
));
$serviceManager->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;
}
}
20 changes: 20 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

chdir(__DIR__);

$loader = null;
if (file_exists('../vendor/autoload.php')) {
$loader = include '../vendor/autoload.php';
} elseif (file_exists('../../../autoload.php')) {
$loader = include '../../../autoload.php';
} else {
throw new RuntimeException('vendor/autoload.php could not be found. Did you run `php composer.phar install`?');
}

$loader->add('GoalioForgotPasswordTest', __DIR__);

if (!$config = @include 'configuration.php') {
$config = require 'configuration.php.dist';
}

\GoalioForgotPasswordTest\Util\ServiceManagerFactory::setConfig($config);
12 changes: 12 additions & 0 deletions tests/configuration.php.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
return array(
'modules' => array(
'GoalioMailService'
),
'module_listener_options' => array(
'config_glob_paths' => array(
__DIR__ . '/testing.config.php',
),
'module_paths' => array(),
),
);
26 changes: 26 additions & 0 deletions tests/phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<phpunit bootstrap="./bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
verbose="true"
stopOnFailure="false"
processIsolation="false"
backupGlobals="false"
syntaxCheck="true"
>
<testsuite name="GoalioForgotPassword Test Suite">
<directory>./GoalioForgotPasswordTest</directory>
</testsuite>

<filter>
<whitelist>
<directory suffix=".php">../src</directory>
</whitelist>
</filter>

<logging>
<log type="coverage-text" target="php://stdout"/>
<log type="coverage-clover" target="../build/logs/clover.xml"/>
</logging>
</phpunit>
14 changes: 14 additions & 0 deletions tests/testing.config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
return array(
'service_manager' => 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',
),
),
);

0 comments on commit 51d569d

Please sign in to comment.