From c1f1cd2d57b67f2d2975f1bf30f09c3e437aa49e Mon Sep 17 00:00:00 2001 From: Romain BASTIDE Date: Sat, 11 Feb 2023 00:35:19 +0100 Subject: [PATCH 1/5] Switch to PSR-4 and move classes accordingly #35 --- Module.php | 117 +----------------- composer.json | 18 +-- phpunit.xml.dist | 4 +- .../Adapter/AbstractAdapter.php | 0 .../Authentication/Adapter/AdapterChain.php | 0 .../Adapter/AdapterChainEvent.php | 0 .../Adapter/AdapterChainServiceFactory.php | 0 .../Adapter/ChainableAdapter.php | 0 .../Authentication/Adapter/Db.php | 0 .../Exception/OptionsNotFoundException.php | 0 .../Authentication/Storage/Db.php | 0 .../Plugin/LmcUserAuthentication.php | 0 .../Controller/RedirectCallback.php | 0 .../Controller/UserController.php | 0 .../Db/Adapter/MasterSlaveAdapter.php | 0 .../Adapter/MasterSlaveAdapterInterface.php | 0 src/{LmcUser => }/Entity/User.php | 0 src/{LmcUser => }/Entity/UserInterface.php | 0 .../EventManager/EventProvider.php | 0 .../AuthenticationEventException.php | 0 .../Exception/DomainException.php | 0 .../Exception/ExceptionInterface.php | 0 .../Authentication/Adapter/DbFactory.php | 0 .../Authentication/Storage/DbFactory.php | 0 .../Factory/AuthenticationService.php | 0 .../Plugin/LmcUserAuthentication.php | 0 .../Controller/RedirectCallbackFactory.php | 0 .../Controller/UserControllerFactory.php | 0 .../Factory/Form/ChangeEmail.php | 0 .../Factory/Form/ChangePassword.php | 0 src/{LmcUser => }/Factory/Form/Login.php | 0 src/{LmcUser => }/Factory/Form/Register.php | 0 src/{LmcUser => }/Factory/Mapper/User.php | 0 .../Factory/Options/ModuleOptions.php | 0 .../Factory/Service/UserFactory.php | 0 src/{LmcUser => }/Factory/UserHydrator.php | 0 .../View/Helper/LmcUserDisplayName.php | 0 .../Factory/View/Helper/LmcUserIdentity.php | 0 .../View/Helper/LmcUserLoginWidget.php | 0 src/{LmcUser => }/Form/Base.php | 0 src/{LmcUser => }/Form/ChangeEmail.php | 0 src/{LmcUser => }/Form/ChangeEmailFilter.php | 0 src/{LmcUser => }/Form/ChangePassword.php | 0 .../Form/ChangePasswordFilter.php | 0 src/{LmcUser => }/Form/Login.php | 0 src/{LmcUser => }/Form/LoginFilter.php | 0 src/{LmcUser => }/Form/ProvidesEventsForm.php | 0 src/{LmcUser => }/Form/Register.php | 0 src/{LmcUser => }/Form/RegisterFilter.php | 0 .../InputFilter/ProvidesEventsInputFilter.php | 0 src/{LmcUser => }/Mapper/AbstractDbMapper.php | 0 .../Mapper/Exception/ExceptionInterface.php | 0 .../Exception/InvalidArgumentException.php | 0 .../Mapper/Exception/RuntimeException.php | 0 src/{LmcUser => }/Mapper/User.php | 0 src/{LmcUser => }/Mapper/UserHydrator.php | 0 src/{LmcUser => }/Mapper/UserInterface.php | 0 src/Module.php | 116 +++++++++++++++++ .../AuthenticationOptionsInterface.php | 0 src/{LmcUser => }/Options/ModuleOptions.php | 0 .../Options/PasswordOptionsInterface.php | 0 .../Options/RegistrationOptionsInterface.php | 0 .../UserControllerOptionsInterface.php | 0 .../Options/UserServiceOptionsInterface.php | 0 .../Service/Exception/ExceptionInterface.php | 0 .../Exception/InvalidArgumentException.php | 0 src/{LmcUser => }/Service/User.php | 0 .../Validator/AbstractRecord.php | 0 .../Exception/ExceptionInterface.php | 0 .../Exception/InvalidArgumentException.php | 0 .../Validator/NoRecordExists.php | 0 src/{LmcUser => }/Validator/RecordExists.php | 0 .../View/Helper/LmcUserDisplayName.php | 0 .../View/Helper/LmcUserIdentity.php | 0 .../View/Helper/LmcUserLoginWidget.php | 0 src/{LmcUser => }/language/cs_CZ.mo | Bin src/{LmcUser => }/language/cs_CZ.po | 0 src/{LmcUser => }/language/de_DE.mo | Bin src/{LmcUser => }/language/de_DE.po | 0 src/{LmcUser => }/language/es_ES.mo | Bin src/{LmcUser => }/language/es_ES.po | 0 src/{LmcUser => }/language/fr_FR.mo | Bin src/{LmcUser => }/language/fr_FR.po | 0 src/{LmcUser => }/language/ja_JP.mo | Bin src/{LmcUser => }/language/ja_JP.po | 0 src/{LmcUser => }/language/msgIds.php | 0 src/{LmcUser => }/language/nl_NL.mo | Bin src/{LmcUser => }/language/nl_NL.po | 0 src/{LmcUser => }/language/pl_PL.mo | Bin src/{LmcUser => }/language/pl_PL.po | 0 src/{LmcUser => }/language/pt_BR.mo | Bin src/{LmcUser => }/language/pt_BR.po | 0 src/{LmcUser => }/language/ru_RU.mo | Bin src/{LmcUser => }/language/ru_RU.po | 0 .../Adapter/AbstractAdapterTest.php | 0 .../Adapter/AdapterChainEventTest.php | 0 .../AdapterChainServiceFactoryTest.php | 0 .../Adapter/AdapterChainTest.php | 0 .../Authentication/Adapter/DbTest.php | 0 .../TestAsset/AbstractAdapterExtension.php | 0 .../Adapter/TestAsset/InvalidUserClass.php | 0 .../Authentication/Storage/DbTest.php | 0 .../Plugin/LmcUserAuthenticationTest.php | 0 .../Controller/RedirectCallbackTest.php | 0 .../Controller/UserControllerTest.php | 0 tests/{LmcUserTest => }/Entity/UserTest.php | 0 .../Form/ChangeEmailFormFactoryTest.php | 0 .../Form/ChangePasswordFormFactoryTest.php | 0 .../Factory/Form/LoginFormFactoryTest.php | 0 .../Factory/Form/RegisterFormFactoryTest.php | 0 .../Factory/Mapper/UserMapperFactoryTest.php | 0 tests/{LmcUserTest => }/Form/BaseTest.php | 0 .../Form/ChangeEmailFilterTest.php | 0 .../Form/ChangeEmailTest.php | 0 .../Form/ChangePasswordFilterTest.php | 0 .../Form/ChangePasswordTest.php | 0 .../Form/LoginFilterTest.php | 0 tests/{LmcUserTest => }/Form/LoginTest.php | 0 .../Form/RegisterFilterTest.php | 0 tests/{LmcUserTest => }/Form/RegisterTest.php | 0 .../Mapper/UserHydratorTest.php | 0 tests/{LmcUserTest => }/Mapper/UserTest.php | 0 .../{LmcUserTest => }/Mapper/_files/user.sql | 0 tests/{LmcUserTest => }/ModuleTest.php | 0 .../Options/ModuleOptionsTest.php | 0 tests/{LmcUserTest => }/Service/UserTest.php | 0 .../Validator/AbstractRecordTest.php | 0 .../Validator/NoRecordExistsTest.php | 0 .../Validator/RecordExistsTest.php | 0 .../TestAsset/AbstractRecordExtension.php | 0 .../View/Helper/LmcUserDisplayNameTest.php | 0 .../View/Helper/LmcUserIdentityTest.php | 0 .../View/Helper/LmcUserLoginWidgetTest.php | 0 133 files changed, 132 insertions(+), 123 deletions(-) rename src/{LmcUser => }/Authentication/Adapter/AbstractAdapter.php (100%) rename src/{LmcUser => }/Authentication/Adapter/AdapterChain.php (100%) rename src/{LmcUser => }/Authentication/Adapter/AdapterChainEvent.php (100%) rename src/{LmcUser => }/Authentication/Adapter/AdapterChainServiceFactory.php (100%) rename src/{LmcUser => }/Authentication/Adapter/ChainableAdapter.php (100%) rename src/{LmcUser => }/Authentication/Adapter/Db.php (100%) rename src/{LmcUser => }/Authentication/Adapter/Exception/OptionsNotFoundException.php (100%) rename src/{LmcUser => }/Authentication/Storage/Db.php (100%) rename src/{LmcUser => }/Controller/Plugin/LmcUserAuthentication.php (100%) rename src/{LmcUser => }/Controller/RedirectCallback.php (100%) rename src/{LmcUser => }/Controller/UserController.php (100%) rename src/{LmcUser => }/Db/Adapter/MasterSlaveAdapter.php (100%) rename src/{LmcUser => }/Db/Adapter/MasterSlaveAdapterInterface.php (100%) rename src/{LmcUser => }/Entity/User.php (100%) rename src/{LmcUser => }/Entity/UserInterface.php (100%) rename src/{LmcUser => }/EventManager/EventProvider.php (100%) rename src/{LmcUser => }/Exception/AuthenticationEventException.php (100%) rename src/{LmcUser => }/Exception/DomainException.php (100%) rename src/{LmcUser => }/Exception/ExceptionInterface.php (100%) rename src/{LmcUser => }/Factory/Authentication/Adapter/DbFactory.php (100%) rename src/{LmcUser => }/Factory/Authentication/Storage/DbFactory.php (100%) rename src/{LmcUser => }/Factory/AuthenticationService.php (100%) rename src/{LmcUser => }/Factory/Controller/Plugin/LmcUserAuthentication.php (100%) rename src/{LmcUser => }/Factory/Controller/RedirectCallbackFactory.php (100%) rename src/{LmcUser => }/Factory/Controller/UserControllerFactory.php (100%) rename src/{LmcUser => }/Factory/Form/ChangeEmail.php (100%) rename src/{LmcUser => }/Factory/Form/ChangePassword.php (100%) rename src/{LmcUser => }/Factory/Form/Login.php (100%) rename src/{LmcUser => }/Factory/Form/Register.php (100%) rename src/{LmcUser => }/Factory/Mapper/User.php (100%) rename src/{LmcUser => }/Factory/Options/ModuleOptions.php (100%) rename src/{LmcUser => }/Factory/Service/UserFactory.php (100%) rename src/{LmcUser => }/Factory/UserHydrator.php (100%) rename src/{LmcUser => }/Factory/View/Helper/LmcUserDisplayName.php (100%) rename src/{LmcUser => }/Factory/View/Helper/LmcUserIdentity.php (100%) rename src/{LmcUser => }/Factory/View/Helper/LmcUserLoginWidget.php (100%) rename src/{LmcUser => }/Form/Base.php (100%) rename src/{LmcUser => }/Form/ChangeEmail.php (100%) rename src/{LmcUser => }/Form/ChangeEmailFilter.php (100%) rename src/{LmcUser => }/Form/ChangePassword.php (100%) rename src/{LmcUser => }/Form/ChangePasswordFilter.php (100%) rename src/{LmcUser => }/Form/Login.php (100%) rename src/{LmcUser => }/Form/LoginFilter.php (100%) rename src/{LmcUser => }/Form/ProvidesEventsForm.php (100%) rename src/{LmcUser => }/Form/Register.php (100%) rename src/{LmcUser => }/Form/RegisterFilter.php (100%) rename src/{LmcUser => }/InputFilter/ProvidesEventsInputFilter.php (100%) rename src/{LmcUser => }/Mapper/AbstractDbMapper.php (100%) rename src/{LmcUser => }/Mapper/Exception/ExceptionInterface.php (100%) rename src/{LmcUser => }/Mapper/Exception/InvalidArgumentException.php (100%) rename src/{LmcUser => }/Mapper/Exception/RuntimeException.php (100%) rename src/{LmcUser => }/Mapper/User.php (100%) rename src/{LmcUser => }/Mapper/UserHydrator.php (100%) rename src/{LmcUser => }/Mapper/UserInterface.php (100%) create mode 100644 src/Module.php rename src/{LmcUser => }/Options/AuthenticationOptionsInterface.php (100%) rename src/{LmcUser => }/Options/ModuleOptions.php (100%) rename src/{LmcUser => }/Options/PasswordOptionsInterface.php (100%) rename src/{LmcUser => }/Options/RegistrationOptionsInterface.php (100%) rename src/{LmcUser => }/Options/UserControllerOptionsInterface.php (100%) rename src/{LmcUser => }/Options/UserServiceOptionsInterface.php (100%) rename src/{LmcUser => }/Service/Exception/ExceptionInterface.php (100%) rename src/{LmcUser => }/Service/Exception/InvalidArgumentException.php (100%) rename src/{LmcUser => }/Service/User.php (100%) rename src/{LmcUser => }/Validator/AbstractRecord.php (100%) rename src/{LmcUser => }/Validator/Exception/ExceptionInterface.php (100%) rename src/{LmcUser => }/Validator/Exception/InvalidArgumentException.php (100%) rename src/{LmcUser => }/Validator/NoRecordExists.php (100%) rename src/{LmcUser => }/Validator/RecordExists.php (100%) rename src/{LmcUser => }/View/Helper/LmcUserDisplayName.php (100%) rename src/{LmcUser => }/View/Helper/LmcUserIdentity.php (100%) rename src/{LmcUser => }/View/Helper/LmcUserLoginWidget.php (100%) rename src/{LmcUser => }/language/cs_CZ.mo (100%) rename src/{LmcUser => }/language/cs_CZ.po (100%) rename src/{LmcUser => }/language/de_DE.mo (100%) rename src/{LmcUser => }/language/de_DE.po (100%) rename src/{LmcUser => }/language/es_ES.mo (100%) rename src/{LmcUser => }/language/es_ES.po (100%) rename src/{LmcUser => }/language/fr_FR.mo (100%) rename src/{LmcUser => }/language/fr_FR.po (100%) rename src/{LmcUser => }/language/ja_JP.mo (100%) rename src/{LmcUser => }/language/ja_JP.po (100%) rename src/{LmcUser => }/language/msgIds.php (100%) rename src/{LmcUser => }/language/nl_NL.mo (100%) rename src/{LmcUser => }/language/nl_NL.po (100%) rename src/{LmcUser => }/language/pl_PL.mo (100%) rename src/{LmcUser => }/language/pl_PL.po (100%) rename src/{LmcUser => }/language/pt_BR.mo (100%) rename src/{LmcUser => }/language/pt_BR.po (100%) rename src/{LmcUser => }/language/ru_RU.mo (100%) rename src/{LmcUser => }/language/ru_RU.po (100%) rename tests/{LmcUserTest => }/Authentication/Adapter/AbstractAdapterTest.php (100%) rename tests/{LmcUserTest => }/Authentication/Adapter/AdapterChainEventTest.php (100%) rename tests/{LmcUserTest => }/Authentication/Adapter/AdapterChainServiceFactoryTest.php (100%) rename tests/{LmcUserTest => }/Authentication/Adapter/AdapterChainTest.php (100%) rename tests/{LmcUserTest => }/Authentication/Adapter/DbTest.php (100%) rename tests/{LmcUserTest => }/Authentication/Adapter/TestAsset/AbstractAdapterExtension.php (100%) rename tests/{LmcUserTest => }/Authentication/Adapter/TestAsset/InvalidUserClass.php (100%) rename tests/{LmcUserTest => }/Authentication/Storage/DbTest.php (100%) rename tests/{LmcUserTest => }/Controller/Plugin/LmcUserAuthenticationTest.php (100%) rename tests/{LmcUserTest => }/Controller/RedirectCallbackTest.php (100%) rename tests/{LmcUserTest => }/Controller/UserControllerTest.php (100%) rename tests/{LmcUserTest => }/Entity/UserTest.php (100%) rename tests/{LmcUserTest => }/Factory/Form/ChangeEmailFormFactoryTest.php (100%) rename tests/{LmcUserTest => }/Factory/Form/ChangePasswordFormFactoryTest.php (100%) rename tests/{LmcUserTest => }/Factory/Form/LoginFormFactoryTest.php (100%) rename tests/{LmcUserTest => }/Factory/Form/RegisterFormFactoryTest.php (100%) rename tests/{LmcUserTest => }/Factory/Mapper/UserMapperFactoryTest.php (100%) rename tests/{LmcUserTest => }/Form/BaseTest.php (100%) rename tests/{LmcUserTest => }/Form/ChangeEmailFilterTest.php (100%) rename tests/{LmcUserTest => }/Form/ChangeEmailTest.php (100%) rename tests/{LmcUserTest => }/Form/ChangePasswordFilterTest.php (100%) rename tests/{LmcUserTest => }/Form/ChangePasswordTest.php (100%) rename tests/{LmcUserTest => }/Form/LoginFilterTest.php (100%) rename tests/{LmcUserTest => }/Form/LoginTest.php (100%) rename tests/{LmcUserTest => }/Form/RegisterFilterTest.php (100%) rename tests/{LmcUserTest => }/Form/RegisterTest.php (100%) rename tests/{LmcUserTest => }/Mapper/UserHydratorTest.php (100%) rename tests/{LmcUserTest => }/Mapper/UserTest.php (100%) rename tests/{LmcUserTest => }/Mapper/_files/user.sql (100%) rename tests/{LmcUserTest => }/ModuleTest.php (100%) rename tests/{LmcUserTest => }/Options/ModuleOptionsTest.php (100%) rename tests/{LmcUserTest => }/Service/UserTest.php (100%) rename tests/{LmcUserTest => }/Validator/AbstractRecordTest.php (100%) rename tests/{LmcUserTest => }/Validator/NoRecordExistsTest.php (100%) rename tests/{LmcUserTest => }/Validator/RecordExistsTest.php (100%) rename tests/{LmcUserTest => }/Validator/TestAsset/AbstractRecordExtension.php (100%) rename tests/{LmcUserTest => }/View/Helper/LmcUserDisplayNameTest.php (100%) rename tests/{LmcUserTest => }/View/Helper/LmcUserIdentityTest.php (100%) rename tests/{LmcUserTest => }/View/Helper/LmcUserLoginWidgetTest.php (100%) diff --git a/Module.php b/Module.php index d1b2743..36b7790 100644 --- a/Module.php +++ b/Module.php @@ -1,116 +1,7 @@ [ - 'lmcUserAuthentication' => Factory\Controller\Plugin\LmcUserAuthentication::class, - ], - ]; - } - - /** - * {@inheritDoc} - * @see \Laminas\ModuleManager\Feature\ControllerProviderInterface::getControllerConfig() - */ - public function getControllerConfig() - { - return [ - 'factories' => [ - 'lmcuser' => Factory\Controller\UserControllerFactory::class, - ], - ]; - } - - /** - * {@inheritDoc} - * @see \Laminas\ModuleManager\Feature\ViewHelperProviderInterface::getViewHelperConfig() - */ - public function getViewHelperConfig() - { - return [ - 'factories' => [ - 'lmcUserDisplayName' => Factory\View\Helper\LmcUserDisplayName::class, - 'lmcUserIdentity' => Factory\View\Helper\LmcUserIdentity::class, - 'lmcUserLoginWidget' => Factory\View\Helper\LmcUserLoginWidget::class, - ], - ]; - } - - /** - * {@inheritDoc} - * @see \Laminas\ModuleManager\Feature\ServiceProviderInterface::getServiceConfig() - */ - public function getServiceConfig() - { - return [ - 'aliases' => [ - 'lmcuser_laminas_db_adapter' => \Laminas\Db\Adapter\Adapter::class, - 'lmcuser_register_form_hydrator' => 'lmcuser_user_hydrator', - 'lmcuser_base_hydrator' => 'lmcuser_default_hydrator', - ], - 'invokables' => [ - 'lmcuser_default_hydrator' => ClassMethodsHydrator::class, - ], - 'factories' => [ - 'lmcuser_redirect_callback' => Factory\Controller\RedirectCallbackFactory::class, - 'lmcuser_module_options' => Factory\Options\ModuleOptions::class, - Authentication\Adapter\AdapterChain::class => Authentication\Adapter\AdapterChainServiceFactory::class, - - // We alias this one because it's LmcUser's instance of - // Laminas\Authentication\AuthenticationService. We don't want to - // hog the FQCN service alias for a Laminas\* class. - 'lmcuser_auth_service' => Factory\AuthenticationService::class, - - 'lmcuser_user_hydrator' => Factory\UserHydrator::class, - 'lmcuser_user_mapper' => Factory\Mapper\User::class, - - 'lmcuser_login_form' => Factory\Form\Login::class, - 'lmcuser_register_form' => Factory\Form\Register::class, - 'lmcuser_change_password_form' => Factory\Form\ChangePassword::class, - 'lmcuser_change_email_form' => Factory\Form\ChangeEmail::class, - - Authentication\Adapter\Db::class => Factory\Authentication\Adapter\DbFactory::class, - Authentication\Storage\Db::class => Factory\Authentication\Storage\DbFactory::class, - - 'lmcuser_user_service' => Factory\Service\UserFactory::class, - ], - ]; - } -} +require_once __DIR__ . '/src/Module.php'; diff --git a/composer.json b/composer.json index 0d9d347..1d9dec3 100644 --- a/composer.json +++ b/composer.json @@ -56,18 +56,20 @@ "laminas/laminas-captcha" : "Laminas\\Captcha if you want to use the captcha component" }, "autoload": { - "psr-0": { - "LmcUser": "src/" - }, - "classmap": [ - "./Module.php" - ] + "psr-4": { + "LmcUser\\": "src/" + } }, "autoload-dev": { - "psr-0": { - "LmcUserTest": "tests/" + "psr-4": { + "LmcUserTest\\": "tests/" } }, + "extra": { + "laminas": { + "module": "LmcUser" + } + }, "scripts": { "check": [ "@cs-check", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index c5fbfe0..d7d2ec5 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,5 +1,5 @@ - - ./tests/LmcUserTest + ./tests diff --git a/src/LmcUser/Authentication/Adapter/AbstractAdapter.php b/src/Authentication/Adapter/AbstractAdapter.php similarity index 100% rename from src/LmcUser/Authentication/Adapter/AbstractAdapter.php rename to src/Authentication/Adapter/AbstractAdapter.php diff --git a/src/LmcUser/Authentication/Adapter/AdapterChain.php b/src/Authentication/Adapter/AdapterChain.php similarity index 100% rename from src/LmcUser/Authentication/Adapter/AdapterChain.php rename to src/Authentication/Adapter/AdapterChain.php diff --git a/src/LmcUser/Authentication/Adapter/AdapterChainEvent.php b/src/Authentication/Adapter/AdapterChainEvent.php similarity index 100% rename from src/LmcUser/Authentication/Adapter/AdapterChainEvent.php rename to src/Authentication/Adapter/AdapterChainEvent.php diff --git a/src/LmcUser/Authentication/Adapter/AdapterChainServiceFactory.php b/src/Authentication/Adapter/AdapterChainServiceFactory.php similarity index 100% rename from src/LmcUser/Authentication/Adapter/AdapterChainServiceFactory.php rename to src/Authentication/Adapter/AdapterChainServiceFactory.php diff --git a/src/LmcUser/Authentication/Adapter/ChainableAdapter.php b/src/Authentication/Adapter/ChainableAdapter.php similarity index 100% rename from src/LmcUser/Authentication/Adapter/ChainableAdapter.php rename to src/Authentication/Adapter/ChainableAdapter.php diff --git a/src/LmcUser/Authentication/Adapter/Db.php b/src/Authentication/Adapter/Db.php similarity index 100% rename from src/LmcUser/Authentication/Adapter/Db.php rename to src/Authentication/Adapter/Db.php diff --git a/src/LmcUser/Authentication/Adapter/Exception/OptionsNotFoundException.php b/src/Authentication/Adapter/Exception/OptionsNotFoundException.php similarity index 100% rename from src/LmcUser/Authentication/Adapter/Exception/OptionsNotFoundException.php rename to src/Authentication/Adapter/Exception/OptionsNotFoundException.php diff --git a/src/LmcUser/Authentication/Storage/Db.php b/src/Authentication/Storage/Db.php similarity index 100% rename from src/LmcUser/Authentication/Storage/Db.php rename to src/Authentication/Storage/Db.php diff --git a/src/LmcUser/Controller/Plugin/LmcUserAuthentication.php b/src/Controller/Plugin/LmcUserAuthentication.php similarity index 100% rename from src/LmcUser/Controller/Plugin/LmcUserAuthentication.php rename to src/Controller/Plugin/LmcUserAuthentication.php diff --git a/src/LmcUser/Controller/RedirectCallback.php b/src/Controller/RedirectCallback.php similarity index 100% rename from src/LmcUser/Controller/RedirectCallback.php rename to src/Controller/RedirectCallback.php diff --git a/src/LmcUser/Controller/UserController.php b/src/Controller/UserController.php similarity index 100% rename from src/LmcUser/Controller/UserController.php rename to src/Controller/UserController.php diff --git a/src/LmcUser/Db/Adapter/MasterSlaveAdapter.php b/src/Db/Adapter/MasterSlaveAdapter.php similarity index 100% rename from src/LmcUser/Db/Adapter/MasterSlaveAdapter.php rename to src/Db/Adapter/MasterSlaveAdapter.php diff --git a/src/LmcUser/Db/Adapter/MasterSlaveAdapterInterface.php b/src/Db/Adapter/MasterSlaveAdapterInterface.php similarity index 100% rename from src/LmcUser/Db/Adapter/MasterSlaveAdapterInterface.php rename to src/Db/Adapter/MasterSlaveAdapterInterface.php diff --git a/src/LmcUser/Entity/User.php b/src/Entity/User.php similarity index 100% rename from src/LmcUser/Entity/User.php rename to src/Entity/User.php diff --git a/src/LmcUser/Entity/UserInterface.php b/src/Entity/UserInterface.php similarity index 100% rename from src/LmcUser/Entity/UserInterface.php rename to src/Entity/UserInterface.php diff --git a/src/LmcUser/EventManager/EventProvider.php b/src/EventManager/EventProvider.php similarity index 100% rename from src/LmcUser/EventManager/EventProvider.php rename to src/EventManager/EventProvider.php diff --git a/src/LmcUser/Exception/AuthenticationEventException.php b/src/Exception/AuthenticationEventException.php similarity index 100% rename from src/LmcUser/Exception/AuthenticationEventException.php rename to src/Exception/AuthenticationEventException.php diff --git a/src/LmcUser/Exception/DomainException.php b/src/Exception/DomainException.php similarity index 100% rename from src/LmcUser/Exception/DomainException.php rename to src/Exception/DomainException.php diff --git a/src/LmcUser/Exception/ExceptionInterface.php b/src/Exception/ExceptionInterface.php similarity index 100% rename from src/LmcUser/Exception/ExceptionInterface.php rename to src/Exception/ExceptionInterface.php diff --git a/src/LmcUser/Factory/Authentication/Adapter/DbFactory.php b/src/Factory/Authentication/Adapter/DbFactory.php similarity index 100% rename from src/LmcUser/Factory/Authentication/Adapter/DbFactory.php rename to src/Factory/Authentication/Adapter/DbFactory.php diff --git a/src/LmcUser/Factory/Authentication/Storage/DbFactory.php b/src/Factory/Authentication/Storage/DbFactory.php similarity index 100% rename from src/LmcUser/Factory/Authentication/Storage/DbFactory.php rename to src/Factory/Authentication/Storage/DbFactory.php diff --git a/src/LmcUser/Factory/AuthenticationService.php b/src/Factory/AuthenticationService.php similarity index 100% rename from src/LmcUser/Factory/AuthenticationService.php rename to src/Factory/AuthenticationService.php diff --git a/src/LmcUser/Factory/Controller/Plugin/LmcUserAuthentication.php b/src/Factory/Controller/Plugin/LmcUserAuthentication.php similarity index 100% rename from src/LmcUser/Factory/Controller/Plugin/LmcUserAuthentication.php rename to src/Factory/Controller/Plugin/LmcUserAuthentication.php diff --git a/src/LmcUser/Factory/Controller/RedirectCallbackFactory.php b/src/Factory/Controller/RedirectCallbackFactory.php similarity index 100% rename from src/LmcUser/Factory/Controller/RedirectCallbackFactory.php rename to src/Factory/Controller/RedirectCallbackFactory.php diff --git a/src/LmcUser/Factory/Controller/UserControllerFactory.php b/src/Factory/Controller/UserControllerFactory.php similarity index 100% rename from src/LmcUser/Factory/Controller/UserControllerFactory.php rename to src/Factory/Controller/UserControllerFactory.php diff --git a/src/LmcUser/Factory/Form/ChangeEmail.php b/src/Factory/Form/ChangeEmail.php similarity index 100% rename from src/LmcUser/Factory/Form/ChangeEmail.php rename to src/Factory/Form/ChangeEmail.php diff --git a/src/LmcUser/Factory/Form/ChangePassword.php b/src/Factory/Form/ChangePassword.php similarity index 100% rename from src/LmcUser/Factory/Form/ChangePassword.php rename to src/Factory/Form/ChangePassword.php diff --git a/src/LmcUser/Factory/Form/Login.php b/src/Factory/Form/Login.php similarity index 100% rename from src/LmcUser/Factory/Form/Login.php rename to src/Factory/Form/Login.php diff --git a/src/LmcUser/Factory/Form/Register.php b/src/Factory/Form/Register.php similarity index 100% rename from src/LmcUser/Factory/Form/Register.php rename to src/Factory/Form/Register.php diff --git a/src/LmcUser/Factory/Mapper/User.php b/src/Factory/Mapper/User.php similarity index 100% rename from src/LmcUser/Factory/Mapper/User.php rename to src/Factory/Mapper/User.php diff --git a/src/LmcUser/Factory/Options/ModuleOptions.php b/src/Factory/Options/ModuleOptions.php similarity index 100% rename from src/LmcUser/Factory/Options/ModuleOptions.php rename to src/Factory/Options/ModuleOptions.php diff --git a/src/LmcUser/Factory/Service/UserFactory.php b/src/Factory/Service/UserFactory.php similarity index 100% rename from src/LmcUser/Factory/Service/UserFactory.php rename to src/Factory/Service/UserFactory.php diff --git a/src/LmcUser/Factory/UserHydrator.php b/src/Factory/UserHydrator.php similarity index 100% rename from src/LmcUser/Factory/UserHydrator.php rename to src/Factory/UserHydrator.php diff --git a/src/LmcUser/Factory/View/Helper/LmcUserDisplayName.php b/src/Factory/View/Helper/LmcUserDisplayName.php similarity index 100% rename from src/LmcUser/Factory/View/Helper/LmcUserDisplayName.php rename to src/Factory/View/Helper/LmcUserDisplayName.php diff --git a/src/LmcUser/Factory/View/Helper/LmcUserIdentity.php b/src/Factory/View/Helper/LmcUserIdentity.php similarity index 100% rename from src/LmcUser/Factory/View/Helper/LmcUserIdentity.php rename to src/Factory/View/Helper/LmcUserIdentity.php diff --git a/src/LmcUser/Factory/View/Helper/LmcUserLoginWidget.php b/src/Factory/View/Helper/LmcUserLoginWidget.php similarity index 100% rename from src/LmcUser/Factory/View/Helper/LmcUserLoginWidget.php rename to src/Factory/View/Helper/LmcUserLoginWidget.php diff --git a/src/LmcUser/Form/Base.php b/src/Form/Base.php similarity index 100% rename from src/LmcUser/Form/Base.php rename to src/Form/Base.php diff --git a/src/LmcUser/Form/ChangeEmail.php b/src/Form/ChangeEmail.php similarity index 100% rename from src/LmcUser/Form/ChangeEmail.php rename to src/Form/ChangeEmail.php diff --git a/src/LmcUser/Form/ChangeEmailFilter.php b/src/Form/ChangeEmailFilter.php similarity index 100% rename from src/LmcUser/Form/ChangeEmailFilter.php rename to src/Form/ChangeEmailFilter.php diff --git a/src/LmcUser/Form/ChangePassword.php b/src/Form/ChangePassword.php similarity index 100% rename from src/LmcUser/Form/ChangePassword.php rename to src/Form/ChangePassword.php diff --git a/src/LmcUser/Form/ChangePasswordFilter.php b/src/Form/ChangePasswordFilter.php similarity index 100% rename from src/LmcUser/Form/ChangePasswordFilter.php rename to src/Form/ChangePasswordFilter.php diff --git a/src/LmcUser/Form/Login.php b/src/Form/Login.php similarity index 100% rename from src/LmcUser/Form/Login.php rename to src/Form/Login.php diff --git a/src/LmcUser/Form/LoginFilter.php b/src/Form/LoginFilter.php similarity index 100% rename from src/LmcUser/Form/LoginFilter.php rename to src/Form/LoginFilter.php diff --git a/src/LmcUser/Form/ProvidesEventsForm.php b/src/Form/ProvidesEventsForm.php similarity index 100% rename from src/LmcUser/Form/ProvidesEventsForm.php rename to src/Form/ProvidesEventsForm.php diff --git a/src/LmcUser/Form/Register.php b/src/Form/Register.php similarity index 100% rename from src/LmcUser/Form/Register.php rename to src/Form/Register.php diff --git a/src/LmcUser/Form/RegisterFilter.php b/src/Form/RegisterFilter.php similarity index 100% rename from src/LmcUser/Form/RegisterFilter.php rename to src/Form/RegisterFilter.php diff --git a/src/LmcUser/InputFilter/ProvidesEventsInputFilter.php b/src/InputFilter/ProvidesEventsInputFilter.php similarity index 100% rename from src/LmcUser/InputFilter/ProvidesEventsInputFilter.php rename to src/InputFilter/ProvidesEventsInputFilter.php diff --git a/src/LmcUser/Mapper/AbstractDbMapper.php b/src/Mapper/AbstractDbMapper.php similarity index 100% rename from src/LmcUser/Mapper/AbstractDbMapper.php rename to src/Mapper/AbstractDbMapper.php diff --git a/src/LmcUser/Mapper/Exception/ExceptionInterface.php b/src/Mapper/Exception/ExceptionInterface.php similarity index 100% rename from src/LmcUser/Mapper/Exception/ExceptionInterface.php rename to src/Mapper/Exception/ExceptionInterface.php diff --git a/src/LmcUser/Mapper/Exception/InvalidArgumentException.php b/src/Mapper/Exception/InvalidArgumentException.php similarity index 100% rename from src/LmcUser/Mapper/Exception/InvalidArgumentException.php rename to src/Mapper/Exception/InvalidArgumentException.php diff --git a/src/LmcUser/Mapper/Exception/RuntimeException.php b/src/Mapper/Exception/RuntimeException.php similarity index 100% rename from src/LmcUser/Mapper/Exception/RuntimeException.php rename to src/Mapper/Exception/RuntimeException.php diff --git a/src/LmcUser/Mapper/User.php b/src/Mapper/User.php similarity index 100% rename from src/LmcUser/Mapper/User.php rename to src/Mapper/User.php diff --git a/src/LmcUser/Mapper/UserHydrator.php b/src/Mapper/UserHydrator.php similarity index 100% rename from src/LmcUser/Mapper/UserHydrator.php rename to src/Mapper/UserHydrator.php diff --git a/src/LmcUser/Mapper/UserInterface.php b/src/Mapper/UserInterface.php similarity index 100% rename from src/LmcUser/Mapper/UserInterface.php rename to src/Mapper/UserInterface.php diff --git a/src/Module.php b/src/Module.php new file mode 100644 index 0000000..d8f1dd3 --- /dev/null +++ b/src/Module.php @@ -0,0 +1,116 @@ + [ + 'lmcUserAuthentication' => Factory\Controller\Plugin\LmcUserAuthentication::class, + ], + ]; + } + + /** + * {@inheritDoc} + * @see \Laminas\ModuleManager\Feature\ControllerProviderInterface::getControllerConfig() + */ + public function getControllerConfig() + { + return [ + 'factories' => [ + 'lmcuser' => Factory\Controller\UserControllerFactory::class, + ], + ]; + } + + /** + * {@inheritDoc} + * @see \Laminas\ModuleManager\Feature\ViewHelperProviderInterface::getViewHelperConfig() + */ + public function getViewHelperConfig() + { + return [ + 'factories' => [ + 'lmcUserDisplayName' => Factory\View\Helper\LmcUserDisplayName::class, + 'lmcUserIdentity' => Factory\View\Helper\LmcUserIdentity::class, + 'lmcUserLoginWidget' => Factory\View\Helper\LmcUserLoginWidget::class, + ], + ]; + } + + /** + * {@inheritDoc} + * @see \Laminas\ModuleManager\Feature\ServiceProviderInterface::getServiceConfig() + */ + public function getServiceConfig() + { + return [ + 'aliases' => [ + 'lmcuser_laminas_db_adapter' => \Laminas\Db\Adapter\Adapter::class, + 'lmcuser_register_form_hydrator' => 'lmcuser_user_hydrator', + 'lmcuser_base_hydrator' => 'lmcuser_default_hydrator', + ], + 'invokables' => [ + 'lmcuser_default_hydrator' => ClassMethodsHydrator::class, + ], + 'factories' => [ + 'lmcuser_redirect_callback' => Factory\Controller\RedirectCallbackFactory::class, + 'lmcuser_module_options' => Factory\Options\ModuleOptions::class, + Authentication\Adapter\AdapterChain::class => Authentication\Adapter\AdapterChainServiceFactory::class, + + // We alias this one because it's LmcUser's instance of + // Laminas\Authentication\AuthenticationService. We don't want to + // hog the FQCN service alias for a Laminas\* class. + 'lmcuser_auth_service' => Factory\AuthenticationService::class, + + 'lmcuser_user_hydrator' => Factory\UserHydrator::class, + 'lmcuser_user_mapper' => Factory\Mapper\User::class, + + 'lmcuser_login_form' => Factory\Form\Login::class, + 'lmcuser_register_form' => Factory\Form\Register::class, + 'lmcuser_change_password_form' => Factory\Form\ChangePassword::class, + 'lmcuser_change_email_form' => Factory\Form\ChangeEmail::class, + + Authentication\Adapter\Db::class => Factory\Authentication\Adapter\DbFactory::class, + Authentication\Storage\Db::class => Factory\Authentication\Storage\DbFactory::class, + + 'lmcuser_user_service' => Factory\Service\UserFactory::class, + ], + ]; + } +} diff --git a/src/LmcUser/Options/AuthenticationOptionsInterface.php b/src/Options/AuthenticationOptionsInterface.php similarity index 100% rename from src/LmcUser/Options/AuthenticationOptionsInterface.php rename to src/Options/AuthenticationOptionsInterface.php diff --git a/src/LmcUser/Options/ModuleOptions.php b/src/Options/ModuleOptions.php similarity index 100% rename from src/LmcUser/Options/ModuleOptions.php rename to src/Options/ModuleOptions.php diff --git a/src/LmcUser/Options/PasswordOptionsInterface.php b/src/Options/PasswordOptionsInterface.php similarity index 100% rename from src/LmcUser/Options/PasswordOptionsInterface.php rename to src/Options/PasswordOptionsInterface.php diff --git a/src/LmcUser/Options/RegistrationOptionsInterface.php b/src/Options/RegistrationOptionsInterface.php similarity index 100% rename from src/LmcUser/Options/RegistrationOptionsInterface.php rename to src/Options/RegistrationOptionsInterface.php diff --git a/src/LmcUser/Options/UserControllerOptionsInterface.php b/src/Options/UserControllerOptionsInterface.php similarity index 100% rename from src/LmcUser/Options/UserControllerOptionsInterface.php rename to src/Options/UserControllerOptionsInterface.php diff --git a/src/LmcUser/Options/UserServiceOptionsInterface.php b/src/Options/UserServiceOptionsInterface.php similarity index 100% rename from src/LmcUser/Options/UserServiceOptionsInterface.php rename to src/Options/UserServiceOptionsInterface.php diff --git a/src/LmcUser/Service/Exception/ExceptionInterface.php b/src/Service/Exception/ExceptionInterface.php similarity index 100% rename from src/LmcUser/Service/Exception/ExceptionInterface.php rename to src/Service/Exception/ExceptionInterface.php diff --git a/src/LmcUser/Service/Exception/InvalidArgumentException.php b/src/Service/Exception/InvalidArgumentException.php similarity index 100% rename from src/LmcUser/Service/Exception/InvalidArgumentException.php rename to src/Service/Exception/InvalidArgumentException.php diff --git a/src/LmcUser/Service/User.php b/src/Service/User.php similarity index 100% rename from src/LmcUser/Service/User.php rename to src/Service/User.php diff --git a/src/LmcUser/Validator/AbstractRecord.php b/src/Validator/AbstractRecord.php similarity index 100% rename from src/LmcUser/Validator/AbstractRecord.php rename to src/Validator/AbstractRecord.php diff --git a/src/LmcUser/Validator/Exception/ExceptionInterface.php b/src/Validator/Exception/ExceptionInterface.php similarity index 100% rename from src/LmcUser/Validator/Exception/ExceptionInterface.php rename to src/Validator/Exception/ExceptionInterface.php diff --git a/src/LmcUser/Validator/Exception/InvalidArgumentException.php b/src/Validator/Exception/InvalidArgumentException.php similarity index 100% rename from src/LmcUser/Validator/Exception/InvalidArgumentException.php rename to src/Validator/Exception/InvalidArgumentException.php diff --git a/src/LmcUser/Validator/NoRecordExists.php b/src/Validator/NoRecordExists.php similarity index 100% rename from src/LmcUser/Validator/NoRecordExists.php rename to src/Validator/NoRecordExists.php diff --git a/src/LmcUser/Validator/RecordExists.php b/src/Validator/RecordExists.php similarity index 100% rename from src/LmcUser/Validator/RecordExists.php rename to src/Validator/RecordExists.php diff --git a/src/LmcUser/View/Helper/LmcUserDisplayName.php b/src/View/Helper/LmcUserDisplayName.php similarity index 100% rename from src/LmcUser/View/Helper/LmcUserDisplayName.php rename to src/View/Helper/LmcUserDisplayName.php diff --git a/src/LmcUser/View/Helper/LmcUserIdentity.php b/src/View/Helper/LmcUserIdentity.php similarity index 100% rename from src/LmcUser/View/Helper/LmcUserIdentity.php rename to src/View/Helper/LmcUserIdentity.php diff --git a/src/LmcUser/View/Helper/LmcUserLoginWidget.php b/src/View/Helper/LmcUserLoginWidget.php similarity index 100% rename from src/LmcUser/View/Helper/LmcUserLoginWidget.php rename to src/View/Helper/LmcUserLoginWidget.php diff --git a/src/LmcUser/language/cs_CZ.mo b/src/language/cs_CZ.mo similarity index 100% rename from src/LmcUser/language/cs_CZ.mo rename to src/language/cs_CZ.mo diff --git a/src/LmcUser/language/cs_CZ.po b/src/language/cs_CZ.po similarity index 100% rename from src/LmcUser/language/cs_CZ.po rename to src/language/cs_CZ.po diff --git a/src/LmcUser/language/de_DE.mo b/src/language/de_DE.mo similarity index 100% rename from src/LmcUser/language/de_DE.mo rename to src/language/de_DE.mo diff --git a/src/LmcUser/language/de_DE.po b/src/language/de_DE.po similarity index 100% rename from src/LmcUser/language/de_DE.po rename to src/language/de_DE.po diff --git a/src/LmcUser/language/es_ES.mo b/src/language/es_ES.mo similarity index 100% rename from src/LmcUser/language/es_ES.mo rename to src/language/es_ES.mo diff --git a/src/LmcUser/language/es_ES.po b/src/language/es_ES.po similarity index 100% rename from src/LmcUser/language/es_ES.po rename to src/language/es_ES.po diff --git a/src/LmcUser/language/fr_FR.mo b/src/language/fr_FR.mo similarity index 100% rename from src/LmcUser/language/fr_FR.mo rename to src/language/fr_FR.mo diff --git a/src/LmcUser/language/fr_FR.po b/src/language/fr_FR.po similarity index 100% rename from src/LmcUser/language/fr_FR.po rename to src/language/fr_FR.po diff --git a/src/LmcUser/language/ja_JP.mo b/src/language/ja_JP.mo similarity index 100% rename from src/LmcUser/language/ja_JP.mo rename to src/language/ja_JP.mo diff --git a/src/LmcUser/language/ja_JP.po b/src/language/ja_JP.po similarity index 100% rename from src/LmcUser/language/ja_JP.po rename to src/language/ja_JP.po diff --git a/src/LmcUser/language/msgIds.php b/src/language/msgIds.php similarity index 100% rename from src/LmcUser/language/msgIds.php rename to src/language/msgIds.php diff --git a/src/LmcUser/language/nl_NL.mo b/src/language/nl_NL.mo similarity index 100% rename from src/LmcUser/language/nl_NL.mo rename to src/language/nl_NL.mo diff --git a/src/LmcUser/language/nl_NL.po b/src/language/nl_NL.po similarity index 100% rename from src/LmcUser/language/nl_NL.po rename to src/language/nl_NL.po diff --git a/src/LmcUser/language/pl_PL.mo b/src/language/pl_PL.mo similarity index 100% rename from src/LmcUser/language/pl_PL.mo rename to src/language/pl_PL.mo diff --git a/src/LmcUser/language/pl_PL.po b/src/language/pl_PL.po similarity index 100% rename from src/LmcUser/language/pl_PL.po rename to src/language/pl_PL.po diff --git a/src/LmcUser/language/pt_BR.mo b/src/language/pt_BR.mo similarity index 100% rename from src/LmcUser/language/pt_BR.mo rename to src/language/pt_BR.mo diff --git a/src/LmcUser/language/pt_BR.po b/src/language/pt_BR.po similarity index 100% rename from src/LmcUser/language/pt_BR.po rename to src/language/pt_BR.po diff --git a/src/LmcUser/language/ru_RU.mo b/src/language/ru_RU.mo similarity index 100% rename from src/LmcUser/language/ru_RU.mo rename to src/language/ru_RU.mo diff --git a/src/LmcUser/language/ru_RU.po b/src/language/ru_RU.po similarity index 100% rename from src/LmcUser/language/ru_RU.po rename to src/language/ru_RU.po diff --git a/tests/LmcUserTest/Authentication/Adapter/AbstractAdapterTest.php b/tests/Authentication/Adapter/AbstractAdapterTest.php similarity index 100% rename from tests/LmcUserTest/Authentication/Adapter/AbstractAdapterTest.php rename to tests/Authentication/Adapter/AbstractAdapterTest.php diff --git a/tests/LmcUserTest/Authentication/Adapter/AdapterChainEventTest.php b/tests/Authentication/Adapter/AdapterChainEventTest.php similarity index 100% rename from tests/LmcUserTest/Authentication/Adapter/AdapterChainEventTest.php rename to tests/Authentication/Adapter/AdapterChainEventTest.php diff --git a/tests/LmcUserTest/Authentication/Adapter/AdapterChainServiceFactoryTest.php b/tests/Authentication/Adapter/AdapterChainServiceFactoryTest.php similarity index 100% rename from tests/LmcUserTest/Authentication/Adapter/AdapterChainServiceFactoryTest.php rename to tests/Authentication/Adapter/AdapterChainServiceFactoryTest.php diff --git a/tests/LmcUserTest/Authentication/Adapter/AdapterChainTest.php b/tests/Authentication/Adapter/AdapterChainTest.php similarity index 100% rename from tests/LmcUserTest/Authentication/Adapter/AdapterChainTest.php rename to tests/Authentication/Adapter/AdapterChainTest.php diff --git a/tests/LmcUserTest/Authentication/Adapter/DbTest.php b/tests/Authentication/Adapter/DbTest.php similarity index 100% rename from tests/LmcUserTest/Authentication/Adapter/DbTest.php rename to tests/Authentication/Adapter/DbTest.php diff --git a/tests/LmcUserTest/Authentication/Adapter/TestAsset/AbstractAdapterExtension.php b/tests/Authentication/Adapter/TestAsset/AbstractAdapterExtension.php similarity index 100% rename from tests/LmcUserTest/Authentication/Adapter/TestAsset/AbstractAdapterExtension.php rename to tests/Authentication/Adapter/TestAsset/AbstractAdapterExtension.php diff --git a/tests/LmcUserTest/Authentication/Adapter/TestAsset/InvalidUserClass.php b/tests/Authentication/Adapter/TestAsset/InvalidUserClass.php similarity index 100% rename from tests/LmcUserTest/Authentication/Adapter/TestAsset/InvalidUserClass.php rename to tests/Authentication/Adapter/TestAsset/InvalidUserClass.php diff --git a/tests/LmcUserTest/Authentication/Storage/DbTest.php b/tests/Authentication/Storage/DbTest.php similarity index 100% rename from tests/LmcUserTest/Authentication/Storage/DbTest.php rename to tests/Authentication/Storage/DbTest.php diff --git a/tests/LmcUserTest/Controller/Plugin/LmcUserAuthenticationTest.php b/tests/Controller/Plugin/LmcUserAuthenticationTest.php similarity index 100% rename from tests/LmcUserTest/Controller/Plugin/LmcUserAuthenticationTest.php rename to tests/Controller/Plugin/LmcUserAuthenticationTest.php diff --git a/tests/LmcUserTest/Controller/RedirectCallbackTest.php b/tests/Controller/RedirectCallbackTest.php similarity index 100% rename from tests/LmcUserTest/Controller/RedirectCallbackTest.php rename to tests/Controller/RedirectCallbackTest.php diff --git a/tests/LmcUserTest/Controller/UserControllerTest.php b/tests/Controller/UserControllerTest.php similarity index 100% rename from tests/LmcUserTest/Controller/UserControllerTest.php rename to tests/Controller/UserControllerTest.php diff --git a/tests/LmcUserTest/Entity/UserTest.php b/tests/Entity/UserTest.php similarity index 100% rename from tests/LmcUserTest/Entity/UserTest.php rename to tests/Entity/UserTest.php diff --git a/tests/LmcUserTest/Factory/Form/ChangeEmailFormFactoryTest.php b/tests/Factory/Form/ChangeEmailFormFactoryTest.php similarity index 100% rename from tests/LmcUserTest/Factory/Form/ChangeEmailFormFactoryTest.php rename to tests/Factory/Form/ChangeEmailFormFactoryTest.php diff --git a/tests/LmcUserTest/Factory/Form/ChangePasswordFormFactoryTest.php b/tests/Factory/Form/ChangePasswordFormFactoryTest.php similarity index 100% rename from tests/LmcUserTest/Factory/Form/ChangePasswordFormFactoryTest.php rename to tests/Factory/Form/ChangePasswordFormFactoryTest.php diff --git a/tests/LmcUserTest/Factory/Form/LoginFormFactoryTest.php b/tests/Factory/Form/LoginFormFactoryTest.php similarity index 100% rename from tests/LmcUserTest/Factory/Form/LoginFormFactoryTest.php rename to tests/Factory/Form/LoginFormFactoryTest.php diff --git a/tests/LmcUserTest/Factory/Form/RegisterFormFactoryTest.php b/tests/Factory/Form/RegisterFormFactoryTest.php similarity index 100% rename from tests/LmcUserTest/Factory/Form/RegisterFormFactoryTest.php rename to tests/Factory/Form/RegisterFormFactoryTest.php diff --git a/tests/LmcUserTest/Factory/Mapper/UserMapperFactoryTest.php b/tests/Factory/Mapper/UserMapperFactoryTest.php similarity index 100% rename from tests/LmcUserTest/Factory/Mapper/UserMapperFactoryTest.php rename to tests/Factory/Mapper/UserMapperFactoryTest.php diff --git a/tests/LmcUserTest/Form/BaseTest.php b/tests/Form/BaseTest.php similarity index 100% rename from tests/LmcUserTest/Form/BaseTest.php rename to tests/Form/BaseTest.php diff --git a/tests/LmcUserTest/Form/ChangeEmailFilterTest.php b/tests/Form/ChangeEmailFilterTest.php similarity index 100% rename from tests/LmcUserTest/Form/ChangeEmailFilterTest.php rename to tests/Form/ChangeEmailFilterTest.php diff --git a/tests/LmcUserTest/Form/ChangeEmailTest.php b/tests/Form/ChangeEmailTest.php similarity index 100% rename from tests/LmcUserTest/Form/ChangeEmailTest.php rename to tests/Form/ChangeEmailTest.php diff --git a/tests/LmcUserTest/Form/ChangePasswordFilterTest.php b/tests/Form/ChangePasswordFilterTest.php similarity index 100% rename from tests/LmcUserTest/Form/ChangePasswordFilterTest.php rename to tests/Form/ChangePasswordFilterTest.php diff --git a/tests/LmcUserTest/Form/ChangePasswordTest.php b/tests/Form/ChangePasswordTest.php similarity index 100% rename from tests/LmcUserTest/Form/ChangePasswordTest.php rename to tests/Form/ChangePasswordTest.php diff --git a/tests/LmcUserTest/Form/LoginFilterTest.php b/tests/Form/LoginFilterTest.php similarity index 100% rename from tests/LmcUserTest/Form/LoginFilterTest.php rename to tests/Form/LoginFilterTest.php diff --git a/tests/LmcUserTest/Form/LoginTest.php b/tests/Form/LoginTest.php similarity index 100% rename from tests/LmcUserTest/Form/LoginTest.php rename to tests/Form/LoginTest.php diff --git a/tests/LmcUserTest/Form/RegisterFilterTest.php b/tests/Form/RegisterFilterTest.php similarity index 100% rename from tests/LmcUserTest/Form/RegisterFilterTest.php rename to tests/Form/RegisterFilterTest.php diff --git a/tests/LmcUserTest/Form/RegisterTest.php b/tests/Form/RegisterTest.php similarity index 100% rename from tests/LmcUserTest/Form/RegisterTest.php rename to tests/Form/RegisterTest.php diff --git a/tests/LmcUserTest/Mapper/UserHydratorTest.php b/tests/Mapper/UserHydratorTest.php similarity index 100% rename from tests/LmcUserTest/Mapper/UserHydratorTest.php rename to tests/Mapper/UserHydratorTest.php diff --git a/tests/LmcUserTest/Mapper/UserTest.php b/tests/Mapper/UserTest.php similarity index 100% rename from tests/LmcUserTest/Mapper/UserTest.php rename to tests/Mapper/UserTest.php diff --git a/tests/LmcUserTest/Mapper/_files/user.sql b/tests/Mapper/_files/user.sql similarity index 100% rename from tests/LmcUserTest/Mapper/_files/user.sql rename to tests/Mapper/_files/user.sql diff --git a/tests/LmcUserTest/ModuleTest.php b/tests/ModuleTest.php similarity index 100% rename from tests/LmcUserTest/ModuleTest.php rename to tests/ModuleTest.php diff --git a/tests/LmcUserTest/Options/ModuleOptionsTest.php b/tests/Options/ModuleOptionsTest.php similarity index 100% rename from tests/LmcUserTest/Options/ModuleOptionsTest.php rename to tests/Options/ModuleOptionsTest.php diff --git a/tests/LmcUserTest/Service/UserTest.php b/tests/Service/UserTest.php similarity index 100% rename from tests/LmcUserTest/Service/UserTest.php rename to tests/Service/UserTest.php diff --git a/tests/LmcUserTest/Validator/AbstractRecordTest.php b/tests/Validator/AbstractRecordTest.php similarity index 100% rename from tests/LmcUserTest/Validator/AbstractRecordTest.php rename to tests/Validator/AbstractRecordTest.php diff --git a/tests/LmcUserTest/Validator/NoRecordExistsTest.php b/tests/Validator/NoRecordExistsTest.php similarity index 100% rename from tests/LmcUserTest/Validator/NoRecordExistsTest.php rename to tests/Validator/NoRecordExistsTest.php diff --git a/tests/LmcUserTest/Validator/RecordExistsTest.php b/tests/Validator/RecordExistsTest.php similarity index 100% rename from tests/LmcUserTest/Validator/RecordExistsTest.php rename to tests/Validator/RecordExistsTest.php diff --git a/tests/LmcUserTest/Validator/TestAsset/AbstractRecordExtension.php b/tests/Validator/TestAsset/AbstractRecordExtension.php similarity index 100% rename from tests/LmcUserTest/Validator/TestAsset/AbstractRecordExtension.php rename to tests/Validator/TestAsset/AbstractRecordExtension.php diff --git a/tests/LmcUserTest/View/Helper/LmcUserDisplayNameTest.php b/tests/View/Helper/LmcUserDisplayNameTest.php similarity index 100% rename from tests/LmcUserTest/View/Helper/LmcUserDisplayNameTest.php rename to tests/View/Helper/LmcUserDisplayNameTest.php diff --git a/tests/LmcUserTest/View/Helper/LmcUserIdentityTest.php b/tests/View/Helper/LmcUserIdentityTest.php similarity index 100% rename from tests/LmcUserTest/View/Helper/LmcUserIdentityTest.php rename to tests/View/Helper/LmcUserIdentityTest.php diff --git a/tests/LmcUserTest/View/Helper/LmcUserLoginWidgetTest.php b/tests/View/Helper/LmcUserLoginWidgetTest.php similarity index 100% rename from tests/LmcUserTest/View/Helper/LmcUserLoginWidgetTest.php rename to tests/View/Helper/LmcUserLoginWidgetTest.php From 04ae165f966fcc107582d59afe8a3328cd6a6a90 Mon Sep 17 00:00:00 2001 From: Romain BASTIDE Date: Sat, 11 Feb 2023 00:40:57 +0100 Subject: [PATCH 2/5] Replace \PHPUnit_Framework_MockObject_MockObject to \PHPUnit\Framework\MockObject\MockObject in docblock Removed tests/bootstrap.php and tests/configuration.php.dist --- .../Adapter/AdapterChainTest.php | 8 ++++---- tests/Authentication/Adapter/DbTest.php | 10 +++++----- tests/Controller/UserControllerTest.php | 2 +- tests/bootstrap.php | 18 ------------------ tests/configuration.php.dist | 2 -- 5 files changed, 10 insertions(+), 30 deletions(-) delete mode 100644 tests/bootstrap.php delete mode 100644 tests/configuration.php.dist diff --git a/tests/Authentication/Adapter/AdapterChainTest.php b/tests/Authentication/Adapter/AdapterChainTest.php index 6dc4242..d903e19 100644 --- a/tests/Authentication/Adapter/AdapterChainTest.php +++ b/tests/Authentication/Adapter/AdapterChainTest.php @@ -24,28 +24,28 @@ class AdapterChainTest extends TestCase /** * Mock event manager. * - * @var \PHPUnit_Framework_MockObject_MockObject|EventManagerInterface + * @var \PHPUnit\Framework\MockObject\MockObject|EventManagerInterface */ protected $eventManager; /** * Mock event manager. * - * @var \PHPUnit_Framework_MockObject_MockObject|SharedEventManagerInterface + * @var \PHPUnit\Framework\MockObject\MockObject|SharedEventManagerInterface */ protected $sharedEventManager; /** * For tests where an event is required. * - * @var \PHPUnit_Framework_MockObject_MockObject|EventInterface + * @var \PHPUnit\Framework\MockObject\MockObject|EventInterface */ protected $event; /** * Used when testing prepareForAuthentication. * - * @var \PHPUnit_Framework_MockObject_MockObject|RequestInterface + * @var \PHPUnit\Framework\MockObject\MockObject|RequestInterface */ protected $request; diff --git a/tests/Authentication/Adapter/DbTest.php b/tests/Authentication/Adapter/DbTest.php index cb1adfb..9806652 100644 --- a/tests/Authentication/Adapter/DbTest.php +++ b/tests/Authentication/Adapter/DbTest.php @@ -18,35 +18,35 @@ class DbTest extends TestCase /** * Mock of AuthEvent. * - * @var \LmcUser\Authentication\Adapter\AdapterChainEvent|\PHPUnit_Framework_MockObject_MockObject + * @var \LmcUser\Authentication\Adapter\AdapterChainEvent|\PHPUnit\Framework\MockObject\MockObject */ protected $authEvent; /** * Mock of Storage. * - * @var \Laminas\Authentication\Storage\Session|\PHPUnit_Framework_MockObject_MockObject + * @var \Laminas\Authentication\Storage\Session|\PHPUnit\Framework\MockObject\MockObject */ protected $storage; /** * Mock of Options. * - * @var \LmcUser\Options\ModuleOptions|\PHPUnit_Framework_MockObject_MockObject + * @var \LmcUser\Options\ModuleOptions|\PHPUnit\Framework\MockObject\MockObject */ protected $options; /** * Mock of Mapper. * - * @var \LmcUser\Mapper\UserInterface|\PHPUnit_Framework_MockObject_MockObject + * @var \LmcUser\Mapper\UserInterface|\PHPUnit\Framework\MockObject\MockObject */ protected $mapper; /** * Mock of User. * - * @var \LmcUser\Entity\UserInterface|\PHPUnit_Framework_MockObject_MockObject + * @var \LmcUser\Entity\UserInterface|\PHPUnit\Framework\MockObject\MockObject */ protected $user; diff --git a/tests/Controller/UserControllerTest.php b/tests/Controller/UserControllerTest.php index f2b9e8d..96a16bd 100644 --- a/tests/Controller/UserControllerTest.php +++ b/tests/Controller/UserControllerTest.php @@ -30,7 +30,7 @@ class UserControllerTest extends TestCase protected $options; /** - * @var \PHPUnit_Framework_MockObject_MockObject|RedirectCallback + * @var \PHPUnit\Framework\MockObject\MockObject|RedirectCallback */ protected $redirectCallback; diff --git a/tests/bootstrap.php b/tests/bootstrap.php deleted file mode 100644 index ff847b7..0000000 --- a/tests/bootstrap.php +++ /dev/null @@ -1,18 +0,0 @@ -add('LmcUserTest', __DIR__); - -if (!$config = @include 'configuration.php') { - $config = include 'configuration.php.dist'; -} diff --git a/tests/configuration.php.dist b/tests/configuration.php.dist deleted file mode 100644 index d266508..0000000 --- a/tests/configuration.php.dist +++ /dev/null @@ -1,2 +0,0 @@ - Date: Tue, 14 Feb 2023 00:24:41 +0100 Subject: [PATCH 3/5] Replace ->will(->returnValue() by ->willReturn() in tests --- .../AdapterChainServiceFactoryTest.php | 4 +- .../Adapter/AdapterChainTest.php | 44 +++-- tests/Authentication/Adapter/DbTest.php | 110 ++++++------ tests/Authentication/Storage/DbTest.php | 14 +- .../Plugin/LmcUserAuthenticationTest.php | 4 +- tests/Controller/RedirectCallbackTest.php | 38 ++--- tests/Controller/UserControllerTest.php | 156 ++++++++---------- tests/Form/ChangeEmailFilterTest.php | 6 +- tests/Form/ChangePasswordFilterTest.php | 4 +- tests/Form/LoginFilterTest.php | 4 +- tests/Form/LoginTest.php | 4 +- tests/Form/RegisterFilterTest.php | 4 +- tests/Form/RegisterTest.php | 20 +-- tests/Mapper/UserTest.php | 26 ++- tests/Service/UserTest.php | 92 +++++------ tests/Validator/AbstractRecordTest.php | 4 +- tests/Validator/NoRecordExistsTest.php | 4 +- tests/Validator/RecordExistsTest.php | 4 +- tests/View/Helper/LmcUserDisplayNameTest.php | 30 ++-- tests/View/Helper/LmcUserIdentityTest.php | 6 +- tests/View/Helper/LmcUserLoginWidgetTest.php | 12 +- 21 files changed, 284 insertions(+), 306 deletions(-) diff --git a/tests/Authentication/Adapter/AdapterChainServiceFactoryTest.php b/tests/Authentication/Adapter/AdapterChainServiceFactoryTest.php index 94f9e0c..e1b6000 100644 --- a/tests/Authentication/Adapter/AdapterChainServiceFactoryTest.php +++ b/tests/Authentication/Adapter/AdapterChainServiceFactoryTest.php @@ -59,7 +59,7 @@ protected function setUp():void $this->serviceLocator->expects($this->any()) ->method('get') - ->will($this->returnCallback(array($this,'helperServiceLocator'))); + ->willReturnCallback(array($this,'helperServiceLocator')); $this->eventManager = $this->createMock('Laminas\EventManager\EventManager'); @@ -89,7 +89,7 @@ public function testCreateService() $this->options->expects($this->once()) ->method('getAuthAdapters') - ->will($this->returnValue($adapterNames)); + ->willReturn($adapterNames); $adapterChain = $this->factory->__invoke($this->serviceLocator, 'LmcUser\Authentication\Adapter\AdapterChain'); diff --git a/tests/Authentication/Adapter/AdapterChainTest.php b/tests/Authentication/Adapter/AdapterChainTest.php index d903e19..277019a 100644 --- a/tests/Authentication/Adapter/AdapterChainTest.php +++ b/tests/Authentication/Adapter/AdapterChainTest.php @@ -63,7 +63,7 @@ protected function setUp():void //$this->sharedEventManager->expects($this->any())->method('getListeners')->will($this->returnValue([])); $this->eventManager = $this->createMock('Laminas\EventManager\EventManagerInterface'); - $this->eventManager->expects($this->any())->method('getSharedManager')->will($this->returnValue($this->sharedEventManager)); + $this->eventManager->expects($this->any())->method('getSharedManager')->willReturn($this->sharedEventManager); $this->eventManager->expects($this->any())->method('setIdentifiers'); $this->adapterChain->setEventManager($this->eventManager); @@ -77,18 +77,18 @@ public function testAuthenticate() $event = $this->createMock('LmcUser\Authentication\Adapter\AdapterChainEvent'); $event->expects($this->once()) ->method('getCode') - ->will($this->returnValue(123)); + ->willReturn(123); $event->expects($this->once()) ->method('getIdentity') - ->will($this->returnValue('identity')); + ->willReturn('identity'); $event->expects($this->once()) ->method('getMessages') - ->will($this->returnValue(array())); + ->willReturn(array()); $this->sharedEventManager->expects($this->once()) ->method('getListeners') ->with($this->equalTo(['authenticate']), $this->equalTo('authenticate')) - ->will($this->returnValue(array())); + ->willReturn(array()); $this->adapterChain->setEvent($event); $result = $this->adapterChain->authenticate(); @@ -113,7 +113,7 @@ public function testResetAdapters() $adapter = $this->createMock('LmcUser\Authentication\Adapter\ChainableAdapter'); $adapter->expects($this->once()) ->method('getStorage') - ->will($this->returnValue($storage)); + ->willReturn($storage); $callback = [$adapter, 'authenticate']; $listeners[] = $callback; @@ -122,7 +122,7 @@ public function testResetAdapters() $this->sharedEventManager->expects($this->once()) ->method('getListeners') ->with($this->equalTo(['authenticate']), $this->equalTo('authenticate')) - ->will($this->returnValue($listeners)); + ->willReturn($listeners); $result = $this->adapterChain->resetAdapters(); @@ -140,7 +140,7 @@ protected function setUpPrepareForAuthentication() $this->event->expects($this->once())->method('setRequest')->with($this->request); $this->event->setName('authenticate.pre'); - $this->eventManager->expects($this->at(0))->method('triggerEvent')->with($this->event); + $this->eventManager->expects($this->atLeastOnce())->method('triggerEvent')->with($this->event); /** * @var $response \Laminas\EventManager\ResponseCollection @@ -148,7 +148,7 @@ protected function setUpPrepareForAuthentication() $responses = $this->createMock('Laminas\EventManager\ResponseCollection'); $this->event->setName('authenticate'); - $this->eventManager->expects($this->at(1)) + $this->eventManager->expects($this->atLeastOnce()) ->method('triggerEventUntil') ->with( function ($test) { @@ -156,15 +156,13 @@ function ($test) { }, $this->event ) - ->will( - $this->returnCallback( - function ($callback) use ($responses) { - if (call_user_func($callback, $responses->last())) { - $responses->setStopped(true); - } - return $responses; + ->willReturnCallback( + function ($callback) use ($responses) { + if (call_user_func($callback, $responses->last())) { + $responses->setStopped(true); } - ) + return $responses; + } ); $this->adapterChain->setEvent($this->event); @@ -198,9 +196,9 @@ public function testPrepareForAuthentication($identity, $expected) { $result = $this->setUpPrepareForAuthentication(); - $result->expects($this->once())->method('stopped')->will($this->returnValue(false)); + $result->expects($this->once())->method('stopped')->willReturn(false); - $this->event->expects($this->once())->method('getIdentity')->will($this->returnValue($identity)); + $this->event->expects($this->once())->method('getIdentity')->willReturn($identity); $this->assertEquals( $expected, @@ -218,10 +216,10 @@ public function testPrepareForAuthenticationWithStoppedEvent() { $result = $this->setUpPrepareForAuthentication(); - $result->expects($this->once())->method('stopped')->will($this->returnValue(true)); + $result->expects($this->once())->method('stopped')->willReturn(true); $lastResponse = $this->createMock('Laminas\Stdlib\ResponseInterface'); - $result->expects($this->atLeastOnce())->method('last')->will($this->returnValue($lastResponse)); + $result->expects($this->atLeastOnce())->method('last')->willReturn($lastResponse); $this->assertEquals( $lastResponse, @@ -240,10 +238,10 @@ public function testPrepareForAuthenticationWithBadEventResult() $this->expectException(\LmcUser\Exception\AuthenticationEventException::class); $result = $this->setUpPrepareForAuthentication(); - $result->expects($this->once())->method('stopped')->will($this->returnValue(true)); + $result->expects($this->once())->method('stopped')->willReturn(true); $lastResponse = 'random-value'; - $result->expects($this->atLeastOnce())->method('last')->will($this->returnValue($lastResponse)); + $result->expects($this->atLeastOnce())->method('last')->willReturn($lastResponse); $this->adapterChain->prepareForAuthentication($this->request); } diff --git a/tests/Authentication/Adapter/DbTest.php b/tests/Authentication/Adapter/DbTest.php index 9806652..2b018ca 100644 --- a/tests/Authentication/Adapter/DbTest.php +++ b/tests/Authentication/Adapter/DbTest.php @@ -93,22 +93,22 @@ public function testAuthenticateWhenSatisfies() $this->authEvent->expects($this->once()) ->method('setIdentity') ->with('LmcUser') - ->will($this->returnValue($this->authEvent)); + ->willReturn($this->authEvent); $this->authEvent->expects($this->once()) ->method('setCode') ->with(\Laminas\Authentication\Result::SUCCESS) - ->will($this->returnValue($this->authEvent)); + ->willReturn($this->authEvent); $this->authEvent->expects($this->once()) ->method('setMessages') ->with(array('Authentication successful.')) - ->will($this->returnValue($this->authEvent)); + ->willReturn($this->authEvent); - $this->storage->expects($this->at(0)) + $this->storage->expects($this->exactly(2)) ->method('read') - ->will($this->returnValue(array('is_satisfied' => true))); - $this->storage->expects($this->at(1)) - ->method('read') - ->will($this->returnValue(array('identity' => 'LmcUser'))); + ->willReturnOnConsecutiveCalls( + ['is_satisfied' => true], + ['identity' => 'LmcUser'] + ); $result = $this->db->authenticate($this->authEvent); @@ -125,22 +125,21 @@ public function testAuthenticateNoUserObject() $this->options->expects($this->once()) ->method('getAuthIdentityFields') - ->will($this->returnValue(array())); + ->willReturn(array()); $this->authEvent->expects($this->once()) ->method('setCode') ->with(\Laminas\Authentication\Result::FAILURE_IDENTITY_NOT_FOUND) - ->will($this->returnValue($this->authEvent)); + ->willReturn($this->authEvent); $this->authEvent->expects($this->once()) ->method('setMessages') ->with(array('A record with the supplied identity could not be found.')) - ->will($this->returnValue($this->authEvent)); + ->willReturn($this->authEvent); $this->db->setOptions($this->options); $result = $this->db->authenticate($this->authEvent); - ; $this->assertFalse($result); $this->assertFalse($this->db->isSatisfied()); @@ -156,30 +155,29 @@ public function testAuthenticationUserStateEnabledUserButUserStateNotInArray() $this->options->expects($this->once()) ->method('getEnableUserState') - ->will($this->returnValue(true)); + ->willReturn(true); $this->options->expects($this->once()) ->method('getAllowedLoginStates') - ->will($this->returnValue(array(2, 3))); + ->willReturn(array(2, 3)); $this->authEvent->expects($this->once()) ->method('setCode') ->with(\Laminas\Authentication\Result::FAILURE_UNCATEGORIZED) - ->will($this->returnValue($this->authEvent)); + ->willReturn($this->authEvent); $this->authEvent->expects($this->once()) ->method('setMessages') ->with(array('A record with the supplied identity is not active.')) - ->will($this->returnValue($this->authEvent)); + ->willReturn($this->authEvent); $this->user->expects($this->once()) ->method('getState') - ->will($this->returnValue(1)); + ->willReturn(1); $this->db->setMapper($this->mapper); $this->db->setOptions($this->options); $result = $this->db->authenticate($this->authEvent); - ; $this->assertFalse($result); $this->assertFalse($this->db->isSatisfied()); @@ -195,17 +193,17 @@ public function testAuthenticateWithWrongPassword() $this->options->expects($this->once()) ->method('getEnableUserState') - ->will($this->returnValue(false)); + ->willReturn(false); // Set lowest possible to spent the least amount of resources/time $this->options->expects($this->once()) ->method('getPasswordCost') - ->will($this->returnValue(4)); + ->willReturn(4); $this->authEvent->expects($this->once()) ->method('setCode') ->with(\Laminas\Authentication\Result::FAILURE_CREDENTIAL_INVALID) - ->will($this->returnValue($this->authEvent)); + ->willReturn($this->authEvent); $this->authEvent->expects($this->once(1)) ->method('setMessages') ->with(array('Supplied credential is invalid.')); @@ -231,35 +229,35 @@ public function testAuthenticationAuthenticatesWithEmail() $this->options->expects($this->once()) ->method('getEnableUserState') - ->will($this->returnValue(false)); + ->willReturn(false); $this->options->expects($this->once()) ->method('getPasswordCost') - ->will($this->returnValue(4)); + ->willReturn(4); $this->user->expects($this->exactly(2)) ->method('getPassword') - ->will($this->returnValue('$2y$04$QVAIS1VWJZt6vQkWoWSHMet9ebjdKuKQGcjAEaILVQZjreRw0EAV2')); + ->willReturn('$2y$04$QVAIS1VWJZt6vQkWoWSHMet9ebjdKuKQGcjAEaILVQZjreRw0EAV2'); $this->user->expects($this->once()) ->method('getId') - ->will($this->returnValue(1)); + ->willReturn(1); $this->storage->expects($this->any()) ->method('getNameSpace') - ->will($this->returnValue('test')); + ->willReturn('test'); $this->authEvent->expects($this->once()) ->method('setIdentity') ->with(1) - ->will($this->returnValue($this->authEvent)); + ->willReturn($this->authEvent); $this->authEvent->expects($this->once()) ->method('setCode') ->with(\Laminas\Authentication\Result::SUCCESS) - ->will($this->returnValue($this->authEvent)); + ->willReturn($this->authEvent); $this->authEvent->expects($this->once()) ->method('setMessages') ->with(array('Authentication successful.')) - ->will($this->returnValue($this->authEvent)); + ->willReturn($this->authEvent); $this->db->setMapper($this->mapper); $this->db->setOptions($this->options); @@ -279,42 +277,42 @@ public function testAuthenticationAuthenticates() $this->options->expects($this->once()) ->method('getEnableUserState') - ->will($this->returnValue(true)); + ->willReturn(true); $this->options->expects($this->once()) ->method('getAllowedLoginStates') - ->will($this->returnValue(array(1, 2, 3))); + ->willReturn(array(1, 2, 3)); $this->options->expects($this->once()) ->method('getPasswordCost') - ->will($this->returnValue(4)); + ->willReturn(4); $this->user->expects($this->exactly(2)) ->method('getPassword') - ->will($this->returnValue('$2y$04$QVAIS1VWJZt6vQkWoWSHMet9ebjdKuKQGcjAEaILVQZjreRw0EAV2')); + ->willReturn('$2y$04$QVAIS1VWJZt6vQkWoWSHMet9ebjdKuKQGcjAEaILVQZjreRw0EAV2'); $this->user->expects($this->once()) ->method('getId') - ->will($this->returnValue(1)); + ->willReturn(1); $this->user->expects($this->once()) ->method('getState') - ->will($this->returnValue(1)); + ->willReturn(1); $this->storage->expects($this->any()) ->method('getNameSpace') - ->will($this->returnValue('test')); + ->willReturn('test'); $this->authEvent->expects($this->once()) ->method('setIdentity') ->with(1) - ->will($this->returnValue($this->authEvent)); + ->willReturn($this->authEvent); $this->authEvent->expects($this->once()) ->method('setCode') ->with(\Laminas\Authentication\Result::SUCCESS) - ->will($this->returnValue($this->authEvent)); + ->willReturn($this->authEvent); $this->authEvent->expects($this->once()) ->method('setMessages') ->with(array('Authentication successful.')) - ->will($this->returnValue($this->authEvent)); + ->willReturn($this->authEvent); $this->db->setMapper($this->mapper); $this->db->setOptions($this->options); @@ -332,12 +330,12 @@ public function testUpdateUserPasswordHashWithSameCost() $user = $this->createMock('LmcUser\Entity\User'); $user->expects($this->once()) ->method('getPassword') - ->will($this->returnValue('$2a$10$x05G2P803MrB3jaORBXBn.QHtiYzGQOBjQ7unpEIge.Mrz6c3KiVm')); + ->willReturn('$2a$10$x05G2P803MrB3jaORBXBn.QHtiYzGQOBjQ7unpEIge.Mrz6c3KiVm'); $bcrypt = $this->createMock('Laminas\Crypt\Password\Bcrypt'); $bcrypt->expects($this->once()) ->method('getCost') - ->will($this->returnValue('10')); + ->willReturn('10'); $method = new \ReflectionMethod( 'LmcUser\Authentication\Adapter\Db', @@ -357,7 +355,7 @@ public function testUpdateUserPasswordHashWithoutSameCost() $user = $this->createMock('LmcUser\Entity\User'); $user->expects($this->once()) ->method('getPassword') - ->will($this->returnValue('$2a$10$x05G2P803MrB3jaORBXBn.QHtiYzGQOBjQ7unpEIge.Mrz6c3KiVm')); + ->willReturn('$2a$10$x05G2P803MrB3jaORBXBn.QHtiYzGQOBjQ7unpEIge.Mrz6c3KiVm'); $user->expects($this->once()) ->method('setPassword') ->with('$2a$10$D41KPuDCn6iGoESjnLee/uE/2Xo985sotVySo2HKDz6gAO4hO/Gh6'); @@ -365,11 +363,11 @@ public function testUpdateUserPasswordHashWithoutSameCost() $bcrypt = $this->createMock('Laminas\Crypt\Password\Bcrypt'); $bcrypt->expects($this->once()) ->method('getCost') - ->will($this->returnValue('5')); + ->willReturn('5'); $bcrypt->expects($this->once()) ->method('create') ->with('LmcUserNew') - ->will($this->returnValue('$2a$10$D41KPuDCn6iGoESjnLee/uE/2Xo985sotVySo2HKDz6gAO4hO/Gh6')); + ->willReturn('$2a$10$D41KPuDCn6iGoESjnLee/uE/2Xo985sotVySo2HKDz6gAO4hO/Gh6'); $mapper = $this->createMock('LmcUser\Mapper\User'); $mapper->expects($this->once()) @@ -444,7 +442,7 @@ public function testGetOptionsWithNoOptionsSet() $serviceMapper->expects($this->once()) ->method('get') ->with('lmcuser_module_options') - ->will($this->returnValue($this->options)); + ->willReturn($this->options); $this->db->setServiceManager($serviceMapper); @@ -478,7 +476,7 @@ public function testGetMapperWithNoMapperSet() $serviceMapper->expects($this->once()) ->method('get') ->with('lmcuser_user_mapper') - ->will($this->returnValue($this->mapper)); + ->willReturn($this->mapper); $this->db->setServiceManager($serviceMapper); @@ -507,11 +505,11 @@ protected function setAuthenticationEmail() $this->mapper->expects($this->once()) ->method('findByEmail') ->with('lmc-user@zf-commons.io') - ->will($this->returnValue($this->user)); + ->willReturn($this->user); $this->options->expects($this->once()) ->method('getAuthIdentityFields') - ->will($this->returnValue(array('email'))); + ->willReturn(array('email')); } protected function setAuthenticationUser() @@ -519,36 +517,36 @@ protected function setAuthenticationUser() $this->mapper->expects($this->once()) ->method('findByUsername') ->with('LmcUser') - ->will($this->returnValue($this->user)); + ->willReturn($this->user); $this->options->expects($this->once()) ->method('getAuthIdentityFields') - ->will($this->returnValue(array('username'))); + ->willReturn(array('username')); } protected function setAuthenticationCredentials($identity = 'LmcUser', $credential = 'LmcUserPassword') { - $this->storage->expects($this->at(0)) + $this->storage->expects($this->atLeastOnce()) ->method('read') - ->will($this->returnValue(array('is_satisfied' => false))); + ->willReturn(['is_satisfied' => false]); $post = $this->createMock('Laminas\Stdlib\Parameters'); $post->expects($this->at(0)) ->method('get') ->with('identity') - ->will($this->returnValue($identity)); + ->willReturn($identity); $post->expects($this->at(1)) ->method('get') ->with('credential') - ->will($this->returnValue($credential)); + ->willReturn($credential); $request = $this->createMock('Laminas\Http\Request'); $request->expects($this->exactly(2)) ->method('getPost') - ->will($this->returnValue($post)); + ->willReturn($post); $this->authEvent->expects($this->exactly(2)) ->method('getRequest') - ->will($this->returnValue($request)); + ->willReturn($request); } } diff --git a/tests/Authentication/Storage/DbTest.php b/tests/Authentication/Storage/DbTest.php index 01df9ef..fe9ae86 100644 --- a/tests/Authentication/Storage/DbTest.php +++ b/tests/Authentication/Storage/DbTest.php @@ -44,7 +44,7 @@ public function testIsEmpty() { $this->storage->expects($this->once()) ->method('isEmpty') - ->will($this->returnValue(true)); + ->willReturn(true); $this->db->setStorage($this->storage); @@ -71,7 +71,7 @@ public function testReadWithoutResolvedEntitySetIdentityIntUserFound() { $this->storage->expects($this->once()) ->method('read') - ->will($this->returnValue(1)); + ->willReturn(1); $this->db->setStorage($this->storage); @@ -81,7 +81,7 @@ public function testReadWithoutResolvedEntitySetIdentityIntUserFound() $this->mapper->expects($this->once()) ->method('findById') ->with(1) - ->will($this->returnValue($user)); + ->willReturn($user); $this->db->setMapper($this->mapper); @@ -97,14 +97,14 @@ public function testReadWithoutResolvedEntitySetIdentityIntUserNotFound() { $this->storage->expects($this->once()) ->method('read') - ->will($this->returnValue(1)); + ->willReturn(1); $this->db->setStorage($this->storage); $this->mapper->expects($this->once()) ->method('findById') ->with(1) - ->will($this->returnValue(false)); + ->willReturn(false); $this->db->setMapper($this->mapper); @@ -123,7 +123,7 @@ public function testReadWithoutResolvedEntitySetIdentityObject() $this->storage->expects($this->once()) ->method('read') - ->will($this->returnValue($user)); + ->willReturn($user); $this->db->setStorage($this->storage); @@ -180,7 +180,7 @@ public function testGetMapperWithNoMapperSet() $sm->expects($this->once()) ->method('get') ->with('lmcuser_user_mapper') - ->will($this->returnValue($this->mapper)); + ->willReturn($this->mapper); $this->db->setServiceManager($sm); diff --git a/tests/Controller/Plugin/LmcUserAuthenticationTest.php b/tests/Controller/Plugin/LmcUserAuthenticationTest.php index 2d9b051..9af119e 100644 --- a/tests/Controller/Plugin/LmcUserAuthenticationTest.php +++ b/tests/Controller/Plugin/LmcUserAuthenticationTest.php @@ -52,11 +52,11 @@ public function testGetAndHasIdentity() $this->mockedAuthenticationService->expects($this->any()) ->method('hasIdentity') - ->will($this->returnCallback($callback)); + ->willReturnCallback($callback); $this->mockedAuthenticationService->expects($this->any()) ->method('getIdentity') - ->will($this->returnCallback($callback)); + ->willReturnCallback($callback); $this->assertTrue($this->SUT->hasIdentity()); $this->assertFalse($this->SUT->hasIdentity()); diff --git a/tests/Controller/RedirectCallbackTest.php b/tests/Controller/RedirectCallbackTest.php index 0a04486..4cea3b9 100644 --- a/tests/Controller/RedirectCallbackTest.php +++ b/tests/Controller/RedirectCallbackTest.php @@ -86,7 +86,7 @@ public function testInvoke(): void $this->routeMatch->expects($this->once()) ->method('getMatchedRouteName') - ->will($this->returnValue('someRoute')); + ->willReturn('someRoute'); $headers = $this->createMock('Laminas\Http\Headers'); $headers->expects($this->once()) @@ -96,11 +96,11 @@ public function testInvoke(): void $this->router->expects($this->any()) ->method('assemble') ->with([], ['name' => 'lmcuser']) - ->will($this->returnValue($url)); + ->willReturn($url); $this->response->expects($this->once()) ->method('getHeaders') - ->will($this->returnValue($headers)); + ->willReturn($headers); $this->response->expects($this->once()) ->method('setStatusCode') @@ -120,7 +120,7 @@ public function testGetRedirectRouteFromRequest($get, $post, $getRouteExists, $p $this->request->expects($this->once()) ->method('getQuery') - ->will($this->returnValue($get)); + ->willReturn($get); if ($get) { $this->router->expects($this->any()) @@ -136,7 +136,7 @@ public function testGetRedirectRouteFromRequest($get, $post, $getRouteExists, $p if (!$get || !$getRouteExists) { $this->request->expects($this->once()) ->method('getPost') - ->will($this->returnValue($post)); + ->willReturn($post); if ($post) { $this->router->expects($this->any()) @@ -199,7 +199,7 @@ public function testRouteExistsRouteDoesntExists(): void $this->router->expects($this->once()) ->method('assemble') ->with([], ['name' => $route]) - ->will($this->throwException(new \Laminas\Router\Exception\RuntimeException)); + ->willThrowException(new \Laminas\Router\Exception\RuntimeException); $method = new \ReflectionMethod( RedirectCallback::class, @@ -262,7 +262,7 @@ public function testGetRedirectNoRedirectParam( ): void { $this->moduleOptions->expects($this->once()) ->method('getUseRedirectParameterIfPresent') - ->will($this->returnValue(true)); + ->willReturn(true); if ($routeMatch) { $routeMatch = $this->getMockBuilder(RouteMatch::class) @@ -279,7 +279,7 @@ public function testGetRedirectNoRedirectParam( $this->router->expects($routeMatch ? $this->never() : $this->exactly(2)) ->method('assemble') ->with([], ['name' => $redirect]) - ->will($this->returnValue($expectedResult)); + ->willReturn($expectedResult); $method = new \ReflectionMethod( RedirectCallback::class, @@ -310,16 +310,16 @@ public function testGetRedirectWithOptionOnButNoRedirect(): void $this->moduleOptions->expects($this->once()) ->method('getUseRedirectParameterIfPresent') - ->will($this->returnValue(true)); + ->willReturn(true); $this->moduleOptions->expects($this->once()) ->method('getLoginRedirectRoute') - ->will($this->returnValue($route)); + ->willReturn($route); $this->router->expects($this->once()) ->method('assemble') ->with([], ['name' => $route]) - ->will($this->returnValue($expectedResult)); + ->willReturn($expectedResult); $method = new \ReflectionMethod( RedirectCallback::class, @@ -339,7 +339,7 @@ public function testGetRedirectWithOptionOnRedirectDoesntExist(): void $this->moduleOptions->expects($this->once()) ->method('getUseRedirectParameterIfPresent') - ->will($this->returnValue(true)); + ->willReturn(true); $this->router->expects($this->once()) ->method('match') @@ -348,16 +348,16 @@ public function testGetRedirectWithOptionOnRedirectDoesntExist(): void $this->router->expects($this->at(1)) ->method('assemble') ->with([], ['name' => $redirect]) - ->will($this->throwException(new \Laminas\Router\Exception\RuntimeException)); + ->willThrowException(new \Laminas\Router\Exception\RuntimeException); $this->router->expects($this->at(2)) ->method('assemble') ->with([], ['name' => $route]) - ->will($this->returnValue($expectedResult)); + ->willReturn($expectedResult); $this->moduleOptions->expects($this->once()) ->method('getLoginRedirectRoute') - ->will($this->returnValue($route)); + ->willReturn($route); $method = new \ReflectionMethod( RedirectCallback::class, @@ -388,17 +388,17 @@ private function setUpApplication(): void ->getMock(); $this->mvcEvent->expects($this->any()) ->method('getRouteMatch') - ->will($this->returnValue($this->routeMatch)); + ->willReturn($this->routeMatch); $this->application->expects($this->any()) ->method('getMvcEvent') - ->will($this->returnValue($this->mvcEvent)); + ->willReturn($this->mvcEvent); $this->application->expects($this->any()) ->method('getRequest') - ->will($this->returnValue($this->request)); + ->willReturn($this->request); $this->application->expects($this->any()) ->method('getResponse') - ->will($this->returnValue($this->response)); + ->willReturn($this->response); } } diff --git a/tests/Controller/UserControllerTest.php b/tests/Controller/UserControllerTest.php index 96a16bd..2df4716 100644 --- a/tests/Controller/UserControllerTest.php +++ b/tests/Controller/UserControllerTest.php @@ -51,7 +51,7 @@ public function setUp():void $pluginManager->expects($this->any()) ->method('get') - ->will($this->returnCallback(array($this, 'helperMockCallbackPluginManagerGet'))); + ->willReturnCallback(array($this, 'helperMockCallbackPluginManagerGet')); $this->pluginManager = $pluginManager; @@ -117,14 +117,14 @@ public function testActionControllHasIdentity($methodeName, $hasIdentity, $redir if ($optionGetter) { $this->options->expects($this->once()) ->method($optionGetter) - ->will($this->returnValue($redirectRoute)); + ->willReturn($redirectRoute); } $redirect = $this->createMock('Laminas\Mvc\Controller\Plugin\Redirect'); $redirect->expects($this->once()) ->method('toRoute') ->with($redirectRoute) - ->will($this->returnValue($response)); + ->willReturn($response); $this->pluginManagerPlugins['redirect']= $redirect; @@ -174,21 +174,19 @@ public function testLoginActionValidFormRedirectFalse($isValid, $wantRedirect) $flashMessenger->expects($this->any()) ->method('setNamespace') - ->with('lmcuser-login-form') - ->will($this->returnSelf()); + ->with('lmcuser-login-form')->willReturnSelf(); $flashMessenger->expects($this->any()) - ->method('addMessage') - ->will($this->returnSelf()); + ->method('addMessage')->willReturnSelf(); $postArray = array('some', 'data'); $request = $this->createMock('Laminas\Http\Request'); $request->expects($this->any()) ->method('isPost') - ->will($this->returnValue(true)); + ->willReturn(true); $request->expects($this->any()) ->method('getPost') - ->will($this->returnValue($postArray)); + ->willReturn($postArray); $this->helperMakePropertyAccessable($controller, 'request', $request); @@ -198,19 +196,19 @@ public function testLoginActionValidFormRedirectFalse($isValid, $wantRedirect) $form->expects($this->any()) ->method('isValid') - ->will($this->returnValue((bool) $isValid)); + ->willReturn((bool) $isValid); $this->options->expects($this->any()) ->method('getUseRedirectParameterIfPresent') - ->will($this->returnValue((bool) $wantRedirect)); + ->willReturn((bool) $wantRedirect); if ($wantRedirect) { $params = new Parameters(); $params->set('redirect', $redirectUrl); $request->expects($this->any()) ->method('getQuery') - ->will($this->returnValue($params)); + ->willReturn($params); } if ($isValid) { @@ -241,7 +239,7 @@ public function testLoginActionValidFormRedirectFalse($isValid, $wantRedirect) $forwardPlugin->expects($this->once()) ->method('dispatch') ->with($controller::CONTROLLER_NAME, array('action' => 'authenticate')) - ->will($this->returnValue($expectedResult)); + ->willReturn($expectedResult); $this->pluginManagerPlugins['forward']= $forwardPlugin; } else { @@ -255,15 +253,13 @@ public function testLoginActionValidFormRedirectFalse($isValid, $wantRedirect) $redirect->expects($this->any()) ->method('toUrl') ->with($route_url . $redirectQuery) - ->will( - $this->returnCallback( - function ($url) use (&$response) { - $response->getHeaders()->addHeaderLine('Location', $url); - $response->setStatusCode(302); - - return $response; - } - ) + ->willReturnCallback( + function ($url) use (&$response) { + $response->getHeaders()->addHeaderLine('Location', $url); + $response->setStatusCode(302); + + return $response; + } ); $this->pluginManagerPlugins['redirect']= $redirect; @@ -274,7 +270,7 @@ function ($url) use (&$response) { $url->expects($this->once()) ->method('fromRoute') ->with($controller::ROUTE_LOGIN) - ->will($this->returnValue($route_url)); + ->willReturn($route_url); $this->pluginManagerPlugins['url']= $url; $TEST = true; @@ -312,7 +308,7 @@ public function testLoginActionIsNotPost($redirect) $request = $this->createMock('Laminas\Http\Request'); $request->expects($this->once()) ->method('isPost') - ->will($this->returnValue(false)); + ->willReturn(false); $form = $this->getMockBuilder('LmcUser\Form\Login') ->disableOriginalConstructor() @@ -322,14 +318,14 @@ public function testLoginActionIsNotPost($redirect) $this->options->expects($this->any()) ->method('getUseRedirectParameterIfPresent') - ->will($this->returnValue((bool) $redirect)); + ->willReturn((bool) $redirect); if ($redirect) { $params = new Parameters(); $params->set('redirect', 'http://localhost/'); $request->expects($this->any()) ->method('getQuery') - ->will($this->returnValue($params)); + ->willReturn($params); } $this->helperMakePropertyAccessable($this->controller, 'request', $request); @@ -385,7 +381,7 @@ public function testLogoutAction($withRedirect, $post, $query) $this->redirectCallback->expects($this->once()) ->method('__invoke') - ->will($this->returnValue($response)); + ->willReturn($response); $result = $controller->logoutAction(); @@ -406,25 +402,20 @@ public function testAuthenticateAction($wantRedirect, $post, $query, $prepareRes $params = $this->createMock('Laminas\Mvc\Controller\Plugin\Params'); $params->expects($this->any()) - ->method('__invoke') - ->will($this->returnSelf()); + ->method('__invoke')->willReturnSelf(); $params->expects($this->once()) ->method('fromPost') - ->will( - $this->returnCallback( - function ($key, $default) use ($post) { - return $post ?: $default; - } - ) + ->willReturnCallback( + function ($key, $default) use ($post) { + return $post ?: $default; + } ); $params->expects($this->once()) ->method('fromQuery') - ->will( - $this->returnCallback( - function ($key, $default) use ($query) { - return $query ?: $default; - } - ) + ->willReturnCallback( + function ($key, $default) use ($query) { + return $query ?: $default; + } ); $this->pluginManagerPlugins['params'] = $params; @@ -437,7 +428,7 @@ function ($key, $default) use ($query) { $adapter->expects($this->once()) ->method('prepareForAuthentication') ->with($request) - ->will($this->returnValue($prepareResult)); + ->willReturn($prepareResult); $service = $this->createMock('Laminas\Authentication\AuthenticationService'); @@ -456,12 +447,12 @@ function ($key, $default) use ($query) { ->getMock(); $authResult->expects($this->once()) ->method('isValid') - ->will($this->returnValue($authValid)); + ->willReturn($authValid); $service->expects($this->once()) ->method('authenticate') ->with($adapter) - ->will($this->returnValue($authResult)); + ->willReturn($authResult); $redirect = $this->createMock('Laminas\Mvc\Controller\Plugin\Redirect'); $this->pluginManagerPlugins['redirect'] = $redirect; @@ -474,8 +465,7 @@ function ($key, $default) use ($query) { $flashMessenger->expects($this->once()) ->method('setNamespace') - ->with('lmcuser-login-form') - ->will($this->returnSelf()); + ->with('lmcuser-login-form')->willReturnSelf(); $flashMessenger->expects($this->once()) ->method('addMessage'); @@ -489,13 +479,13 @@ function ($key, $default) use ($query) { $redirect->expects($this->once()) ->method('toUrl') ->with('user/login' . $redirectQuery) - ->will($this->returnValue($response)); + ->willReturn($response); $url = $this->createMock('Laminas\Mvc\Controller\Plugin\Url'); $url->expects($this->once()) ->method('fromRoute') ->with($controller::ROUTE_LOGIN) - ->will($this->returnValue('user/login')); + ->willReturn('user/login'); $this->pluginManagerPlugins['url'] = $url; } else { $this->redirectCallback->expects($this->once()) @@ -504,7 +494,7 @@ function ($key, $default) use ($query) { $this->options->expects($this->any()) ->method('getUseRedirectParameterIfPresent') - ->will($this->returnValue((bool) $wantRedirect)); + ->willReturn((bool) $wantRedirect); } $result = $controller->authenticateAction(); @@ -526,7 +516,7 @@ public function testRegisterActionIsNotAllowed() $this->options->expects($this->once()) ->method('getEnableRegistration') - ->will($this->returnValue(false)); + ->willReturn(false); $result = $controller->registerAction(); @@ -556,7 +546,7 @@ public function testRegisterAction($wantRedirect, $postRedirectGetReturn, $regis $this->options->expects($this->any()) ->method('getEnableRegistration') - ->will($this->returnValue(true)); + ->willReturn(true); $request = $this->createMock('Laminas\Http\Request'); $this->helperMakePropertyAccessable($controller, 'request', $request); @@ -572,7 +562,7 @@ public function testRegisterAction($wantRedirect, $postRedirectGetReturn, $regis $this->options->expects($this->any()) ->method('getUseRedirectParameterIfPresent') - ->will($this->returnValue((bool) $wantRedirect)); + ->willReturn((bool) $wantRedirect); if ($wantRedirect) { $params = new Parameters(); @@ -580,7 +570,7 @@ public function testRegisterAction($wantRedirect, $postRedirectGetReturn, $regis $request->expects($this->any()) ->method('getQuery') - ->will($this->returnValue($params)); + ->willReturn($params); } @@ -588,7 +578,7 @@ public function testRegisterAction($wantRedirect, $postRedirectGetReturn, $regis $url->expects($this->at(0)) ->method('fromRoute') ->with($controller::ROUTE_REGISTER) - ->will($this->returnValue($route_url)); + ->willReturn($route_url); $this->pluginManagerPlugins['url']= $url; @@ -599,7 +589,7 @@ public function testRegisterAction($wantRedirect, $postRedirectGetReturn, $regis $prg->expects($this->once()) ->method('__invoke') ->with($route_url . $redirectQuery) - ->will($this->returnValue($postRedirectGetReturn)); + ->willReturn($postRedirectGetReturn); if ($registerSuccess) { $user = new UserIdentity(); @@ -609,20 +599,20 @@ public function testRegisterAction($wantRedirect, $postRedirectGetReturn, $regis $userService->expects($this->once()) ->method('register') ->with($postRedirectGetReturn) - ->will($this->returnValue($user)); + ->willReturn($user); $userService->expects($this->any()) ->method('getOptions') - ->will($this->returnValue($this->options)); + ->willReturn($this->options); $this->options->expects($this->once()) ->method('getLoginAfterRegistration') - ->will($this->returnValue(!empty($loginAfterSuccessWith))); + ->willReturn(!empty($loginAfterSuccessWith)); if ($loginAfterSuccessWith) { $this->options->expects($this->once()) ->method('getAuthIdentityFields') - ->will($this->returnValue(array($loginAfterSuccessWith))); + ->willReturn(array($loginAfterSuccessWith)); $expectedResult = new \stdClass(); @@ -632,7 +622,7 @@ public function testRegisterAction($wantRedirect, $postRedirectGetReturn, $regis $forwardPlugin->expects($this->once()) ->method('dispatch') ->with($controller::CONTROLLER_NAME, array('action' => 'authenticate')) - ->will($this->returnValue($expectedResult)); + ->willReturn($expectedResult); $this->pluginManagerPlugins['forward']= $forwardPlugin; } else { @@ -649,7 +639,7 @@ public function testRegisterAction($wantRedirect, $postRedirectGetReturn, $regis $redirect->expects($this->once()) ->method('toUrl') ->with($route_url . $redirectQuery) - ->will($this->returnValue($response)); + ->willReturn($response); $this->pluginManagerPlugins['redirect']= $redirect; @@ -657,7 +647,7 @@ public function testRegisterAction($wantRedirect, $postRedirectGetReturn, $regis $url->expects($this->at(1)) ->method('fromRoute') ->with($controller::ROUTE_LOGIN) - ->will($this->returnValue($route_url)); + ->willReturn($route_url); } } @@ -734,12 +724,11 @@ public function testChangepasswordAction($status, $postRedirectGetReturn, $isVal $flashMessenger->expects($this->any()) ->method('setNamespace') - ->with('change-password') - ->will($this->returnSelf()); + ->with('change-password')->willReturnSelf(); $flashMessenger->expects($this->once()) ->method('getMessages') - ->will($this->returnValue($status ? array('test') : array())); + ->willReturn($status ? array('test') : array()); $prg = $this->createMock('Laminas\Mvc\Plugin\Prg\PostRedirectGet'); @@ -749,7 +738,7 @@ public function testChangepasswordAction($status, $postRedirectGetReturn, $isVal $prg->expects($this->once()) ->method('__invoke') ->with($controller::ROUTE_CHANGEPASSWD) - ->will($this->returnValue($postRedirectGetReturn)); + ->willReturn($postRedirectGetReturn); if ($postRedirectGetReturn !== false && !($postRedirectGetReturn instanceof Response)) { $form->expects($this->once()) @@ -758,7 +747,7 @@ public function testChangepasswordAction($status, $postRedirectGetReturn, $isVal $form->expects($this->once()) ->method('isValid') - ->will($this->returnValue((bool) $isValid)); + ->willReturn((bool) $isValid); if ($isValid) { $userService = $this->createMock('LmcUser\Service\User'); @@ -767,12 +756,12 @@ public function testChangepasswordAction($status, $postRedirectGetReturn, $isVal $form->expects($this->once()) ->method('getData') - ->will($this->returnValue($postRedirectGetReturn)); + ->willReturn($postRedirectGetReturn); $userService->expects($this->once()) ->method('changePassword') ->with($postRedirectGetReturn) - ->will($this->returnValue((bool) $changeSuccess)); + ->willReturn((bool) $changeSuccess); if ($changeSuccess) { @@ -785,7 +774,7 @@ public function testChangepasswordAction($status, $postRedirectGetReturn, $isVal $redirect->expects($this->once()) ->method('toRoute') ->with($controller::ROUTE_CHANGEPASSWD) - ->will($this->returnValue($response)); + ->willReturn($response); $this->pluginManagerPlugins['redirect']= $redirect; } @@ -852,11 +841,11 @@ public function testChangeEmailAction($status, $postRedirectGetReturn, $isValid, $userService->expects($this->once()) ->method('getAuthService') - ->will($this->returnValue($authService)); + ->willReturn($authService); $authService->expects($this->once()) ->method('getIdentity') - ->will($this->returnValue($identity)); + ->willReturn($identity); $identity->setEmail('user@example.com'); @@ -868,7 +857,7 @@ public function testChangeEmailAction($status, $postRedirectGetReturn, $isValid, $request = $this->createMock('Laminas\Http\Request'); $request->expects($this->once()) ->method('getPost') - ->will($this->returnValue($requestParams)); + ->willReturn($requestParams); $this->helperMakePropertyAccessable($controller, 'request', $request); @@ -880,12 +869,11 @@ public function testChangeEmailAction($status, $postRedirectGetReturn, $isValid, $flashMessenger->expects($this->any()) ->method('setNamespace') - ->with('change-email') - ->will($this->returnSelf()); + ->with('change-email')->willReturnSelf(); $flashMessenger->expects($this->once()) ->method('getMessages') - ->will($this->returnValue($status ? array('test') : array())); + ->willReturn($status ? array('test') : array()); $prg = $this->createMock('Laminas\Mvc\Plugin\Prg\PostRedirectGet'); @@ -895,7 +883,7 @@ public function testChangeEmailAction($status, $postRedirectGetReturn, $isValid, $prg->expects($this->once()) ->method('__invoke') ->with($controller::ROUTE_CHANGEEMAIL) - ->will($this->returnValue($postRedirectGetReturn)); + ->willReturn($postRedirectGetReturn); if ($postRedirectGetReturn !== false && !($postRedirectGetReturn instanceof Response)) { $form->expects($this->once()) @@ -904,13 +892,13 @@ public function testChangeEmailAction($status, $postRedirectGetReturn, $isValid, $form->expects($this->once()) ->method('isValid') - ->will($this->returnValue((bool) $isValid)); + ->willReturn((bool) $isValid); if ($isValid) { $userService->expects($this->once()) ->method('changeEmail') ->with($postRedirectGetReturn) - ->will($this->returnValue((bool) $changeSuccess)); + ->willReturn((bool) $changeSuccess); if ($changeSuccess) { @@ -923,7 +911,7 @@ public function testChangeEmailAction($status, $postRedirectGetReturn, $isValid, $redirect->expects($this->once()) ->method('toRoute') ->with($controller::ROUTE_CHANGEEMAIL) - ->will($this->returnValue($response)); + ->willReturn($response); $this->pluginManagerPlugins['redirect']= $redirect; } else { @@ -989,7 +977,7 @@ public function testSetterGetterServices( $serviceLocator->expects($this->once()) ->method('get') ->with($serviceName) - ->will($this->returnValue($servicePrototype)); + ->willReturn($servicePrototype); $controller->setServiceLocator($serviceLocator); } else { call_user_func(array($controller, 'set' . $method), $servicePrototype); @@ -1070,8 +1058,7 @@ public function providerTestSetterGetterServices() $flashMessenger->expects($that->any()) ->method('setNamespace') - ->with('lmcuser-login-form') - ->will($that->returnSelf()); + ->with('lmcuser-login-form')->willReturnSelf(); }; $loginFormCallback[] = function ($that, $controller) { $flashMessenger = $that->createMock( @@ -1081,8 +1068,7 @@ public function providerTestSetterGetterServices() $flashMessenger->expects($that->any()) ->method('setNamespace') - ->with('lmcuser-login-form') - ->will($that->returnSelf()); + ->with('lmcuser-login-form')->willReturnSelf(); }; diff --git a/tests/Form/ChangeEmailFilterTest.php b/tests/Form/ChangeEmailFilterTest.php index d89acd1..d5eb379 100644 --- a/tests/Form/ChangeEmailFilterTest.php +++ b/tests/Form/ChangeEmailFilterTest.php @@ -12,7 +12,7 @@ public function testConstruct() $options = $this->createMock('LmcUser\Options\ModuleOptions'); $options->expects($this->once()) ->method('getAuthIdentityFields') - ->will($this->returnValue(array('email'))); + ->willReturn(array('email')); $validator = $this->getMockBuilder('LmcUser\Validator\NoRecordExists')->disableOriginalConstructor()->getMock(); $filter = new Filter($options, $validator); @@ -35,7 +35,7 @@ public function testConstructIdentityEmail($onlyEmail) $options = $this->createMock('LmcUser\Options\ModuleOptions'); $options->expects($this->once()) ->method('getAuthIdentityFields') - ->will($this->returnValue(($onlyEmail) ? array('email') : array('username'))); + ->willReturn(($onlyEmail) ? array('email') : array('username')); $validator = $this->getMockBuilder('LmcUser\Validator\NoRecordExists')->disableOriginalConstructor()->getMock(); $filter = new Filter($options, $validator); @@ -62,7 +62,7 @@ public function testSetGetEmailValidator() $options = $this->createMock('LmcUser\Options\ModuleOptions'); $options->expects($this->once()) ->method('getAuthIdentityFields') - ->will($this->returnValue(array())); + ->willReturn(array()); $validatorInit = $this->getMockBuilder('LmcUser\Validator\NoRecordExists')->disableOriginalConstructor()->getMock(); $validatorNew = $this->getMockBuilder('LmcUser\Validator\NoRecordExists')->disableOriginalConstructor()->getMock(); diff --git a/tests/Form/ChangePasswordFilterTest.php b/tests/Form/ChangePasswordFilterTest.php index e6222f2..2bd8adc 100644 --- a/tests/Form/ChangePasswordFilterTest.php +++ b/tests/Form/ChangePasswordFilterTest.php @@ -12,7 +12,7 @@ public function testConstruct() $options = $this->createMock('LmcUser\Options\ModuleOptions'); $options->expects($this->once()) ->method('getAuthIdentityFields') - ->will($this->returnValue(array('email'))); + ->willReturn(array('email')); $filter = new Filter($options); @@ -35,7 +35,7 @@ public function testConstructIdentityEmail($onlyEmail) $options = $this->createMock('LmcUser\Options\ModuleOptions'); $options->expects($this->once()) ->method('getAuthIdentityFields') - ->will($this->returnValue($onlyEmail ? array('email') : array('username'))); + ->willReturn($onlyEmail ? array('email') : array('username')); $filter = new Filter($options); diff --git a/tests/Form/LoginFilterTest.php b/tests/Form/LoginFilterTest.php index 491c7a0..2437520 100644 --- a/tests/Form/LoginFilterTest.php +++ b/tests/Form/LoginFilterTest.php @@ -15,7 +15,7 @@ public function testConstruct() $options = $this->createMock('LmcUser\Options\ModuleOptions'); $options->expects($this->once()) ->method('getAuthIdentityFields') - ->will($this->returnValue(array())); + ->willReturn(array()); $filter = new Filter($options); @@ -34,7 +34,7 @@ public function testConstructIdentityEmail() $options = $this->createMock('LmcUser\Options\ModuleOptions'); $options->expects($this->once()) ->method('getAuthIdentityFields') - ->will($this->returnValue(array('email'))); + ->willReturn(array('email')); $filter = new Filter($options); diff --git a/tests/Form/LoginTest.php b/tests/Form/LoginTest.php index 2a75122..7417414 100644 --- a/tests/Form/LoginTest.php +++ b/tests/Form/LoginTest.php @@ -16,7 +16,7 @@ public function testConstruct($authIdentityFields = array()) $options = $this->createMock('LmcUser\Options\AuthenticationOptionsInterface'); $options->expects($this->once()) ->method('getAuthIdentityFields') - ->will($this->returnValue($authIdentityFields)); + ->willReturn($authIdentityFields); $form = new Form(null, $options); @@ -46,7 +46,7 @@ public function testSetGetAuthenticationOptions() $options = $this->createMock('LmcUser\Options\AuthenticationOptionsInterface'); $options->expects($this->once()) ->method('getAuthIdentityFields') - ->will($this->returnValue(array())); + ->willReturn(array()); $form = new Form(null, $options); $this->assertSame($options, $form->getAuthenticationOptions()); diff --git a/tests/Form/RegisterFilterTest.php b/tests/Form/RegisterFilterTest.php index 89e8588..549990e 100644 --- a/tests/Form/RegisterFilterTest.php +++ b/tests/Form/RegisterFilterTest.php @@ -15,10 +15,10 @@ public function testConstruct() $options = $this->createMock('LmcUser\Options\ModuleOptions'); $options->expects($this->once()) ->method('getEnableUsername') - ->will($this->returnValue(true)); + ->willReturn(true); $options->expects($this->once()) ->method('getEnableDisplayName') - ->will($this->returnValue(true)); + ->willReturn(true); $emailValidator = $this->getMockBuilder('LmcUser\Validator\NoRecordExists')->disableOriginalConstructor()->getMock(); $usernameValidator = $this->getMockBuilder('LmcUser\Validator\NoRecordExists')->disableOriginalConstructor()->getMock(); diff --git a/tests/Form/RegisterTest.php b/tests/Form/RegisterTest.php index be8ed37..8f33c31 100644 --- a/tests/Form/RegisterTest.php +++ b/tests/Form/RegisterTest.php @@ -15,19 +15,19 @@ public function testConstruct($useCaptcha = false) $options = $this->createMock('LmcUser\Options\RegistrationOptionsInterface'); $options->expects($this->once()) ->method('getEnableUsername') - ->will($this->returnValue(false)); + ->willReturn(false); $options->expects($this->once()) ->method('getEnableDisplayName') - ->will($this->returnValue(false)); + ->willReturn(false); $options->expects($this->any()) ->method('getUseRegistrationFormCaptcha') - ->will($this->returnValue($useCaptcha)); + ->willReturn($useCaptcha); if ($useCaptcha && class_exists('\Laminas\Captcha\AbstractAdapter')) { $captcha = $this->getMockForAbstractClass('\Laminas\Captcha\AbstractAdapter'); $options->expects($this->once()) ->method('getFormCaptchaOptions') - ->will($this->returnValue($captcha)); + ->willReturn($captcha); } $form = new Form(null, $options); @@ -55,13 +55,13 @@ public function testSetGetRegistrationOptions() $options = $this->createMock('LmcUser\Options\RegistrationOptionsInterface'); $options->expects($this->once()) ->method('getEnableUsername') - ->will($this->returnValue(false)); + ->willReturn(false); $options->expects($this->once()) ->method('getEnableDisplayName') - ->will($this->returnValue(false)); + ->willReturn(false); $options->expects($this->any()) ->method('getUseRegistrationFormCaptcha') - ->will($this->returnValue(false)); + ->willReturn(false); $form = new Form(null, $options); $this->assertSame($options, $form->getRegistrationOptions()); @@ -76,13 +76,13 @@ public function testSetCaptchaElement() $options = $this->createMock('LmcUser\Options\RegistrationOptionsInterface'); $options->expects($this->once()) ->method('getEnableUsername') - ->will($this->returnValue(false)); + ->willReturn(false); $options->expects($this->once()) ->method('getEnableDisplayName') - ->will($this->returnValue(false)); + ->willReturn(false); $options->expects($this->any()) ->method('getUseRegistrationFormCaptcha') - ->will($this->returnValue(false)); + ->willReturn(false); $captcha = $this->createMock('\Laminas\Form\Element\Captcha'); $form = new Form(null, $options); diff --git a/tests/Mapper/UserTest.php b/tests/Mapper/UserTest.php index e0dabdd..3b8a07f 100644 --- a/tests/Mapper/UserTest.php +++ b/tests/Mapper/UserTest.php @@ -145,7 +145,7 @@ public function setUpMockedAdapter() $this->mockedDbAdapterPlatform->expects($this->any()) ->method('getName') - ->will($this->returnValue('null')); + ->willReturn('null'); $this->mockedDbAdapter = $this->getMockBuilder('Laminas\Db\Adapter\Adapter') ->setConstructorArgs( @@ -158,7 +158,7 @@ public function setUpMockedAdapter() $this->mockedDbAdapter->expects($this->any()) ->method('getPlatform') - ->will($this->returnValue($this->mockedDbAdapterPlatform)); + ->willReturn($this->mockedDbAdapterPlatform); $this->mockedDbSql = $this->getMockBuilder('Laminas\Db\Sql\Sql') ->setConstructorArgs(array($this->mockedDbAdapter)) @@ -166,7 +166,7 @@ public function setUpMockedAdapter() ->getMock(); $this->mockedDbSql->expects($this->any()) ->method('prepareStatementForSqlObject') - ->will($this->returnValue($this->mockedDbAdapterStatement)); + ->willReturn($this->mockedDbAdapterStatement); $this->mockedDbSqlPlatform = $this->getMockBuilder('\Laminas\Db\Sql\Platform\Platform') ->setConstructorArgs(array($this->mockedDbAdapter)) @@ -189,12 +189,12 @@ public function setUpMockMapperInsert($mapperMethods) case 'getSelect': $this->mapper->expects($this->once()) ->method('getSelect') - ->will($this->returnValue($this->mockedSelect)); + ->willReturn($this->mockedSelect); break; case 'initialize': $this->mapper->expects($this->once()) ->method('initialize') - ->will($this->returnValue(true)); + ->willReturn(true); break; } } @@ -217,18 +217,16 @@ public function &setUpMockedMapper($eventListenerArray, array $mapperMethods = a $this->mapper->expects($this->once()) ->method('select') - ->will($this->returnValue($this->mockedResultSet)); + ->willReturn($this->mockedResultSet); $mockedSelect = $this->mockedSelect; $this->mockedSelect->expects($this->once()) ->method('where') - ->will( - $this->returnCallback( - function () use (&$returnMockedParams, $mockedSelect) { - $returnMockedParams['whereArgs'] = func_get_args(); - return $mockedSelect; - } - ) + ->willReturnCallback( + function () use (&$returnMockedParams, $mockedSelect) { + $returnMockedParams['whereArgs'] = func_get_args(); + return $mockedSelect; + } ); foreach ($eventListenerArray as $eventKey => $eventListener) { @@ -253,7 +251,7 @@ public function testFindBy($method, $args, $expectedParams, $eventListener, $ent $this->mockedResultSet->expects($this->once()) ->method('current') - ->will($this->returnValue($entityEqual)); + ->willReturn($entityEqual); $return = call_user_func_array(array($this->mapper, $method), $args); diff --git a/tests/Service/UserTest.php b/tests/Service/UserTest.php index 3042237..49c7aa1 100644 --- a/tests/Service/UserTest.php +++ b/tests/Service/UserTest.php @@ -62,7 +62,7 @@ public function testRegisterWithInvalidForm() $this->options->expects($this->once()) ->method('getUserEntityClass') - ->will($this->returnValue('LmcUser\Entity\User')); + ->willReturn('LmcUser\Entity\User'); $registerForm = $this->getMockBuilder('LmcUser\Form\Register')->disableOriginalConstructor()->getMock(); $registerForm->expects($this->once()) @@ -74,7 +74,7 @@ public function testRegisterWithInvalidForm() ->with($expectArray); $registerForm->expects($this->once()) ->method('isValid') - ->will($this->returnValue(false)); + ->willReturn(false); $this->service->setRegisterForm($registerForm); @@ -107,22 +107,22 @@ public function testRegisterWithUsernameAndDisplayNameUserStateDisabled() $this->options->expects($this->once()) ->method('getUserEntityClass') - ->will($this->returnValue('LmcUser\Entity\User')); + ->willReturn('LmcUser\Entity\User'); $this->options->expects($this->once()) ->method('getPasswordCost') - ->will($this->returnValue(4)); + ->willReturn(4); $this->options->expects($this->once()) ->method('getEnableUsername') - ->will($this->returnValue(true)); + ->willReturn(true); $this->options->expects($this->once()) ->method('getEnableDisplayName') - ->will($this->returnValue(true)); + ->willReturn(true); $this->options->expects($this->once()) ->method('getEnableUserState') - ->will($this->returnValue(true)); + ->willReturn(true); $this->options->expects($this->once()) ->method('getDefaultUserState') - ->will($this->returnValue(1)); + ->willReturn(1); $registerForm = $this->getMockBuilder('LmcUser\Form\Register')->disableOriginalConstructor()->getMock(); $registerForm->expects($this->once()) @@ -134,10 +134,10 @@ public function testRegisterWithUsernameAndDisplayNameUserStateDisabled() ->with($expectArray); $registerForm->expects($this->once()) ->method('getData') - ->will($this->returnValue($user)); + ->willReturn($user); $registerForm->expects($this->once()) ->method('isValid') - ->will($this->returnValue(true)); + ->willReturn(true); $this->eventManager->expects($this->exactly(2)) ->method('trigger'); @@ -145,7 +145,7 @@ public function testRegisterWithUsernameAndDisplayNameUserStateDisabled() $this->mapper->expects($this->once()) ->method('insert') ->with($user) - ->will($this->returnValue($user)); + ->willReturn($user); $this->service->setRegisterForm($registerForm); @@ -178,22 +178,22 @@ public function testRegisterWithDefaultUserStateOfZero() $this->options->expects($this->once()) ->method('getUserEntityClass') - ->will($this->returnValue('LmcUser\Entity\User')); + ->willReturn('LmcUser\Entity\User'); $this->options->expects($this->once()) ->method('getPasswordCost') - ->will($this->returnValue(4)); + ->willReturn(4); $this->options->expects($this->once()) ->method('getEnableUsername') - ->will($this->returnValue(true)); + ->willReturn(true); $this->options->expects($this->once()) ->method('getEnableDisplayName') - ->will($this->returnValue(true)); + ->willReturn(true); $this->options->expects($this->once()) ->method('getEnableUserState') - ->will($this->returnValue(true)); + ->willReturn(true); $this->options->expects($this->once()) ->method('getDefaultUserState') - ->will($this->returnValue(0)); + ->willReturn(0); $registerForm = $this->getMockBuilder('LmcUser\Form\Register')->disableOriginalConstructor()->getMock(); $registerForm->expects($this->once()) @@ -205,10 +205,10 @@ public function testRegisterWithDefaultUserStateOfZero() ->with($expectArray); $registerForm->expects($this->once()) ->method('getData') - ->will($this->returnValue($user)); + ->willReturn($user); $registerForm->expects($this->once()) ->method('isValid') - ->will($this->returnValue(true)); + ->willReturn(true); $this->eventManager->expects($this->exactly(2)) ->method('trigger'); @@ -216,7 +216,7 @@ public function testRegisterWithDefaultUserStateOfZero() $this->mapper->expects($this->once()) ->method('insert') ->with($user) - ->will($this->returnValue($user)); + ->willReturn($user); $this->service->setRegisterForm($registerForm); @@ -249,19 +249,19 @@ public function testRegisterWithUserStateDisabled() $this->options->expects($this->once()) ->method('getUserEntityClass') - ->will($this->returnValue('LmcUser\Entity\User')); + ->willReturn('LmcUser\Entity\User'); $this->options->expects($this->once()) ->method('getPasswordCost') - ->will($this->returnValue(4)); + ->willReturn(4); $this->options->expects($this->once()) ->method('getEnableUsername') - ->will($this->returnValue(true)); + ->willReturn(true); $this->options->expects($this->once()) ->method('getEnableDisplayName') - ->will($this->returnValue(true)); + ->willReturn(true); $this->options->expects($this->once()) ->method('getEnableUserState') - ->will($this->returnValue(false)); + ->willReturn(false); $this->options->expects($this->never()) ->method('getDefaultUserState'); @@ -275,10 +275,10 @@ public function testRegisterWithUserStateDisabled() ->with($expectArray); $registerForm->expects($this->once()) ->method('getData') - ->will($this->returnValue($user)); + ->willReturn($user); $registerForm->expects($this->once()) ->method('isValid') - ->will($this->returnValue(true)); + ->willReturn(true); $this->eventManager->expects($this->exactly(2)) ->method('trigger'); @@ -286,7 +286,7 @@ public function testRegisterWithUserStateDisabled() $this->mapper->expects($this->once()) ->method('insert') ->with($user) - ->will($this->returnValue($user)); + ->willReturn($user); $this->service->setRegisterForm($registerForm); @@ -305,7 +305,7 @@ public function testChangePasswordWithWrongOldPassword() $this->options->expects($this->any()) ->method('getPasswordCost') - ->will($this->returnValue(4)); + ->willReturn(4); $bcrypt = new Bcrypt(); $bcrypt->setCost($this->options->getPasswordCost()); @@ -313,11 +313,11 @@ public function testChangePasswordWithWrongOldPassword() $user = $this->createMock('LmcUser\Entity\User'); $user->expects($this->any()) ->method('getPassword') - ->will($this->returnValue($bcrypt->create('wrongPassword'))); + ->willReturn($bcrypt->create('wrongPassword')); $this->authService->expects($this->any()) ->method('getIdentity') - ->will($this->returnValue($user)); + ->willReturn($user); $result = $this->service->changePassword($data); $this->assertFalse($result); @@ -332,7 +332,7 @@ public function testChangePassword() $this->options->expects($this->any()) ->method('getPasswordCost') - ->will($this->returnValue(4)); + ->willReturn(4); $bcrypt = new Bcrypt(); $bcrypt->setCost($this->options->getPasswordCost()); @@ -340,13 +340,13 @@ public function testChangePassword() $user = $this->createMock('LmcUser\Entity\User'); $user->expects($this->any()) ->method('getPassword') - ->will($this->returnValue($bcrypt->create($data['credential']))); + ->willReturn($bcrypt->create($data['credential'])); $user->expects($this->any()) ->method('setPassword'); $this->authService->expects($this->any()) ->method('getIdentity') - ->will($this->returnValue($user)); + ->willReturn($user); $this->eventManager->expects($this->exactly(2)) ->method('trigger'); @@ -368,7 +368,7 @@ public function testChangeEmail() $this->options->expects($this->any()) ->method('getPasswordCost') - ->will($this->returnValue(4)); + ->willReturn(4); $bcrypt = new Bcrypt(); $bcrypt->setCost($this->options->getPasswordCost()); @@ -376,14 +376,14 @@ public function testChangeEmail() $user = $this->createMock('LmcUser\Entity\User'); $user->expects($this->any()) ->method('getPassword') - ->will($this->returnValue($bcrypt->create($data['credential']))); + ->willReturn($bcrypt->create($data['credential'])); $user->expects($this->any()) ->method('setEmail') ->with('lmcUser@lmcUser.com'); $this->authService->expects($this->any()) ->method('getIdentity') - ->will($this->returnValue($user)); + ->willReturn($user); $this->eventManager->expects($this->exactly(2)) ->method('trigger'); @@ -405,7 +405,7 @@ public function testChangeEmailWithWrongPassword() $this->options->expects($this->any()) ->method('getPasswordCost') - ->will($this->returnValue(4)); + ->willReturn(4); $bcrypt = new Bcrypt(); $bcrypt->setCost($this->options->getPasswordCost()); @@ -413,11 +413,11 @@ public function testChangeEmailWithWrongPassword() $user = $this->createMock('LmcUser\Entity\User'); $user->expects($this->any()) ->method('getPassword') - ->will($this->returnValue($bcrypt->create('wrongPassword'))); + ->willReturn($bcrypt->create('wrongPassword')); $this->authService->expects($this->any()) ->method('getIdentity') - ->will($this->returnValue($user)); + ->willReturn($user); $result = $this->service->changeEmail($data); $this->assertFalse($result); @@ -431,7 +431,7 @@ public function testGetUserMapper() $this->serviceManager->expects($this->once()) ->method('get') ->with('lmcuser_user_mapper') - ->will($this->returnValue($this->mapper)); + ->willReturn($this->mapper); $service = new Service; $service->setServiceManager($this->serviceManager); @@ -455,7 +455,7 @@ public function testGetAuthService() $this->serviceManager->expects($this->once()) ->method('get') ->with('lmcuser_auth_service') - ->will($this->returnValue($this->authService)); + ->willReturn($this->authService); $service = new Service; $service->setServiceManager($this->serviceManager); @@ -481,7 +481,7 @@ public function testGetRegisterForm() $this->serviceManager->expects($this->once()) ->method('get') ->with('lmcuser_register_form') - ->will($this->returnValue($form)); + ->willReturn($form); $service = new Service; $service->setServiceManager($this->serviceManager); @@ -514,7 +514,7 @@ public function testGetChangePasswordForm() $this->serviceManager->expects($this->once()) ->method('get') ->with('lmcuser_change_password_form') - ->will($this->returnValue($form)); + ->willReturn($form); $service = new Service; $service->setServiceManager($this->serviceManager); @@ -541,7 +541,7 @@ public function testGetOptions() $this->serviceManager->expects($this->once()) ->method('get') ->with('lmcuser_module_options') - ->will($this->returnValue($this->options)); + ->willReturn($this->options); $service = new Service; $service->setServiceManager($this->serviceManager); @@ -573,7 +573,7 @@ public function testGetFormHydrator() $this->serviceManager->expects($this->once()) ->method('get') ->with('lmcuser_register_form_hydrator') - ->will($this->returnValue($this->formHydrator)); + ->willReturn($this->formHydrator); $service = new Service; $service->setServiceManager($this->serviceManager); diff --git a/tests/Validator/AbstractRecordTest.php b/tests/Validator/AbstractRecordTest.php index 7713d05..49d06ae 100644 --- a/tests/Validator/AbstractRecordTest.php +++ b/tests/Validator/AbstractRecordTest.php @@ -87,7 +87,7 @@ public function testQueryWithKeyUsername() $mapper->expects($this->once()) ->method('findByUsername') ->with('test') - ->will($this->returnValue('LmcUser')); + ->willReturn('LmcUser'); $validator->setMapper($mapper); @@ -111,7 +111,7 @@ public function testQueryWithKeyEmail() $mapper->expects($this->once()) ->method('findByEmail') ->with('test@test.com') - ->will($this->returnValue('LmcUser')); + ->willReturn('LmcUser'); $validator->setMapper($mapper); diff --git a/tests/Validator/NoRecordExistsTest.php b/tests/Validator/NoRecordExistsTest.php index 7c1f8b5..828ecb8 100644 --- a/tests/Validator/NoRecordExistsTest.php +++ b/tests/Validator/NoRecordExistsTest.php @@ -31,7 +31,7 @@ public function testIsValid() $this->mapper->expects($this->once()) ->method('findByUsername') ->with('lmcUser') - ->will($this->returnValue(false)); + ->willReturn(false); $result = $this->validator->isValid('lmcUser'); $this->assertTrue($result); @@ -45,7 +45,7 @@ public function testIsInvalid() $this->mapper->expects($this->once()) ->method('findByUsername') ->with('lmcUser') - ->will($this->returnValue('lmcUser')); + ->willReturn('lmcUser'); $result = $this->validator->isValid('lmcUser'); $this->assertFalse($result); diff --git a/tests/Validator/RecordExistsTest.php b/tests/Validator/RecordExistsTest.php index e245d61..ad4cb60 100644 --- a/tests/Validator/RecordExistsTest.php +++ b/tests/Validator/RecordExistsTest.php @@ -31,7 +31,7 @@ public function testIsValid() $this->mapper->expects($this->once()) ->method('findByUsername') ->with('lmcUser') - ->will($this->returnValue('lmcUser')); + ->willReturn('lmcUser'); $result = $this->validator->isValid('lmcUser'); $this->assertTrue($result); @@ -45,7 +45,7 @@ public function testIsInvalid() $this->mapper->expects($this->once()) ->method('findByUsername') ->with('lmcUser') - ->will($this->returnValue(false)); + ->willReturn(false); $result = $this->validator->isValid('lmcUser'); $this->assertFalse($result); diff --git a/tests/View/Helper/LmcUserDisplayNameTest.php b/tests/View/Helper/LmcUserDisplayNameTest.php index fff3dea..7b3893c 100644 --- a/tests/View/Helper/LmcUserDisplayNameTest.php +++ b/tests/View/Helper/LmcUserDisplayNameTest.php @@ -35,7 +35,7 @@ public function testInvokeWithoutUserAndNotLoggedIn() { $this->authService->expects($this->once()) ->method('hasIdentity') - ->will($this->returnValue(false)); + ->willReturn(false); $result = $this->helper->__invoke(null); @@ -50,10 +50,10 @@ public function testInvokeWithoutUserButLoggedInWithWrongUserObject() $this->expectException(DomainException::class); $this->authService->expects($this->once()) ->method('hasIdentity') - ->will($this->returnValue(true)); + ->willReturn(true); $this->authService->expects($this->once()) ->method('getIdentity') - ->will($this->returnValue(new \StdClass)); + ->willReturn(new \StdClass); $this->helper->__invoke(null); } @@ -65,14 +65,14 @@ public function testInvokeWithoutUserButLoggedInWithDisplayName() { $this->user->expects($this->once()) ->method('getDisplayName') - ->will($this->returnValue('lmcUser')); + ->willReturn('lmcUser'); $this->authService->expects($this->once()) ->method('hasIdentity') - ->will($this->returnValue(true)); + ->willReturn(true); $this->authService->expects($this->once()) ->method('getIdentity') - ->will($this->returnValue($this->user)); + ->willReturn($this->user); $result = $this->helper->__invoke(null); @@ -86,17 +86,17 @@ public function testInvokeWithoutUserButLoggedInWithoutDisplayNameButWithUsernam { $this->user->expects($this->once()) ->method('getDisplayName') - ->will($this->returnValue(null)); + ->willReturn(null); $this->user->expects($this->once()) ->method('getUsername') - ->will($this->returnValue('lmcUser')); + ->willReturn('lmcUser'); $this->authService->expects($this->once()) ->method('hasIdentity') - ->will($this->returnValue(true)); + ->willReturn(true); $this->authService->expects($this->once()) ->method('getIdentity') - ->will($this->returnValue($this->user)); + ->willReturn($this->user); $result = $this->helper->__invoke(null); @@ -110,20 +110,20 @@ public function testInvokeWithoutUserButLoggedInWithoutDisplayNameAndWithOutUser { $this->user->expects($this->once()) ->method('getDisplayName') - ->will($this->returnValue(null)); + ->willReturn(null); $this->user->expects($this->once()) ->method('getUsername') - ->will($this->returnValue(null)); + ->willReturn(null); $this->user->expects($this->once()) ->method('getEmail') - ->will($this->returnValue('lmcUser@lmcUser.com')); + ->willReturn('lmcUser@lmcUser.com'); $this->authService->expects($this->once()) ->method('hasIdentity') - ->will($this->returnValue(true)); + ->willReturn(true); $this->authService->expects($this->once()) ->method('getIdentity') - ->will($this->returnValue($this->user)); + ->willReturn($this->user); $result = $this->helper->__invoke(null); diff --git a/tests/View/Helper/LmcUserIdentityTest.php b/tests/View/Helper/LmcUserIdentityTest.php index 35b3be2..f369feb 100644 --- a/tests/View/Helper/LmcUserIdentityTest.php +++ b/tests/View/Helper/LmcUserIdentityTest.php @@ -29,10 +29,10 @@ public function testInvokeWithIdentity() { $this->authService->expects($this->once()) ->method('hasIdentity') - ->will($this->returnValue(true)); + ->willReturn(true); $this->authService->expects($this->once()) ->method('getIdentity') - ->will($this->returnValue('lmcUser')); + ->willReturn('lmcUser'); $result = $this->helper->__invoke(); @@ -46,7 +46,7 @@ public function testInvokeWithoutIdentity() { $this->authService->expects($this->once()) ->method('hasIdentity') - ->will($this->returnValue(false)); + ->willReturn(false); $result = $this->helper->__invoke(); diff --git a/tests/View/Helper/LmcUserLoginWidgetTest.php b/tests/View/Helper/LmcUserLoginWidgetTest.php index 48b349a..7f1d1be 100644 --- a/tests/View/Helper/LmcUserLoginWidgetTest.php +++ b/tests/View/Helper/LmcUserLoginWidgetTest.php @@ -70,13 +70,11 @@ public function testInvokeWithRender($option, $expect) $this->view->expects($this->at(0)) ->method('render') - ->will( - $this->returnCallback( - function ($vm) use (&$viewModel) { - $viewModel = $vm; - return "test"; - } - ) + ->willReturnCallback( + function ($vm) use (&$viewModel) { + $viewModel = $vm; + return "test"; + } ); $result = $this->helper->__invoke($option); From 6209762649d72a289b6baf3fde3c4a49e3a292c4 Mon Sep 17 00:00:00 2001 From: Romain BASTIDE Date: Tue, 14 Feb 2023 00:27:21 +0100 Subject: [PATCH 4/5] Remove useless extra comma --- tests/Authentication/Adapter/DbTest.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/Authentication/Adapter/DbTest.php b/tests/Authentication/Adapter/DbTest.php index 2b018ca..89e4114 100644 --- a/tests/Authentication/Adapter/DbTest.php +++ b/tests/Authentication/Adapter/DbTest.php @@ -112,7 +112,6 @@ public function testAuthenticateWhenSatisfies() $result = $this->db->authenticate($this->authEvent); - ; $this->assertNull($result); } @@ -213,7 +212,6 @@ public function testAuthenticateWithWrongPassword() $result = $this->db->authenticate($this->authEvent); - ; $this->assertFalse($result); $this->assertFalse($this->db->isSatisfied()); @@ -264,7 +262,6 @@ public function testAuthenticationAuthenticatesWithEmail() $result = $this->db->authenticate($this->authEvent); - ; } /** @@ -319,7 +316,6 @@ public function testAuthenticationAuthenticates() $result = $this->db->authenticate($this->authEvent); - ; } /** From 2dcf938c7163198fd0a9200070ed2a348b9cf41d Mon Sep 17 00:00:00 2001 From: Romain BASTIDE Date: Tue, 14 Feb 2023 01:17:26 +0100 Subject: [PATCH 5/5] Rewrite some tests to remove ->at() calls (deprecated, and will be removed in PHPUnit 10) --- tests/Authentication/Adapter/DbTest.php | 10 +++----- tests/Controller/RedirectCallbackTest.php | 26 ++++++++++++++------ tests/Controller/UserControllerTest.php | 14 +++++------ tests/View/Helper/LmcUserLoginWidgetTest.php | 6 ++--- 4 files changed, 32 insertions(+), 24 deletions(-) diff --git a/tests/Authentication/Adapter/DbTest.php b/tests/Authentication/Adapter/DbTest.php index 89e4114..b872b80 100644 --- a/tests/Authentication/Adapter/DbTest.php +++ b/tests/Authentication/Adapter/DbTest.php @@ -527,14 +527,10 @@ protected function setAuthenticationCredentials($identity = 'LmcUser', $credenti ->willReturn(['is_satisfied' => false]); $post = $this->createMock('Laminas\Stdlib\Parameters'); - $post->expects($this->at(0)) + $post->expects($this->atLeastOnce()) ->method('get') - ->with('identity') - ->willReturn($identity); - $post->expects($this->at(1)) - ->method('get') - ->with('credential') - ->willReturn($credential); + ->withConsecutive(['identity'], ['credential']) + ->willReturnOnConsecutiveCalls($identity, $credential); $request = $this->createMock('Laminas\Http\Request'); $request->expects($this->exactly(2)) diff --git a/tests/Controller/RedirectCallbackTest.php b/tests/Controller/RedirectCallbackTest.php index 4cea3b9..7aa8f76 100644 --- a/tests/Controller/RedirectCallbackTest.php +++ b/tests/Controller/RedirectCallbackTest.php @@ -345,15 +345,27 @@ public function testGetRedirectWithOptionOnRedirectDoesntExist(): void ->method('match') ->willReturn(null); - $this->router->expects($this->at(1)) +// $this->router->expects($this->at(1)) +// ->method('assemble') +// ->with([], ['name' => $redirect]) +// ->willThrowException(new \Laminas\Router\Exception\RuntimeException); +// +// $this->router->expects($this->at(2)) +// ->method('assemble') +// ->with([], ['name' => $route]) +// ->willReturn($expectedResult); + + $matcher = $this->exactly(2); + $this->router->expects($matcher) ->method('assemble') - ->with([], ['name' => $redirect]) - ->willThrowException(new \Laminas\Router\Exception\RuntimeException); + ->withConsecutive([[], ['name' => $redirect]], [[], ['name' => $route]]) + ->willReturnCallback(function () use ($matcher, $expectedResult) { + if ($matcher->getInvocationCount() === 2) { + return $expectedResult; + } - $this->router->expects($this->at(2)) - ->method('assemble') - ->with([], ['name' => $route]) - ->willReturn($expectedResult); + throw new \Laminas\Router\Exception\RuntimeException; + }); $this->moduleOptions->expects($this->once()) ->method('getLoginRedirectRoute') diff --git a/tests/Controller/UserControllerTest.php b/tests/Controller/UserControllerTest.php index 2df4716..5119191 100644 --- a/tests/Controller/UserControllerTest.php +++ b/tests/Controller/UserControllerTest.php @@ -575,10 +575,10 @@ public function testRegisterAction($wantRedirect, $postRedirectGetReturn, $regis $url = $this->createMock('Laminas\Mvc\Controller\Plugin\Url'); - $url->expects($this->at(0)) + $url->expects($this->atLeastOnce()) ->method('fromRoute') - ->with($controller::ROUTE_REGISTER) - ->willReturn($route_url); + ->withConsecutive([$controller::ROUTE_REGISTER], [$controller::ROUTE_LOGIN]) + ->willReturn('/user/register', '/user/login'); $this->pluginManagerPlugins['url']= $url; @@ -644,10 +644,10 @@ public function testRegisterAction($wantRedirect, $postRedirectGetReturn, $regis $this->pluginManagerPlugins['redirect']= $redirect; - $url->expects($this->at(1)) - ->method('fromRoute') - ->with($controller::ROUTE_LOGIN) - ->willReturn($route_url); +// $url->expects($this->atLeastOnce()) +// ->method('fromRoute') +// ->with($controller::ROUTE_LOGIN) +// ->willReturn($route_url); } } diff --git a/tests/View/Helper/LmcUserLoginWidgetTest.php b/tests/View/Helper/LmcUserLoginWidgetTest.php index 7f1d1be..f653b47 100644 --- a/tests/View/Helper/LmcUserLoginWidgetTest.php +++ b/tests/View/Helper/LmcUserLoginWidgetTest.php @@ -58,7 +58,7 @@ public function providerTestInvokeWithRender() } /** - * @covers LmcUser\View\Helper\LmcUserLoginWidget::__invoke + * @covers \LmcUser\View\Helper\LmcUserLoginWidget::__invoke * @dataProvider providerTestInvokeWithRender */ public function testInvokeWithRender($option, $expect) @@ -68,7 +68,7 @@ public function testInvokeWithRender($option, $expect) */ $viewModel = null; - $this->view->expects($this->at(0)) + $this->view->expects($this->once()) ->method('render') ->willReturnCallback( function ($vm) use (&$viewModel) { @@ -90,7 +90,7 @@ function ($vm) use (&$viewModel) { } /** - * @covers LmcUser\View\Helper\LmcUserLoginWidget::__invoke + * @covers \LmcUser\View\Helper\LmcUserLoginWidget::__invoke */ public function testInvokeWithoutRender() {