diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index 9767dda..25d37ed 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -15,7 +15,6 @@ jobs: - ubuntu-latest php: - - "8.2" - "8.3" - "8.4" - "8.5" diff --git a/.github/workflows/qodana_code_quality.yml b/.github/workflows/qodana_code_quality.yml index 946797d..661f9d0 100644 --- a/.github/workflows/qodana_code_quality.yml +++ b/.github/workflows/qodana_code_quality.yml @@ -16,7 +16,7 @@ jobs: checks: write strategy: matrix: - php-versions: [ '8.2', '8.3', '8.4', '8.5' ] + php-versions: ['8.3', '8.4', '8.5' ] steps: - uses: actions/checkout@v6 with: diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index d9d0a0a..f818db0 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -15,7 +15,6 @@ jobs: - ubuntu-latest php: - - "8.2" - "8.3" - "8.4" - "8.5" diff --git a/CHANGELOG.md b/CHANGELOG.md index 4be81a0..399c3c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,28 @@ # Changelog +## 7.2.0 - 2026-04-21 + +### Changed + +* Issue [#419](https://github.com/dotkernel/admin/issues/419): Bump `PHPUnit` to version `12.5.23` by [@SergiuBota1](https://github.com/SergiuBota1) in [#420](https://github.com/dotkernel/admin/pull/420) + +### Added + +* Nothing + +### Deprecated + +* Nothing + +### Removed + +* Removed PHP `8.2` support + +### Fixed + +* Fixed PHPUnit notices caused by mock objects without expectations configured +* Fixed PHPUnit deprecation warnings caused by using `with()` on test stubs + ## 7.1.0 - 2026-03-27 ### Changed diff --git a/README.md b/README.md index 98732e4..7ce0645 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Documentation is available at: https://docs.dotkernel.org/admin-documentation/ | Branch | Release | PSR-11 | OSS Lifecycle | PHP Version | |--------|----------|--------|----------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------| -| 7.0 | `>= 7.0` | 1 | ![OSS Lifecycle](https://img.shields.io/osslifecycle?file_url=https%3A%2F%2Fgithub.com%2Fdotkernel%2Fadmin%2Fblob%2F7.0%2FOSSMETADATA) | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/admin/7.1.0) | +| 7.0 | `>= 7.0` | 1 | ![OSS Lifecycle](https://img.shields.io/osslifecycle?file_url=https%3A%2F%2Fgithub.com%2Fdotkernel%2Fadmin%2Fblob%2F7.0%2FOSSMETADATA) | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/admin/7.2.0) | | 6.0 | `< 7.0` | 1 | ![OSS Lifecycle](https://img.shields.io/osslifecycle?file_url=https%3A%2F%2Fgithub.com%2Fdotkernel%2Fadmin%2Fblob%2F6.0%2FOSSMETADATA) | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/admin/6.2.0) | | 5.0 | `< 6.0` | 1 | ![OSS Lifecycle](https://img.shields.io/osslifecycle?file_url=https%3A%2F%2Fgithub.com%2Fdotkernel%2Fadmin%2Fblob%2F5.0%2FOSSMETADATA) | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/admin/5.0.3) | | 4.0 | `< 5.0` | 1 | ![OSS Lifecycle](https://img.shields.io/osslifecycle?file_url=https%3A%2F%2Fgithub.com%2Fdotkernel%2Fadmin%2Fblob%2F4.0%2FOSSMETADATA) | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/admin/4.3.1) | diff --git a/SECURITY.md b/SECURITY.md index fdced46..51b56e0 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -4,7 +4,7 @@ | Branch | OSS Lifecycle | PHP Version | |--------|----------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------| -| 7.0 | ![OSS Lifecycle](https://img.shields.io/osslifecycle?file_url=https%3A%2F%2Fgithub.com%2Fdotkernel%2Fadmin%2Fblob%2F7.0%2FOSSMETADATA) | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/admin/7.1.0) | +| 7.0 | ![OSS Lifecycle](https://img.shields.io/osslifecycle?file_url=https%3A%2F%2Fgithub.com%2Fdotkernel%2Fadmin%2Fblob%2F7.0%2FOSSMETADATA) | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/admin/7.2.0) | | 6.0 | ![OSS Lifecycle](https://img.shields.io/osslifecycle?file_url=https%3A%2F%2Fgithub.com%2Fdotkernel%2Fadmin%2Fblob%2F6.0%2FOSSMETADATA) | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/admin/6.2.0) | | 5.0 | ![OSS Lifecycle](https://img.shields.io/osslifecycle?file_url=https%3A%2F%2Fgithub.com%2Fdotkernel%2Fadmin%2Fblob%2F5.0%2FOSSMETADATA) | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/admin/5.0.3) | | 4.0 | ![OSS Lifecycle](https://img.shields.io/osslifecycle?file_url=https%3A%2F%2Fgithub.com%2Fdotkernel%2Fadmin%2Fblob%2F4.0%2FOSSMETADATA) | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/admin/4.3.1) | diff --git a/composer.json b/composer.json index 6efc9e1..db256b1 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ "process-timeout": 0 }, "require": { - "php": "~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0", + "php": "~8.3.0 || ~8.4.0 || ~8.5.0", "dotkernel/dot-cache": "^4.4.0", "dotkernel/dot-cli": "^3.10.0", "dotkernel/dot-data-fixtures": "^1.5.0", @@ -64,7 +64,7 @@ "phpstan/phpstan": "^2.1.32", "phpstan/phpstan-doctrine": "^2.0.11", "phpstan/phpstan-phpunit": "^2.0.8", - "phpunit/phpunit": "^10.5.58", + "phpunit/phpunit": "^12.5.23", "roave/security-advisories": "dev-latest", "symfony/var-dumper": "^7.4.0", "vincentlanglet/twig-cs-fixer": "^3.11.0" diff --git a/phpunit.xml b/phpunit.xml index 52f8da3..dc3c141 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -3,6 +3,9 @@ xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true" + displayDetailsOnPhpunitNotices="true" + displayDetailsOnTestsThatTriggerDeprecations="true" + displayDetailsOnPhpunitDeprecations="true" stopOnError="true"> diff --git a/test/Unit/Admin/Adapter/AuthenticationAdapterTest.php b/test/Unit/Admin/Adapter/AuthenticationAdapterTest.php index 840fa91..e4557cb 100644 --- a/test/Unit/Admin/Adapter/AuthenticationAdapterTest.php +++ b/test/Unit/Admin/Adapter/AuthenticationAdapterTest.php @@ -30,7 +30,7 @@ class AuthenticationAdapterTest extends UnitTest public function testAccessors(): void { $adapter = new AuthenticationAdapter( - $this->createMock(EntityManager::class), + $this->createStub(EntityManager::class), [] ); @@ -54,14 +54,14 @@ public function testAccessors(): void public function testWillNotAuthenticateWithoutValidConfig(): void { $adapter = new AuthenticationAdapter( - $this->createMock(EntityManager::class), + $this->createStub(EntityManager::class), [] ); $this->expectExceptionMessage('No or invalid param "identity_class" provided.'); $adapter->authenticate(); $adapter = new AuthenticationAdapter( - $this->createMock(EntityManager::class), + $this->createStub(EntityManager::class), [ 'orm_default' => [ 'identity_class' => Admin::class, @@ -72,7 +72,7 @@ public function testWillNotAuthenticateWithoutValidConfig(): void $adapter->authenticate(); $adapter = new AuthenticationAdapter( - $this->createMock(EntityManager::class), + $this->createStub(EntityManager::class), [ 'orm_default' => [ 'identity_class' => Admin::class, @@ -84,7 +84,7 @@ public function testWillNotAuthenticateWithoutValidConfig(): void $adapter->authenticate(); $adapter = new AuthenticationAdapter( - $this->createMock(EntityManager::class), + $this->createStub(EntityManager::class), [ 'orm_default' => [ 'identity_class' => Admin::class, @@ -104,7 +104,7 @@ public function testWillNotAuthenticateWithoutValidConfig(): void public function testWillNotAuthenticateWithInvalidIdentityClassConfig(): void { $adapter = new AuthenticationAdapter( - $this->createMock(EntityManager::class), + $this->createStub(EntityManager::class), [ 'orm_default' => [ 'identity_class' => Exception::class, @@ -133,7 +133,7 @@ public function testWillNotAuthenticateWithInvalidIdentityClassConfig(): void public function testWillNotAuthenticateWithInvalidIdentityPropertyConfig(): void { $adapter = new AuthenticationAdapter( - $this->createMock(EntityManager::class), + $this->createStub(EntityManager::class), [ 'orm_default' => [ 'identity_class' => Admin::class, diff --git a/test/Unit/Admin/Delegator/AdminRoleDelegatorTest.php b/test/Unit/Admin/Delegator/AdminRoleDelegatorTest.php index f32abe6..7f30978 100644 --- a/test/Unit/Admin/Delegator/AdminRoleDelegatorTest.php +++ b/test/Unit/Admin/Delegator/AdminRoleDelegatorTest.php @@ -23,7 +23,7 @@ class AdminRoleDelegatorTest extends UnitTest */ public function testInvokeWillSucceedWithoutAdminForm(): void { - $container = $this->createMock(ContainerInterface::class); + $container = $this->createStub(ContainerInterface::class); $delegator = (new AdminRoleDelegator())( $container, @@ -47,7 +47,7 @@ public function testInvokeWillSucceedWithAdminForm(): void ->method('get') ->with(EntityManagerInterface::class) ->willReturn( - $this->createMock(EntityManagerInterface::class) + $this->createStub(EntityManagerInterface::class) ); $delegator = (new AdminRoleDelegator())( diff --git a/test/Unit/Admin/Factory/AuthenticationServiceFactoryTest.php b/test/Unit/Admin/Factory/AuthenticationServiceFactoryTest.php index 10c3cdb..75f770b 100644 --- a/test/Unit/Admin/Factory/AuthenticationServiceFactoryTest.php +++ b/test/Unit/Admin/Factory/AuthenticationServiceFactoryTest.php @@ -22,7 +22,7 @@ class AuthenticationServiceFactoryTest extends UnitTest */ public function testWillInvoke(): void { - $authenticationAdapter = $this->createMock(AuthenticationAdapter::class); + $authenticationAdapter = $this->createStub(AuthenticationAdapter::class); $container = $this->createMock(ContainerInterface::class); $container->expects($this->once()) diff --git a/test/Unit/Admin/Handler/Account/GetAccountEditFormHandlerTest.php b/test/Unit/Admin/Handler/Account/GetAccountEditFormHandlerTest.php index 232c617..db97800 100644 --- a/test/Unit/Admin/Handler/Account/GetAccountEditFormHandlerTest.php +++ b/test/Unit/Admin/Handler/Account/GetAccountEditFormHandlerTest.php @@ -27,17 +27,17 @@ class GetAccountEditFormHandlerTest extends UnitTest */ public function testWillReturnHtmlTemplate(): void { - $adminService = $this->createMock(AdminServiceInterface::class); - $router = $this->createMock(RouterInterface::class); - $template = $this->createMock(TemplateRendererInterface::class); - $authenticationService = $this->createMock(AuthenticationServiceInterface::class); - $accountForm = $this->createMock(AccountForm::class); - $changePasswordForm = $this->createMock(ChangePasswordForm::class); - $messenger = $this->createMock(FlashMessengerInterface::class); - $request = $this->createMock(ServerRequestInterface::class); - $identity = $this->createMock(AdminIdentity::class); - $adminRepository = $this->createMock(AdminRepository::class); - $admin = $this->createMock(Admin::class); + $adminService = $this->createStub(AdminServiceInterface::class); + $router = $this->createStub(RouterInterface::class); + $template = $this->createStub(TemplateRendererInterface::class); + $authenticationService = $this->createStub(AuthenticationServiceInterface::class); + $accountForm = $this->createStub(AccountForm::class); + $changePasswordForm = $this->createStub(ChangePasswordForm::class); + $messenger = $this->createStub(FlashMessengerInterface::class); + $request = $this->createStub(ServerRequestInterface::class); + $identity = $this->createStub(AdminIdentity::class); + $adminRepository = $this->createStub(AdminRepository::class); + $admin = $this->createStub(Admin::class); $identity->method('getId')->willReturn('test'); $authenticationService->method('getIdentity')->willReturn($identity); diff --git a/test/Unit/Admin/Handler/Account/GetAccountLoginFormHandlerTest.php b/test/Unit/Admin/Handler/Account/GetAccountLoginFormHandlerTest.php index 32dfc56..e94226a 100644 --- a/test/Unit/Admin/Handler/Account/GetAccountLoginFormHandlerTest.php +++ b/test/Unit/Admin/Handler/Account/GetAccountLoginFormHandlerTest.php @@ -23,13 +23,13 @@ class GetAccountLoginFormHandlerTest extends UnitTest */ public function testAdminLoggedWillReturnRedirectResponse(): void { - $router = $this->createMock(RouterInterface::class); - $template = $this->createMock(TemplateRendererInterface::class); - $authenticationService = $this->createMock(AuthenticationServiceInterface::class); - $messenger = $this->createMock(FlashMessengerInterface::class); - $formsPlugin = $this->createMock(FormsPlugin::class); - $loginForm = $this->createMock(LoginForm::class); - $request = $this->createMock(ServerRequestInterface::class); + $router = $this->createStub(RouterInterface::class); + $template = $this->createStub(TemplateRendererInterface::class); + $authenticationService = $this->createStub(AuthenticationServiceInterface::class); + $messenger = $this->createStub(FlashMessengerInterface::class); + $formsPlugin = $this->createStub(FormsPlugin::class); + $loginForm = $this->createStub(LoginForm::class); + $request = $this->createStub(ServerRequestInterface::class); $authenticationService->method('hasIdentity')->willReturn(true); @@ -52,13 +52,13 @@ public function testAdminLoggedWillReturnRedirectResponse(): void */ public function testWillReturnHtmlResponse(): void { - $router = $this->createMock(RouterInterface::class); - $template = $this->createMock(TemplateRendererInterface::class); - $authenticationService = $this->createMock(AuthenticationServiceInterface::class); - $messenger = $this->createMock(FlashMessengerInterface::class); - $formsPlugin = $this->createMock(FormsPlugin::class); - $loginForm = $this->createMock(LoginForm::class); - $request = $this->createMock(ServerRequestInterface::class); + $router = $this->createStub(RouterInterface::class); + $template = $this->createStub(TemplateRendererInterface::class); + $authenticationService = $this->createStub(AuthenticationServiceInterface::class); + $messenger = $this->createStub(FlashMessengerInterface::class); + $formsPlugin = $this->createStub(FormsPlugin::class); + $loginForm = $this->createStub(LoginForm::class); + $request = $this->createStub(ServerRequestInterface::class); $authenticationService->method('hasIdentity')->willReturn(false); diff --git a/test/Unit/Admin/Handler/Account/GetAccountLogoutHandlerTest.php b/test/Unit/Admin/Handler/Account/GetAccountLogoutHandlerTest.php index 237a875..d773057 100644 --- a/test/Unit/Admin/Handler/Account/GetAccountLogoutHandlerTest.php +++ b/test/Unit/Admin/Handler/Account/GetAccountLogoutHandlerTest.php @@ -19,9 +19,9 @@ class GetAccountLogoutHandlerTest extends UnitTest */ public function testLogoutWillReturnRedirectResponse(): void { - $router = $this->createMock(RouterInterface::class); - $authenticationService = $this->createMock(AuthenticationServiceInterface::class); - $request = $this->createMock(ServerRequestInterface::class); + $router = $this->createStub(RouterInterface::class); + $authenticationService = $this->createStub(AuthenticationServiceInterface::class); + $request = $this->createStub(ServerRequestInterface::class); $handler = new GetLogoutAccountHandler( $router, diff --git a/test/Unit/Admin/Handler/Account/PostAccountChangePasswordHandlerTest.php b/test/Unit/Admin/Handler/Account/PostAccountChangePasswordHandlerTest.php index 099bfc6..95efa32 100644 --- a/test/Unit/Admin/Handler/Account/PostAccountChangePasswordHandlerTest.php +++ b/test/Unit/Admin/Handler/Account/PostAccountChangePasswordHandlerTest.php @@ -21,20 +21,21 @@ use Mezzio\Template\TemplateRendererInterface; use PHPUnit\Framework\MockObject\Exception as MockObjectException; use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\MockObject\Stub; use Psr\Http\Message\ServerRequestInterface; class PostAccountChangePasswordHandlerTest extends UnitTest { - private MockObject&AdminServiceInterface $adminService; - private MockObject&RouterInterface $router; - private MockObject&TemplateRendererInterface $template; - private MockObject&AuthenticationServiceInterface $authenticationService; + private Stub&AdminServiceInterface $adminService; + private Stub&RouterInterface $router; + private Stub&TemplateRendererInterface $template; + private Stub&AuthenticationServiceInterface $authenticationService; private MockObject&FlashMessengerInterface $messenger; - private MockObject&AccountForm $accountForm; - private MockObject&ChangePasswordForm $changePasswordForm; - private MockObject&ServerRequestInterface $request; - private MockObject&AdminIdentity $identity; - private MockObject&Admin $admin; + private Stub&AccountForm $accountForm; + private Stub&ChangePasswordForm $changePasswordForm; + private Stub&ServerRequestInterface $request; + private Stub&AdminIdentity $identity; + private Stub&Admin $admin; private Logger $logger; /** @@ -44,16 +45,16 @@ public function setUp(): void { parent::setUp(); - $this->adminService = $this->createMock(AdminServiceInterface::class); - $this->router = $this->createMock(RouterInterface::class); - $this->template = $this->createMock(TemplateRendererInterface::class); - $this->authenticationService = $this->createMock(AuthenticationServiceInterface::class); + $this->adminService = $this->createStub(AdminServiceInterface::class); + $this->router = $this->createStub(RouterInterface::class); + $this->template = $this->createStub(TemplateRendererInterface::class); + $this->authenticationService = $this->createStub(AuthenticationServiceInterface::class); $this->messenger = $this->createMock(FlashMessengerInterface::class); - $this->accountForm = $this->createMock(AccountForm::class); - $this->changePasswordForm = $this->createMock(ChangePasswordForm::class); - $this->request = $this->createMock(ServerRequestInterface::class); - $this->identity = $this->createMock(AdminIdentity::class); - $this->admin = $this->createMock(Admin::class); + $this->accountForm = $this->createStub(AccountForm::class); + $this->changePasswordForm = $this->createStub(ChangePasswordForm::class); + $this->request = $this->createStub(ServerRequestInterface::class); + $this->identity = $this->createStub(AdminIdentity::class); + $this->admin = $this->createStub(Admin::class); $this->logger = new Logger([ 'writers' => [ 'FileWriter' => [ @@ -75,6 +76,7 @@ public function testInvalidChangePasswordFormDataProvidedWillReturnHtmlResponse( $this->changePasswordForm->method('isValid')->willReturn(false); $this->accountForm->method('prepare')->willReturn('
'); $this->changePasswordForm->method('prepare')->willReturn('
'); + $this->messenger->expects($this->never())->method('addError'); $handler = new PostChangeAccountPasswordHandler( $this->adminService, diff --git a/test/Unit/Admin/Handler/Account/PostAccountEditHandlerTest.php b/test/Unit/Admin/Handler/Account/PostAccountEditHandlerTest.php index 7f3843a..9da3fec 100644 --- a/test/Unit/Admin/Handler/Account/PostAccountEditHandlerTest.php +++ b/test/Unit/Admin/Handler/Account/PostAccountEditHandlerTest.php @@ -22,22 +22,23 @@ use Mezzio\Template\TemplateRendererInterface; use PHPUnit\Framework\MockObject\Exception as MockObjectException; use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\MockObject\Stub; use Psr\Http\Message\ServerRequestInterface; class PostAccountEditHandlerTest extends UnitTest { - private MockObject&AdminServiceInterface $adminService; - private MockObject&RouterInterface $router; - private MockObject&TemplateRendererInterface $template; - private MockObject&AuthenticationServiceInterface $authenticationService; - private MockObject&AccountForm $accountForm; - private MockObject&ChangePasswordForm $changePasswordForm; + private Stub&AdminServiceInterface $adminService; + private Stub&RouterInterface $router; + private Stub&TemplateRendererInterface $template; + private Stub&AuthenticationServiceInterface $authenticationService; + private Stub&AccountForm $accountForm; + private Stub&ChangePasswordForm $changePasswordForm; private MockObject&FlashMessengerInterface $messenger; private Logger $logger; - private MockObject&AdminIdentity $identity; - private MockObject&ServerRequestInterface $request; + private Stub&AdminIdentity $identity; + private Stub&ServerRequestInterface $request; - private MockObject&Admin $admin; + private Stub&Admin $admin; /** * @throws MockObjectException @@ -46,16 +47,16 @@ public function setUp(): void { parent::setUp(); - $this->adminService = $this->createMock(AdminServiceInterface::class); - $this->router = $this->createMock(RouterInterface::class); - $this->template = $this->createMock(TemplateRendererInterface::class); - $this->authenticationService = $this->createMock(AuthenticationServiceInterface::class); - $this->accountForm = $this->createMock(AccountForm::class); - $this->changePasswordForm = $this->createMock(ChangePasswordForm::class); + $this->adminService = $this->createStub(AdminServiceInterface::class); + $this->router = $this->createStub(RouterInterface::class); + $this->template = $this->createStub(TemplateRendererInterface::class); + $this->authenticationService = $this->createStub(AuthenticationServiceInterface::class); + $this->accountForm = $this->createStub(AccountForm::class); + $this->changePasswordForm = $this->createStub(ChangePasswordForm::class); $this->messenger = $this->createMock(FlashMessengerInterface::class); - $this->identity = $this->createMock(AdminIdentity::class); - $this->request = $this->createMock(ServerRequestInterface::class); - $this->admin = $this->createMock(Admin::class); + $this->identity = $this->createStub(AdminIdentity::class); + $this->request = $this->createStub(ServerRequestInterface::class); + $this->admin = $this->createStub(Admin::class); $this->logger = new Logger([ 'writers' => [ 'FileWriter' => [ @@ -71,6 +72,7 @@ public function testInvalidAccountFormDataProvidedWillReturnHtmlResponse(): void $this->request->method('getParsedBody')->willReturn(['test']); $this->authenticationService->method('getIdentity')->willReturn($this->identity); $this->accountForm->method('isValid')->willReturn(false); + $this->messenger->expects($this->never())->method('addError'); $handler = new PostEditAccountHandler( $this->adminService, diff --git a/test/Unit/Admin/Handler/Account/PostAccountLoginHandlerTest.php b/test/Unit/Admin/Handler/Account/PostAccountLoginHandlerTest.php index ce10b7e..7b2533b 100644 --- a/test/Unit/Admin/Handler/Account/PostAccountLoginHandlerTest.php +++ b/test/Unit/Admin/Handler/Account/PostAccountLoginHandlerTest.php @@ -25,23 +25,24 @@ use Mezzio\Router\RouterInterface; use PHPUnit\Framework\MockObject\Exception as MockObjectException; use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\MockObject\Stub; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\UriInterface; class PostAccountLoginHandlerTest extends UnitTest { - private MockObject&AdminServiceInterface $adminService; + private Stub&AdminServiceInterface $adminService; private MockObject&AdminLoginServiceInterface $adminLoginService; - private MockObject&RouterInterface $router; + private Stub&RouterInterface $router; private MockObject&LaminasAuthenticationServiceInterface&AuthenticationServiceInterface $authenticationService; private MockObject&FlashMessengerInterface $messenger; - private MockObject&FormsPlugin $formsPlugin; - private MockObject&LoginForm $loginForm; + private Stub&FormsPlugin $formsPlugin; + private Stub&LoginForm $loginForm; private Logger $logger; - private MockObject&ServerRequestInterface $request; - private MockObject&Result $authenticationResult; - private MockObject&AuthenticationAdapter $authenticationAdapter; - private MockObject&AdminIdentity $identity; + private Stub&ServerRequestInterface $request; + private Stub&Result $authenticationResult; + private Stub&AuthenticationAdapter $authenticationAdapter; + private Stub&AdminIdentity $identity; private MockObject&StorageInterface $storage; /** @@ -58,16 +59,16 @@ public function setUp(): void ]); $this->authenticationService = $authenticationService; - $this->adminService = $this->createMock(AdminServiceInterface::class); + $this->adminService = $this->createStub(AdminServiceInterface::class); $this->adminLoginService = $this->createMock(AdminLoginServiceInterface::class); - $this->router = $this->createMock(RouterInterface::class); + $this->router = $this->createStub(RouterInterface::class); $this->messenger = $this->createMock(FlashMessengerInterface::class); - $this->formsPlugin = $this->createMock(FormsPlugin::class); - $this->loginForm = $this->createMock(LoginForm::class); - $this->request = $this->createMock(ServerRequestInterface::class); - $this->authenticationResult = $this->createMock(Result::class); - $this->authenticationAdapter = $this->createMock(AuthenticationAdapter::class); - $this->identity = $this->createMock(AdminIdentity::class); + $this->formsPlugin = $this->createStub(FormsPlugin::class); + $this->loginForm = $this->createStub(LoginForm::class); + $this->request = $this->createStub(ServerRequestInterface::class); + $this->authenticationResult = $this->createStub(Result::class); + $this->authenticationAdapter = $this->createStub(AuthenticationAdapter::class); + $this->identity = $this->createStub(AdminIdentity::class); $this->storage = $this->createMock(StorageInterface::class); $this->logger = new Logger([ 'writers' => [ @@ -81,7 +82,12 @@ public function setUp(): void public function testAdminAlreadyLoggedWillReturnRedirectResponse(): void { - $this->authenticationService->method('hasIdentity')->willReturn(true); + $this->authenticationService->expects($this->once())->method('hasIdentity')->willReturn(true); + + $this->messenger->expects($this->never())->method('addError'); + $this->adminLoginService->expects($this->never())->method('logFailedLogin'); + $this->adminLoginService->expects($this->never())->method('logSuccessfulLogin'); + $this->storage->expects($this->never())->method('write'); $handler = new PostLoginAccountHandler( $this->adminService, @@ -104,21 +110,17 @@ public function testAdminAlreadyLoggedWillReturnRedirectResponse(): void */ public function testInvalidLoginFormDataProvidedWillReturnRedirectResponse(): void { - $this->authenticationService->method('hasIdentity')->willReturn(false); - $this->request->method('getUri')->willReturn($this->createMock(UriInterface::class)); + $this->authenticationService->expects($this->once())->method('hasIdentity')->willReturn(false); + $this->request->method('getUri')->willReturn($this->createStub(UriInterface::class)); $this->request->method('getParsedBody')->willReturn(['test']); $this->loginForm->method('isValid')->willReturn(false); - $this->request->method('getParsedBody')->willReturn(['test']); $this->request->method('getQueryParams')->willReturn([]); $this->request->method('getServerParams')->willReturn([]); - $this->request->method('getUri')->willReturn( - $this->createMock(UriInterface::class) - ); - $this - ->messenger - ->expects($this->atLeastOnce()) - ->method('addError'); + $this->messenger->expects($this->atLeastOnce())->method('addError'); + $this->adminLoginService->expects($this->never())->method('logFailedLogin'); + $this->adminLoginService->expects($this->never())->method('logSuccessfulLogin'); + $this->storage->expects($this->never())->method('write'); $handler = new PostLoginAccountHandler( $this->adminService, @@ -143,19 +145,22 @@ public function testInvalidPasswordProvidedWillReturnRedirectResponse(): void { $this->authenticationResult->method('isValid')->willReturn(false); $this->authenticationResult->method('getMessages')->willReturn([]); - $this->authenticationService->method('authenticate')->willReturn($this->authenticationResult); - $this->authenticationService->method('hasIdentity')->willReturn(false); + $this->authenticationService->expects($this->once())->method('hasIdentity')->willReturn(false); + $this->authenticationService->expects($this->once())->method('authenticate') + ->willReturn($this->authenticationResult); + $this->authenticationService->expects($this->once())->method('getAdapter') + ->willReturn($this->authenticationAdapter); $this->request->method('getParsedBody')->willReturn(['test']); $this->request->method('getServerParams')->willReturn([]); - $this->request->method('getUri')->willReturn($this->createMock(UriInterface::class)); + $this->request->method('getUri')->willReturn($this->createStub(UriInterface::class)); $this->loginForm->method('isValid')->willReturn(true); $this->loginForm->method('getData')->willReturn(['identity' => 'test', 'password' => 'test']); $this->authenticationAdapter->method('setIdentity')->willReturn($this->authenticationAdapter); $this->authenticationAdapter->method('setCredential')->willReturn($this->authenticationAdapter); - $this->authenticationService->method('getAdapter')->willReturn($this->authenticationAdapter); $this->messenger->expects($this->atLeastOnce())->method('addError'); $this->adminLoginService->expects($this->atLeastOnce())->method('logFailedLogin'); + $this->storage->expects($this->never())->method('write'); $handler = new PostLoginAccountHandler( $this->adminService, @@ -182,27 +187,25 @@ public function testAdminInactiveWillReturnRedirectResponse(): void $this->authenticationResult->method('isValid')->willReturn(true); $this->authenticationResult->method('getMessages')->willReturn([]); $this->authenticationResult->method('getIdentity')->willReturn($this->identity); - $this->authenticationService->method('authenticate')->willReturn($this->authenticationResult); - $this->authenticationService->method('hasIdentity')->willReturn(false); + $this->authenticationService->expects($this->once())->method('hasIdentity')->willReturn(false); + $this->authenticationService->expects($this->once())->method('authenticate') + ->willReturn($this->authenticationResult); + $this->authenticationService->expects($this->once())->method('getAdapter') + ->willReturn($this->authenticationAdapter); + $this->authenticationService->expects($this->atLeastOnce())->method('clearIdentity'); $this->request->method('getParsedBody')->willReturn(['test']); $this->request->method('getServerParams')->willReturn([]); - $this->request->method('getUri')->willReturn($this->createMock(UriInterface::class)); + $this->request->method('getUri')->willReturn($this->createStub(UriInterface::class)); $this->loginForm->method('isValid')->willReturn(true); $this->loginForm->method('getData')->willReturn(['identity' => 'test', 'password' => 'test']); $this->authenticationAdapter->method('setIdentity')->willReturn($this->authenticationAdapter); $this->authenticationAdapter->method('setCredential')->willReturn($this->authenticationAdapter); - $this->authenticationService->method('getAdapter')->willReturn($this->authenticationAdapter); - $this - ->messenger - ->expects($this->atLeastOnce()) - ->method('addError') + $this->messenger->expects($this->atLeastOnce())->method('addError') ->with(Message::ADMIN_INACTIVE); - - $this - ->authenticationService - ->expects($this->atLeastOnce()) - ->method('clearIdentity'); + $this->adminLoginService->expects($this->never())->method('logFailedLogin'); + $this->adminLoginService->expects($this->never())->method('logSuccessfulLogin'); + $this->storage->expects($this->never())->method('write'); $handler = new PostLoginAccountHandler( $this->adminService, @@ -225,14 +228,15 @@ public function testAdminInactiveWillReturnRedirectResponse(): void */ public function testAdminLoginThrowsExceptionWillReturnRedirectResponse(): void { - $this->request->method('getUri')->willReturn($this->createMock(UriInterface::class)); + $this->authenticationService->expects($this->once())->method('hasIdentity')->willReturn(false); + $this->request->method('getUri')->willReturn($this->createStub(UriInterface::class)); $this->throwException(new Exception()); - $this - ->messenger - ->expects($this->atLeastOnce()) - ->method('addError') + $this->messenger->expects($this->atLeastOnce())->method('addError') ->with(Message::AN_ERROR_OCCURRED); + $this->adminLoginService->expects($this->never())->method('logSuccessfulLogin'); + $this->adminLoginService->expects($this->never())->method('logFailedLogin'); + $this->storage->expects($this->never())->method('write'); $handler = new PostLoginAccountHandler( $this->adminService, @@ -259,22 +263,23 @@ public function testAdminLoginSuccessfulWillReturnRedirectResponse(): void $this->authenticationResult->method('isValid')->willReturn(true); $this->authenticationResult->method('getMessages')->willReturn([]); $this->authenticationResult->method('getIdentity')->willReturn($this->identity); - $this->authenticationService->method('authenticate')->willReturn($this->authenticationResult); - $this->authenticationService->method('hasIdentity')->willReturn(false); - $this->authenticationService->method('getStorage')->willReturn($this->storage); + $this->authenticationService->expects($this->once())->method('hasIdentity')->willReturn(false); + $this->authenticationService->expects($this->once())->method('authenticate') + ->willReturn($this->authenticationResult); + $this->authenticationService->expects($this->once())->method('getStorage')->willReturn($this->storage); + $this->authenticationService->expects($this->once())->method('getAdapter') + ->willReturn($this->authenticationAdapter); $this->request->method('getParsedBody')->willReturn(['test']); $this->request->method('getServerParams')->willReturn([]); - $this->request->method('getUri')->willReturn( - $this->createMock(UriInterface::class), - ); + $this->request->method('getUri')->willReturn($this->createStub(UriInterface::class)); $this->loginForm->method('isValid')->willReturn(true); $this->loginForm->method('getData')->willReturn(['identity' => 'test', 'password' => 'test']); $this->authenticationAdapter->method('setIdentity')->willReturn($this->authenticationAdapter); $this->authenticationAdapter->method('setCredential')->willReturn($this->authenticationAdapter); - $this->authenticationService->method('getAdapter')->willReturn($this->authenticationAdapter); $this->adminLoginService->expects($this->atLeastOnce())->method('logSuccessfulLogin'); $this->storage->expects($this->atLeastOnce())->method('write')->with($this->identity); + $this->messenger->expects($this->never())->method('addError'); $handler = new PostLoginAccountHandler( $this->adminService, diff --git a/test/Unit/Admin/Handler/Admin/GetAdminCreateFormHandlerTest.php b/test/Unit/Admin/Handler/Admin/GetAdminCreateFormHandlerTest.php index a77a809..b6b4ac8 100644 --- a/test/Unit/Admin/Handler/Admin/GetAdminCreateFormHandlerTest.php +++ b/test/Unit/Admin/Handler/Admin/GetAdminCreateFormHandlerTest.php @@ -20,10 +20,10 @@ class GetAdminCreateFormHandlerTest extends UnitTest */ public function testWillReturnHtmlTemplate(): void { - $router = $this->createMock(RouterInterface::class); - $template = $this->createMock(TemplateRendererInterface::class); - $form = $this->createMock(CreateAdminForm::class); - $request = $this->createMock(ServerRequestInterface::class); + $router = $this->createStub(RouterInterface::class); + $template = $this->createStub(TemplateRendererInterface::class); + $form = $this->createStub(CreateAdminForm::class); + $request = $this->createStub(ServerRequestInterface::class); $handler = new GetCreateAdminFormHandler( $router, diff --git a/test/Unit/Admin/Handler/Admin/GetAdminDeleteFormHandlerTest.php b/test/Unit/Admin/Handler/Admin/GetAdminDeleteFormHandlerTest.php index 65fa0e1..88ad71b 100644 --- a/test/Unit/Admin/Handler/Admin/GetAdminDeleteFormHandlerTest.php +++ b/test/Unit/Admin/Handler/Admin/GetAdminDeleteFormHandlerTest.php @@ -17,16 +17,17 @@ use Mezzio\Template\TemplateRendererInterface; use PHPUnit\Framework\MockObject\Exception; use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\MockObject\Stub; use Psr\Http\Message\ServerRequestInterface; use Ramsey\Uuid\Uuid; class GetAdminDeleteFormHandlerTest extends UnitTest { - private MockObject&AdminServiceInterface $adminService; - private MockObject&RouterInterface $router; - private MockObject&TemplateRendererInterface $template; - private MockObject&DeleteAdminForm $form; - private MockObject&ServerRequestInterface $request; + private Stub&AdminServiceInterface $adminService; + private Stub&RouterInterface $router; + private Stub&TemplateRendererInterface $template; + private Stub&DeleteAdminForm $form; + private Stub&ServerRequestInterface $request; private MockObject&FlashMessengerInterface $messenger; /** @@ -36,20 +37,20 @@ public function setUp(): void { parent::setUp(); - $this->adminService = $this->createMock(AdminServiceInterface::class); - $this->router = $this->createMock(RouterInterface::class); - $this->template = $this->createMock(TemplateRendererInterface::class); - $this->form = $this->createMock(DeleteAdminForm::class); - $this->request = $this->createMock(ServerRequestInterface::class); + $this->adminService = $this->createStub(AdminServiceInterface::class); + $this->router = $this->createStub(RouterInterface::class); + $this->template = $this->createStub(TemplateRendererInterface::class); + $this->form = $this->createStub(DeleteAdminForm::class); + $this->request = $this->createStub(ServerRequestInterface::class); $this->messenger = $this->createMock(FlashMessengerInterface::class); } public function testInvalidAdminProvidedWillReturnNotFoundResponse(): void { - $this->request->method('getAttribute')->with('id')->willReturn('test'); + $this->request->method('getAttribute')->willReturn('test'); $this->adminService->method('findAdmin')->willThrowException(new NotFoundException(Message::ADMIN_NOT_FOUND)); - $this->messenger->expects($this->once())->method('addError')->with(Message::ADMIN_NOT_FOUND); + $this->messenger->expects($this->once())->method('addError'); $handler = new GetDeleteAdminFormHandler( $this->adminService, @@ -69,18 +70,19 @@ public function testInvalidAdminProvidedWillReturnNotFoundResponse(): void */ public function testValidAdminWillReturnHtmlTemplate(): void { - $id = $this->createMock(Uuid::class); - $admin = $this->createMock(Admin::class); + $id = $this->createStub(Uuid::class); + $admin = $this->createStub(Admin::class); $id->method('toString')->willReturn('0x123'); $admin->method('getId')->willReturn($id); - $this->request->method('getAttribute')->with('id')->willReturn($id->toString()); - $this->adminService->method('findAdmin')->with($id->toString())->willReturn($admin); + $this->request->method('getAttribute')->willReturn($id->toString()); + $this->adminService->method('findAdmin')->willReturn($admin); $this->form->method('setAttribute')->willReturn(null); $this->router->method('generateUri')->willReturn('/'); $this->template->method('render')->willReturn('

'); + $this->messenger->expects($this->never())->method('addError'); $handler = new GetDeleteAdminFormHandler( $this->adminService, diff --git a/test/Unit/Admin/Handler/Admin/GetAdminEditFormHandlerTest.php b/test/Unit/Admin/Handler/Admin/GetAdminEditFormHandlerTest.php index 3d937c7..2da81d5 100644 --- a/test/Unit/Admin/Handler/Admin/GetAdminEditFormHandlerTest.php +++ b/test/Unit/Admin/Handler/Admin/GetAdminEditFormHandlerTest.php @@ -20,18 +20,19 @@ use Mezzio\Template\TemplateRendererInterface; use PHPUnit\Framework\MockObject\Exception; use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\MockObject\Stub; use Psr\Http\Message\ServerRequestInterface; use Ramsey\Uuid\Uuid; class GetAdminEditFormHandlerTest extends UnitTest { - private MockObject&AdminServiceInterface $adminService; - private MockObject&AdminRoleServiceInterface $adminRoleService; - private MockObject&RouterInterface $router; - private MockObject&TemplateRendererInterface $template; + private Stub&AdminServiceInterface $adminService; + private Stub&AdminRoleServiceInterface $adminRoleService; + private Stub&RouterInterface $router; + private Stub&TemplateRendererInterface $template; private MockObject&FlashMessengerInterface $messenger; - private MockObject&EditAdminForm $form; - private MockObject&ServerRequestInterface $request; + private Stub&EditAdminForm $form; + private Stub&ServerRequestInterface $request; /** * @throws Exception @@ -40,19 +41,21 @@ public function setUp(): void { parent::setUp(); - $this->adminService = $this->createMock(AdminServiceInterface::class); - $this->adminRoleService = $this->createMock(AdminRoleServiceInterface::class); - $this->router = $this->createMock(RouterInterface::class); - $this->template = $this->createMock(TemplateRendererInterface::class); + $this->adminService = $this->createStub(AdminServiceInterface::class); + $this->adminRoleService = $this->createStub(AdminRoleServiceInterface::class); + $this->router = $this->createStub(RouterInterface::class); + $this->template = $this->createStub(TemplateRendererInterface::class); $this->messenger = $this->createMock(FlashMessengerInterface::class); - $this->form = $this->createMock(EditAdminForm::class); - $this->request = $this->createMock(ServerRequestInterface::class); + $this->form = $this->createStub(EditAdminForm::class); + $this->request = $this->createStub(ServerRequestInterface::class); } public function testInvalidAdminProvidedWillReturnNotFoundResponse(): void { - $this->request->method('getAttribute')->with('id')->willReturn('test'); - $this->adminService->method('findAdmin')->willThrowException(new NotFoundException(Message::ADMIN_NOT_FOUND)); + $this->request->method('getAttribute')->willReturn('test'); + $this->adminService->method('findAdmin') + ->willThrowException(new NotFoundException(Message::ADMIN_NOT_FOUND)); + $this->messenger->expects($this->once())->method('addError')->with(Message::ADMIN_NOT_FOUND); $this ->messenger @@ -80,8 +83,8 @@ public function testInvalidAdminProvidedWillReturnNotFoundResponse(): void */ public function testValidAdminWillReturnHtmlTemplate(): void { - $id = $this->createMock(Uuid::class); - $admin = $this->createMock(Admin::class); + $id = $this->createStub(Uuid::class); + $admin = $this->createStub(Admin::class); $id->method('toString')->willReturn('0x123'); $admin->method('getId')->willReturn($id); @@ -89,10 +92,11 @@ public function testValidAdminWillReturnHtmlTemplate(): void $this->form->method('setAttribute')->willReturn($this->form); $this->form->method('bind')->willReturn($this->form); - $this->request->method('getAttribute')->with('id')->willReturn($id->toString()); - $this->adminService->method('findAdmin')->with($id->toString())->willReturn($admin); + $this->request->method('getAttribute')->willReturn($id->toString()); + $this->adminService->method('findAdmin')->willReturn($admin); $this->template->method('render')->willReturn('

'); + $this->messenger->expects($this->never())->method('addError'); $handler = new GetEditAdminFormHandler( $this->adminService, diff --git a/test/Unit/Admin/Handler/Admin/GetAdminListHandlerTest.php b/test/Unit/Admin/Handler/Admin/GetAdminListHandlerTest.php index 61e2cf7..73a0f3b 100644 --- a/test/Unit/Admin/Handler/Admin/GetAdminListHandlerTest.php +++ b/test/Unit/Admin/Handler/Admin/GetAdminListHandlerTest.php @@ -21,13 +21,13 @@ class GetAdminListHandlerTest extends UnitTest */ public function testListAdminWillReturnHtmlResponse(): void { - $adminService = $this->createMock(AdminServiceInterface::class); - $template = $this->createMock(TemplateRendererInterface::class); - $adminRepository = $this->createMock(AdminRepository::class); - $request = $this->createMock(ServerRequestInterface::class); + $adminService = $this->createStub(AdminServiceInterface::class); + $template = $this->createStub(TemplateRendererInterface::class); + $adminRepository = $this->createStub(AdminRepository::class); + $request = $this->createStub(ServerRequestInterface::class); $request->method('getQueryParams')->willReturn([]); - $adminRepository->method('findOneBy')->willReturn($this->createMock(Admin::class)); + $adminRepository->method('findOneBy')->willReturn($this->createStub(Admin::class)); $adminService->method('getAdmins')->willReturn([ 'rows' => [], 'total' => 1, diff --git a/test/Unit/Admin/Handler/Admin/GetAdminLoginListHandlerTest.php b/test/Unit/Admin/Handler/Admin/GetAdminLoginListHandlerTest.php index 35db4a8..543705a 100644 --- a/test/Unit/Admin/Handler/Admin/GetAdminLoginListHandlerTest.php +++ b/test/Unit/Admin/Handler/Admin/GetAdminLoginListHandlerTest.php @@ -19,9 +19,9 @@ class GetAdminLoginListHandlerTest extends UnitTest */ public function testListAdminLoginsWillReturnHtmlResponse(): void { - $adminLoginService = $this->createMock(AdminLoginServiceInterface::class); - $template = $this->createMock(TemplateRendererInterface::class); - $request = $this->createMock(ServerRequestInterface::class); + $adminLoginService = $this->createStub(AdminLoginServiceInterface::class); + $template = $this->createStub(TemplateRendererInterface::class); + $request = $this->createStub(ServerRequestInterface::class); $request->method('getQueryParams')->willReturn([]); $adminLoginService->method('getAdminLogins')->willReturn([]); diff --git a/test/Unit/Admin/Handler/Admin/PostAdminCreateHandlerTest.php b/test/Unit/Admin/Handler/Admin/PostAdminCreateHandlerTest.php index 8af3af4..10a7276 100644 --- a/test/Unit/Admin/Handler/Admin/PostAdminCreateHandlerTest.php +++ b/test/Unit/Admin/Handler/Admin/PostAdminCreateHandlerTest.php @@ -18,17 +18,18 @@ use Mezzio\Template\TemplateRendererInterface; use PHPUnit\Framework\MockObject\Exception as MockObjectException; use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\MockObject\Stub; use Psr\Http\Message\ServerRequestInterface; class PostAdminCreateHandlerTest extends UnitTest { - private MockObject&AdminServiceInterface $adminService; - private MockObject&RouterInterface $router; - private MockObject&TemplateRendererInterface $template; + private Stub&AdminServiceInterface $adminService; + private Stub&RouterInterface $router; + private Stub&TemplateRendererInterface $template; private MockObject&FlashMessengerInterface $messenger; - private MockObject&CreateAdminForm $adminForm; + private Stub&CreateAdminForm $adminForm; private Logger $logger; - private MockObject&ServerRequestInterface $request; + private Stub&ServerRequestInterface $request; /** * @throws MockObjectException @@ -37,12 +38,12 @@ public function setUp(): void { parent::setUp(); - $this->adminService = $this->createMock(AdminServiceInterface::class); - $this->router = $this->createMock(RouterInterface::class); - $this->template = $this->createMock(TemplateRendererInterface::class); + $this->adminService = $this->createStub(AdminServiceInterface::class); + $this->router = $this->createStub(RouterInterface::class); + $this->template = $this->createStub(TemplateRendererInterface::class); $this->messenger = $this->createMock(FlashMessengerInterface::class); - $this->adminForm = $this->createMock(CreateAdminForm::class); - $this->request = $this->createMock(ServerRequestInterface::class); + $this->adminForm = $this->createStub(CreateAdminForm::class); + $this->request = $this->createStub(ServerRequestInterface::class); $this->logger = new Logger([ 'writers' => [ 'FileWriter' => [ @@ -84,6 +85,8 @@ public function testCreateAdminInvalidFormProvidedWillReturnHtmlResponse(): void $this->request->method('getParsedBody')->willReturn(['test']); $this->adminForm->method('isValid')->willReturn(false); $this->adminForm->method('getData')->willReturn([]); + $this->messenger->expects($this->never())->method('addError'); + $this->messenger->expects($this->never())->method('addSuccess'); $handler = new PostCreateAdminHandler( $this->adminService, @@ -103,6 +106,8 @@ public function testCreateAdminIdentityExceptionWillReturnHtmlResponse(): void { $this->request->method('getParsedBody')->willReturn(['test']); $this->adminForm->method('getData')->willReturn([]); + $this->messenger->expects($this->never())->method('addError'); + $this->messenger->expects($this->never())->method('addSuccess'); $this->throwException(new ConflictException()); @@ -124,6 +129,8 @@ public function testCreateAdminThrowExceptionWillReturnHtmlResponse(): void { $this->request->method('getParsedBody')->willReturn(['test']); $this->adminForm->method('getData')->willReturn([]); + $this->messenger->expects($this->never())->method('addError'); + $this->messenger->expects($this->never())->method('addSuccess'); $this->throwException(new Exception()); diff --git a/test/Unit/Admin/Handler/Admin/PostAdminDeleteHandlerTest.php b/test/Unit/Admin/Handler/Admin/PostAdminDeleteHandlerTest.php index c22f785..3e0077c 100644 --- a/test/Unit/Admin/Handler/Admin/PostAdminDeleteHandlerTest.php +++ b/test/Unit/Admin/Handler/Admin/PostAdminDeleteHandlerTest.php @@ -19,18 +19,19 @@ use Mezzio\Template\TemplateRendererInterface; use PHPUnit\Framework\MockObject\Exception as MockObjectException; use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\MockObject\Stub; use Psr\Http\Message\ServerRequestInterface; use Ramsey\Uuid\Uuid; class PostAdminDeleteHandlerTest extends UnitTest { private MockObject&AdminServiceInterface $adminService; - private MockObject&RouterInterface $router; - private MockObject&TemplateRendererInterface $template; + private Stub&RouterInterface $router; + private Stub&TemplateRendererInterface $template; private MockObject&FlashMessengerInterface $messenger; - private MockObject&DeleteAdminForm $form; + private Stub&DeleteAdminForm $form; private Logger $logger; - private MockObject&ServerRequestInterface $request; + private Stub&ServerRequestInterface $request; /** * @throws MockObjectException @@ -40,11 +41,11 @@ public function setUp(): void parent::setUp(); $this->adminService = $this->createMock(AdminServiceInterface::class); - $this->router = $this->createMock(RouterInterface::class); - $this->template = $this->createMock(TemplateRendererInterface::class); + $this->router = $this->createStub(RouterInterface::class); + $this->template = $this->createStub(TemplateRendererInterface::class); $this->messenger = $this->createMock(FlashMessengerInterface::class); - $this->form = $this->createMock(DeleteAdminForm::class); - $this->request = $this->createMock(ServerRequestInterface::class); + $this->form = $this->createStub(DeleteAdminForm::class); + $this->request = $this->createStub(ServerRequestInterface::class); $this->logger = new Logger([ 'writers' => [ 'FileWriter' => [ @@ -57,8 +58,11 @@ public function setUp(): void public function testDeleteAdminInvalidAdminProvidedWillReturnNotFoundResponse(): void { - $this->request->method('getAttribute')->with('id')->willReturn('test'); - $this->adminService->method('findAdmin')->willThrowException(new NotFoundException(Message::ADMIN_NOT_FOUND)); + $this->request->method('getAttribute')->willReturn('test'); + $this->adminService + ->expects($this->once()) + ->method('findAdmin') + ->willThrowException(new NotFoundException(Message::ADMIN_NOT_FOUND)); $this ->messenger @@ -85,14 +89,14 @@ public function testDeleteAdminInvalidAdminProvidedWillReturnNotFoundResponse(): */ public function testDeleteAdminValidFormDataProvidedWillFlashSuccessMessage(): void { - $id = $this->createMock(Uuid::class); - $admin = $this->createMock(Admin::class); + $id = $this->createStub(Uuid::class); + $admin = $this->createStub(Admin::class); $id->method('toString')->willReturn('0x123'); $admin->method('getId')->willReturn($id); - $this->request->method('getAttribute')->with('id')->willReturn($id->toString()); - $this->adminService->method('findAdmin')->with($id->toString())->willReturn($admin); + $this->request->method('getAttribute')->willReturn($id->toString()); + $this->adminService->method('findAdmin')->willReturn($admin); $this->request->method('getParsedBody')->willReturn([]); $this->form->method('isValid')->willReturn(true); @@ -124,19 +128,22 @@ public function testDeleteAdminValidFormDataProvidedWillFlashSuccessMessage(): v */ public function testDeleteAdminInvalidFormDataProvidedWillReturnHtmlResponse(): void { - $id = $this->createMock(Uuid::class); - $admin = $this->createMock(Admin::class); + $id = $this->createStub(Uuid::class); + $admin = $this->createStub(Admin::class); $id->method('toString')->willReturn('0x123'); $admin->method('getId')->willReturn($id); - $this->request->method('getAttribute')->with('id')->willReturn($id->toString()); + $this->request->method('getAttribute')->willReturn($id->toString()); $this->adminService->method('findAdmin')->with($id->toString())->willReturn($admin); $this->request->method('getParsedBody')->willReturn(['test']); $this->form->method('isValid')->willReturn(false); $this->form->method('getData')->willReturn([]); + $this->messenger->expects($this->never())->method('addError'); + $this->messenger->expects($this->never())->method('addSuccess'); + $handler = new PostDeleteAdminHandler( $this->adminService, $this->router, @@ -156,15 +163,17 @@ public function testDeleteAdminInvalidFormDataProvidedWillReturnHtmlResponse(): */ public function testDeleteAdminThrowsErrorWillReturnEmptyResponse(): void { - $this->request->method('getAttribute')->with('id')->willReturn('test'); - $this->adminService->method('findAdmin')->willReturn(new Admin()); + $this->request->method('getAttribute')->willReturn('test'); + $this->adminService + ->expects($this->once()) + ->method('findAdmin') + ->willReturn(new Admin()); $this->form->method('setData')->willThrowException(new Exception('test')); $this ->messenger ->expects($this->once()) - ->method('addError') - ->with(Message::AN_ERROR_OCCURRED); + ->method('addError'); $handler = new PostDeleteAdminHandler( $this->adminService, diff --git a/test/Unit/Admin/Handler/Admin/PostAdminEditHandlerTest.php b/test/Unit/Admin/Handler/Admin/PostAdminEditHandlerTest.php index 5a1cb3f..4b7fc20 100644 --- a/test/Unit/Admin/Handler/Admin/PostAdminEditHandlerTest.php +++ b/test/Unit/Admin/Handler/Admin/PostAdminEditHandlerTest.php @@ -22,21 +22,22 @@ use Mezzio\Template\TemplateRendererInterface; use PHPUnit\Framework\MockObject\Exception as MockObjectException; use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\MockObject\Stub; use Psr\Http\Message\ServerRequestInterface; use Ramsey\Uuid\Uuid; class PostAdminEditHandlerTest extends UnitTest { private MockObject&AdminServiceInterface $adminService; - private MockObject&AdminRoleServiceInterface $adminRoleService; - private MockObject&RouterInterface $router; - private MockObject&TemplateRendererInterface $template; + private Stub&AdminRoleServiceInterface $adminRoleService; + private Stub&RouterInterface $router; + private Stub&TemplateRendererInterface $template; private MockObject&FlashMessengerInterface $messenger; - private MockObject&EditAdminForm $form; + private Stub&EditAdminForm $form; private Logger $logger; - private MockObject&ServerRequestInterface $request; - private MockObject&Admin $admin; - private MockObject&Uuid $id; + private Stub&ServerRequestInterface $request; + private Stub&Admin $admin; + private Stub&Uuid $id; /** * @throws MockObjectException @@ -46,14 +47,14 @@ public function setUp(): void parent::setUp(); $this->adminService = $this->createMock(AdminServiceInterface::class); - $this->adminRoleService = $this->createMock(AdminRoleServiceInterface::class); - $this->router = $this->createMock(RouterInterface::class); - $this->template = $this->createMock(TemplateRendererInterface::class); + $this->adminRoleService = $this->createStub(AdminRoleServiceInterface::class); + $this->router = $this->createStub(RouterInterface::class); + $this->template = $this->createStub(TemplateRendererInterface::class); $this->messenger = $this->createMock(FlashMessengerInterface::class); - $this->form = $this->createMock(EditAdminForm::class); - $this->request = $this->createMock(ServerRequestInterface::class); - $this->admin = $this->createMock(Admin::class); - $this->id = $this->createMock(Uuid::class); + $this->form = $this->createStub(EditAdminForm::class); + $this->request = $this->createStub(ServerRequestInterface::class); + $this->admin = $this->createStub(Admin::class); + $this->id = $this->createStub(Uuid::class); $this->logger = new Logger([ 'writers' => [ 'FileWriter' => [ @@ -69,13 +70,15 @@ public function setUp(): void */ public function testEditAdminInvalidAdminProvidedWillReturnNotFoundResponse(): void { - $this->request->method('getAttribute')->with('id')->willReturn('test'); - $this->adminService->method('findAdmin')->willThrowException(new NotFoundException(Message::ADMIN_NOT_FOUND)); + $this->request->method('getAttribute')->willReturn('test'); + $this->adminService + ->expects($this->once()) + ->method('findAdmin') + ->willThrowException(new NotFoundException(Message::ADMIN_NOT_FOUND)); $this->form->method('isValid')->willReturn(true); $this->form->method('getData')->willReturn([]); - $this - ->messenger + $this->messenger ->expects($this->once()) ->method('addError') ->with(Message::ADMIN_NOT_FOUND); @@ -103,7 +106,7 @@ public function testEditAdminValidFormDataProvidedWillFlashSuccessMessage(): voi { $this->id->method('toString')->willReturn('0x123'); $this->admin->method('getId')->willReturn($this->id); - $this->request->method('getAttribute')->with('id')->willReturn($this->id->toString()); + $this->request->method('getAttribute')->willReturn($this->id->toString()); $this->adminService->method('findAdmin')->with($this->id->toString())->willReturn($this->admin); $this->form->method('setAttribute')->willReturn($this->form); $this->request->method('getParsedBody')->willReturn([]); @@ -141,12 +144,13 @@ public function testEditAdminInvalidFormDataProvidedWillReturnHtmlResponse(): vo { $this->id->method('toString')->willReturn('0x123'); $this->admin->method('getId')->willReturn($this->id); - $this->request->method('getAttribute')->with('id')->willReturn($this->id->toString()); + $this->request->method('getAttribute')->willReturn($this->id->toString()); $this->adminService->method('findAdmin')->with($this->id->toString())->willReturn($this->admin); $this->form->method('setAttribute')->willReturn($this->form); $this->request->method('getParsedBody')->willReturn(['test']); $this->form->method('isValid')->willReturn(false); $this->form->method('getData')->willReturn([]); + $this->messenger->expects($this->never())->method('addError'); $handler = new PostEditAdminHandler( $this->adminService, @@ -170,12 +174,13 @@ public function testEditAdminThrowConflictExceptionWillReturnHtmlResponse(): voi { $this->id->method('toString')->willReturn('0x123'); $this->admin->method('getId')->willReturn($this->id); - $this->request->method('getAttribute')->with('id')->willReturn($this->id->toString()); + $this->request->method('getAttribute')->willReturn($this->id->toString()); $this->adminService->method('findAdmin')->with($this->id->toString())->willReturn($this->admin); $this->form->method('setAttribute')->willReturn($this->form); $this->request->method('getParsedBody')->willReturn(['test']); $this->form->method('isValid')->willReturn(false); $this->form->method('getData')->willReturn([]); + $this->messenger->expects($this->never())->method('addError'); $handler = new PostEditAdminHandler( $this->adminService, @@ -201,12 +206,13 @@ public function testEditAdminThrowExceptionWillReturnHtmlResponse(): void { $this->id->method('toString')->willReturn('0x123'); $this->admin->method('getId')->willReturn($this->id); - $this->request->method('getAttribute')->with('id')->willReturn($this->id->toString()); + $this->request->method('getAttribute')->willReturn($this->id->toString()); $this->adminService->method('findAdmin')->with($this->id->toString())->willReturn($this->admin); $this->form->method('setAttribute')->willReturn($this->form); $this->request->method('getParsedBody')->willReturn(['test']); $this->form->method('isValid')->willReturn(false); $this->form->method('getData')->willReturn([]); + $this->messenger->expects($this->never())->method('addError'); $handler = new PostEditAdminHandler( $this->adminService, diff --git a/test/Unit/Admin/RoutesDelegatorTest.php b/test/Unit/Admin/RoutesDelegatorTest.php index 239b376..c38d52b 100644 --- a/test/Unit/Admin/RoutesDelegatorTest.php +++ b/test/Unit/Admin/RoutesDelegatorTest.php @@ -28,14 +28,14 @@ public function testWillInvoke(): void ->method('get') ->with(RouteCollectorInterface::class) ->willReturn( - $this->createMock(RouteCollectorInterface::class) + $this->createStub(RouteCollectorInterface::class) ); $application = (new RoutesDelegator())( $container, '', function () { - return $this->createMock(Application::class); + return $this->createStub(Application::class); } ); diff --git a/test/Unit/Admin/Service/AdminServiceTest.php b/test/Unit/Admin/Service/AdminServiceTest.php index cd3048d..80ab8d4 100644 --- a/test/Unit/Admin/Service/AdminServiceTest.php +++ b/test/Unit/Admin/Service/AdminServiceTest.php @@ -20,8 +20,8 @@ class AdminServiceTest extends UnitTest */ public function testWillCreate(): void { - $adminRepository = $this->createMock(AdminRepository::class); - $adminRoleRepository = $this->createMock(AdminRoleRepository::class); + $adminRepository = $this->createStub(AdminRepository::class); + $adminRoleRepository = $this->createStub(AdminRoleRepository::class); $service = new AdminService($adminRepository, $adminRoleRepository); diff --git a/test/Unit/App/Factory/AuthMiddlewareFactoryTest.php b/test/Unit/App/Factory/AuthMiddlewareFactoryTest.php index c3bb938..fb1c204 100644 --- a/test/Unit/App/Factory/AuthMiddlewareFactoryTest.php +++ b/test/Unit/App/Factory/AuthMiddlewareFactoryTest.php @@ -38,9 +38,9 @@ public function getGuards(): array } }); - $routerInterface = $this->createMock(RouterInterface::class); - $flashMessenger = $this->createMock(FlashMessenger::class); - $container = $this->createMock(ContainerInterface::class); + $routerInterface = $this->createStub(RouterInterface::class); + $flashMessenger = $this->createStub(FlashMessenger::class); + $container = $this->createStub(ContainerInterface::class); $rbacGuardOptions = new RbacGuardOptions([]); $rbacGuardOptions->setGuardsProvider([ diff --git a/test/Unit/App/Factory/EntityListenerResolverFactoryTest.php b/test/Unit/App/Factory/EntityListenerResolverFactoryTest.php index 1bfb9cd..8c1e554 100644 --- a/test/Unit/App/Factory/EntityListenerResolverFactoryTest.php +++ b/test/Unit/App/Factory/EntityListenerResolverFactoryTest.php @@ -18,7 +18,7 @@ class EntityListenerResolverFactoryTest extends UnitTest public function testWillInvoke(): void { $service = (new EntityListenerResolverFactory())( - $this->createMock(ContainerInterface::class) + $this->createStub(ContainerInterface::class) ); $this->assertSame(EntityListenerResolver::class, $service::class); diff --git a/test/Unit/App/Handler/GetIndexRedirectHandlerTest.php b/test/Unit/App/Handler/GetIndexRedirectHandlerTest.php index 522c906..77cddd2 100644 --- a/test/Unit/App/Handler/GetIndexRedirectHandlerTest.php +++ b/test/Unit/App/Handler/GetIndexRedirectHandlerTest.php @@ -24,8 +24,8 @@ public function setUp(): void { parent::setUp(); - $this->router = $this->createMock(RouterInterface::class); - $this->authenticationService = $this->createMock(AuthenticationServiceInterface::class); + $this->router = $this->createStub(RouterInterface::class); + $this->authenticationService = $this->createStub(AuthenticationServiceInterface::class); } public function testWillCreate(): void @@ -40,7 +40,7 @@ public function testWillCreate(): void */ public function testWillReturnRedirectResponse(): void { - $request = $this->createMock(ServerRequestInterface::class); + $request = $this->createStub(ServerRequestInterface::class); $handler = new GetIndexRedirectHandler($this->authenticationService, $this->router); diff --git a/test/Unit/App/Middleware/AuthMiddlewareTest.php b/test/Unit/App/Middleware/AuthMiddlewareTest.php index 34397d3..40be557 100644 --- a/test/Unit/App/Middleware/AuthMiddlewareTest.php +++ b/test/Unit/App/Middleware/AuthMiddlewareTest.php @@ -29,9 +29,9 @@ class AuthMiddlewareTest extends UnitTest public function testWillCreate(): void { $authMiddleware = new AuthMiddleware( - $this->createMock(RouterInterface::class), - $this->createMock(FlashMessengerInterface::class), - $this->createMock(GuardsProviderInterface::class), + $this->createStub(RouterInterface::class), + $this->createStub(FlashMessengerInterface::class), + $this->createStub(GuardsProviderInterface::class), new RbacGuardOptions([]) ); @@ -47,15 +47,15 @@ public function testWillRedirectWhenNotGranted(): void $rbacGuardOptions->setProtectionPolicy(GuardInterface::POLICY_DENY); $authMiddleware = new AuthMiddleware( - $this->createMock(RouterInterface::class), - $this->createMock(FlashMessengerInterface::class), - $this->createMock(GuardsProviderInterface::class), + $this->createStub(RouterInterface::class), + $this->createStub(FlashMessengerInterface::class), + $this->createStub(GuardsProviderInterface::class), $rbacGuardOptions ); $response = $authMiddleware->process( - $this->createMock(ServerRequestInterface::class), - $this->createMock(RequestHandlerInterface::class) + $this->createStub(ServerRequestInterface::class), + $this->createStub(RequestHandlerInterface::class) ); $this->assertInstanceOf(RedirectResponse::class, $response); $this->assertTrue($response->hasHeader('location')); @@ -68,15 +68,15 @@ public function testWillRedirectWhenNotGranted(): void public function testWillProcessWithoutGuards(): void { $authMiddleware = new AuthMiddleware( - $this->createMock(RouterInterface::class), - $this->createMock(FlashMessengerInterface::class), - $this->createMock(GuardsProviderInterface::class), + $this->createStub(RouterInterface::class), + $this->createStub(FlashMessengerInterface::class), + $this->createStub(GuardsProviderInterface::class), new RbacGuardOptions([]) ); $response = $authMiddleware->process( - $this->createMock(ServerRequestInterface::class), - $this->createMock(RequestHandlerInterface::class) + $this->createStub(ServerRequestInterface::class), + $this->createStub(RequestHandlerInterface::class) ); $this->assertContainsOnlyInstancesOf(ResponseInterface::class, [$response]); @@ -94,8 +94,8 @@ public function testWillProcessWithGuardsAndFailOnInvalidGuard(): void ->willReturn(['test']); $authMiddleware = new AuthMiddleware( - $this->createMock(RouterInterface::class), - $this->createMock(FlashMessengerInterface::class), + $this->createStub(RouterInterface::class), + $this->createStub(FlashMessengerInterface::class), $guardsProvider, new RbacGuardOptions([]) ); @@ -105,8 +105,8 @@ public function testWillProcessWithGuardsAndFailOnInvalidGuard(): void sprintf('Guard is not an instance of %s', GuardInterface::class) ); $authMiddleware->process( - $this->createMock(ServerRequestInterface::class), - $this->createMock(RequestHandlerInterface::class) + $this->createStub(ServerRequestInterface::class), + $this->createStub(RequestHandlerInterface::class) ); } @@ -134,15 +134,15 @@ public function getPriority(): int ]); $authMiddleware = new AuthMiddleware( - $this->createMock(RouterInterface::class), - $this->createMock(FlashMessengerInterface::class), + $this->createStub(RouterInterface::class), + $this->createStub(FlashMessengerInterface::class), $guardsProvider, new RbacGuardOptions([]) ); $response = $authMiddleware->process( - $this->createMock(ServerRequestInterface::class), - $this->createMock(RequestHandlerInterface::class) + $this->createStub(ServerRequestInterface::class), + $this->createStub(RequestHandlerInterface::class) ); $this->assertInstanceOf(RedirectResponse::class, $response); $this->assertTrue($response->hasHeader('location')); @@ -173,15 +173,15 @@ public function getPriority(): int ]); $authMiddleware = new AuthMiddleware( - $this->createMock(RouterInterface::class), - $this->createMock(FlashMessengerInterface::class), + $this->createStub(RouterInterface::class), + $this->createStub(FlashMessengerInterface::class), $guardsProvider, new RbacGuardOptions([]) ); $response = $authMiddleware->process( - $this->createMock(ServerRequestInterface::class), - $this->createMock(RequestHandlerInterface::class) + $this->createStub(ServerRequestInterface::class), + $this->createStub(RequestHandlerInterface::class) ); $this->assertContainsOnlyInstancesOf(ResponseInterface::class, [$response]); diff --git a/test/Unit/App/Plugin/FormsPluginTest.php b/test/Unit/App/Plugin/FormsPluginTest.php index 97939dd..36ea021 100644 --- a/test/Unit/App/Plugin/FormsPluginTest.php +++ b/test/Unit/App/Plugin/FormsPluginTest.php @@ -20,8 +20,8 @@ class FormsPluginTest extends UnitTest */ public function testWillInstantiate(): void { - $formElementManager = $this->createMock(FormElementManager::class); - $flashMessengerInterface = $this->createMock(FlashMessengerInterface::class); + $formElementManager = $this->createStub(FormElementManager::class); + $flashMessengerInterface = $this->createStub(FlashMessengerInterface::class); $formsPlugin = new FormsPlugin($formElementManager, $flashMessengerInterface); $this->assertSame(FormsPlugin::class, $formsPlugin::class); @@ -46,7 +46,7 @@ public function testWillRestoreState(): void 'loginCsrf' => $hash, ]; - $formElementManager = $this->createMock(FormElementManager::class); + $formElementManager = $this->createStub(FormElementManager::class); $flashMessengerInterface = $this->createMock(FlashMessengerInterface::class); $flashMessengerInterface ->expects($this->exactly(2)) @@ -107,7 +107,7 @@ public function testWillSaveState(): void 'test-message', ]; - $formElementManager = $this->createMock(FormElementManager::class); + $formElementManager = $this->createStub(FormElementManager::class); $flashMessengerInterface = $this->getDummyFlashMessenger(); $form = new LoginForm('loginForm'); @@ -135,8 +135,8 @@ public function testWillGetMessages(): void $form->setData([]); $this->assertFalse($form->isValid()); - $formElementManager = $this->createMock(FormElementManager::class); - $flashMessengerInterface = $this->createMock(FlashMessengerInterface::class); + $formElementManager = $this->createStub(FormElementManager::class); + $flashMessengerInterface = $this->createStub(FlashMessengerInterface::class); $formsPlugin = new FormsPlugin($formElementManager, $flashMessengerInterface); diff --git a/test/Unit/App/Resolver/EntityListenerResolverTest.php b/test/Unit/App/Resolver/EntityListenerResolverTest.php index 50e155f..f6b3733 100644 --- a/test/Unit/App/Resolver/EntityListenerResolverTest.php +++ b/test/Unit/App/Resolver/EntityListenerResolverTest.php @@ -20,7 +20,7 @@ class EntityListenerResolverTest extends UnitTest public function testWillCreate(): void { $resolver = new EntityListenerResolver( - $this->createMock(ContainerInterface::class) + $this->createStub(ContainerInterface::class) ); $this->assertSame(EntityListenerResolver::class, $resolver::class); @@ -61,7 +61,7 @@ public function testWillResolveExistingItem(): void ->method('get') ->with(EntityListenerResolver::class) ->willReturn( - $this->createMock(EntityListenerResolver::class) + $this->createStub(EntityListenerResolver::class) ); $resolver = new EntityListenerResolver($container); diff --git a/test/Unit/App/RoutesDelegatorTest.php b/test/Unit/App/RoutesDelegatorTest.php index 2683f15..6aebd95 100644 --- a/test/Unit/App/RoutesDelegatorTest.php +++ b/test/Unit/App/RoutesDelegatorTest.php @@ -28,14 +28,14 @@ public function testWillInvoke(): void ->method('get') ->with(RouteCollectorInterface::class) ->willReturn( - $this->createMock(RouteCollectorInterface::class) + $this->createStub(RouteCollectorInterface::class) ); $application = (new RoutesDelegator())( $container, '', function () { - return $this->createMock(Application::class); + return $this->createStub(Application::class); } ); diff --git a/test/Unit/App/Twig/Extension/RouteExtensionTest.php b/test/Unit/App/Twig/Extension/RouteExtensionTest.php index a6b0ae7..af12db6 100644 --- a/test/Unit/App/Twig/Extension/RouteExtensionTest.php +++ b/test/Unit/App/Twig/Extension/RouteExtensionTest.php @@ -22,7 +22,7 @@ class RouteExtensionTest extends UnitTest public function testWillInstantiate(): void { $routeExtension = new RouteExtension( - $this->createMock(UrlHelper::class) + $this->createStub(UrlHelper::class) ); $this->assertSame(RouteExtension::class, $routeExtension::class); @@ -34,7 +34,7 @@ public function testWillInstantiate(): void public function testWillAddExistingFunctions(): void { $routeExtension = new RouteExtension( - $this->createMock(UrlHelper::class) + $this->createStub(UrlHelper::class) ); $functions = $routeExtension->getFunctions(); @@ -56,9 +56,9 @@ public function testWillAddExistingFunctions(): void */ public function testIsRoute(): void { - $request = $this->createMock(ServerRequestInterface::class); - $urlHelper = $this->createMock(UrlHelper::class); - $routeResult = $this->createMock(RouteResult::class); + $request = $this->createStub(ServerRequestInterface::class); + $urlHelper = $this->createStub(UrlHelper::class); + $routeResult = $this->createStub(RouteResult::class); $routeResult->method('getMatchedRouteName')->willReturn('test'); $urlHelper->method('getRouteResult')->willReturn($routeResult); diff --git a/test/Unit/Dashboard/Handler/GetDashboardViewHandlerTest.php b/test/Unit/Dashboard/Handler/GetDashboardViewHandlerTest.php index 92c8dbc..5f0f97c 100644 --- a/test/Unit/Dashboard/Handler/GetDashboardViewHandlerTest.php +++ b/test/Unit/Dashboard/Handler/GetDashboardViewHandlerTest.php @@ -19,16 +19,15 @@ class GetDashboardViewHandlerTest extends UnitTest */ public function testPageWillReturnHtmlTemplate(): void { - $request = $this->createMock(ServerRequestInterface::class); - $routeResult = $this->createMock(RouteResult::class); - $template = $this->createMock(TemplateRendererInterface::class); + $request = $this->createStub(ServerRequestInterface::class); + $routeResult = $this->createStub(RouteResult::class); + $template = $this->createStub(TemplateRendererInterface::class); $routeResult->method('getMatchedRouteName')->willReturn('test'); $template->method('render')->willReturn('

'); $request ->method('getAttribute') - ->with(RouteResult::class) ->willReturn($routeResult); $handler = new GetViewDashboardHandler($template); diff --git a/test/Unit/Dashboard/RoutesDelegatorTest.php b/test/Unit/Dashboard/RoutesDelegatorTest.php index 33e935f..a92fc91 100644 --- a/test/Unit/Dashboard/RoutesDelegatorTest.php +++ b/test/Unit/Dashboard/RoutesDelegatorTest.php @@ -28,14 +28,14 @@ public function testWillInvoke(): void ->method('get') ->with(RouteCollectorInterface::class) ->willReturn( - $this->createMock(RouteCollectorInterface::class) + $this->createStub(RouteCollectorInterface::class) ); $application = (new RoutesDelegator())( $container, '', function () { - return $this->createMock(Application::class); + return $this->createStub(Application::class); } ); diff --git a/test/Unit/Page/Handler/GetPageViewHandlerTest.php b/test/Unit/Page/Handler/GetPageViewHandlerTest.php index 86fa411..23ac340 100644 --- a/test/Unit/Page/Handler/GetPageViewHandlerTest.php +++ b/test/Unit/Page/Handler/GetPageViewHandlerTest.php @@ -19,16 +19,15 @@ class GetPageViewHandlerTest extends UnitTest */ public function testPageWillReturnHtmlTemplate(): void { - $request = $this->createMock(ServerRequestInterface::class); - $routeResult = $this->createMock(RouteResult::class); - $template = $this->createMock(TemplateRendererInterface::class); + $request = $this->createStub(ServerRequestInterface::class); + $routeResult = $this->createStub(RouteResult::class); + $template = $this->createStub(TemplateRendererInterface::class); $routeResult->method('getMatchedRouteName')->willReturn('test'); $template->method('render')->willReturn('

'); $request ->method('getAttribute') - ->with(RouteResult::class) ->willReturn($routeResult); $handler = new GetViewPageHandler($template); diff --git a/test/Unit/Page/RoutesDelegatorTest.php b/test/Unit/Page/RoutesDelegatorTest.php index 0a1085e..3a868fc 100644 --- a/test/Unit/Page/RoutesDelegatorTest.php +++ b/test/Unit/Page/RoutesDelegatorTest.php @@ -22,11 +22,11 @@ class RoutesDelegatorTest extends UnitTest */ public function testWillInvoke(): void { - $container = $this->createMock(ContainerInterface::class); + $container = $this->createStub(ContainerInterface::class); $container ->method('get') ->willReturnMap([ - [RouteCollectorInterface::class, $this->createMock(RouteCollectorInterface::class)], + [RouteCollectorInterface::class, $this->createStub(RouteCollectorInterface::class)], ['config', []], ]); @@ -34,7 +34,7 @@ public function testWillInvoke(): void $container, '', function () { - return $this->createMock(Application::class); + return $this->createStub(Application::class); } ); diff --git a/test/Unit/Setting/Entity/SettingEntityTest.php b/test/Unit/Setting/Entity/SettingEntityTest.php index 8b97a23..dc0c066 100644 --- a/test/Unit/Setting/Entity/SettingEntityTest.php +++ b/test/Unit/Setting/Entity/SettingEntityTest.php @@ -28,7 +28,7 @@ public function setUp(): void { parent::setUp(); - $this->admin = $this->createMock(Admin::class); + $this->admin = $this->createStub(Admin::class); } public function testAttributes(): void diff --git a/test/Unit/Setting/Handler/GetSettingHandlerTest.php b/test/Unit/Setting/Handler/GetSettingHandlerTest.php index 8627ae6..540b4b8 100644 --- a/test/Unit/Setting/Handler/GetSettingHandlerTest.php +++ b/test/Unit/Setting/Handler/GetSettingHandlerTest.php @@ -32,9 +32,9 @@ class GetSettingHandlerTest extends UnitTest public function testWillCreate(): void { $handler = new GetViewSettingHandler( - $this->createMock(AuthenticationServiceInterface::class), - $this->createMock(AdminService::class), - $this->createMock(SettingService::class), + $this->createStub(AuthenticationServiceInterface::class), + $this->createStub(AdminService::class), + $this->createStub(SettingService::class), ); $this->assertSame(GetViewSettingHandler::class, $handler::class); @@ -45,10 +45,10 @@ public function testWillCreate(): void */ public function testInvalidIdentifierProvided(): void { - $authenticationService = $this->createMock(AuthenticationServiceInterface::class); - $adminService = $this->createMock(AdminService::class); - $settingService = $this->createMock(SettingService::class); - $request = $this->createMock(ServerRequestInterface::class); + $authenticationService = $this->createStub(AuthenticationServiceInterface::class); + $adminService = $this->createStub(AdminService::class); + $settingService = $this->createStub(SettingService::class); + $request = $this->createStub(ServerRequestInterface::class); $handler = new GetViewSettingHandler( $authenticationService, @@ -56,7 +56,7 @@ public function testInvalidIdentifierProvided(): void $settingService, ); - $request->method('getAttribute')->with('identifier')->willReturn('test'); + $request->method('getAttribute')->willReturn('test'); $response = $handler->handle($request); @@ -73,11 +73,11 @@ public function testInvalidIdentifierProvided(): void */ public function testInvalidAdminProvided(): void { - $authenticationService = $this->createMock(AuthenticationServiceInterface::class); - $adminService = $this->createMock(AdminServiceInterface::class); - $settingService = $this->createMock(SettingServiceInterface::class); - $request = $this->createMock(ServerRequestInterface::class); - $identity = $this->createMock(AdminIdentity::class); + $authenticationService = $this->createStub(AuthenticationServiceInterface::class); + $adminService = $this->createStub(AdminServiceInterface::class); + $settingService = $this->createStub(SettingServiceInterface::class); + $request = $this->createStub(ServerRequestInterface::class); + $identity = $this->createStub(AdminIdentity::class); $identity->method('getId')->willReturn('test'); $authenticationService->method('getIdentity')->willReturn($identity); @@ -85,7 +85,6 @@ public function testInvalidAdminProvided(): void $request ->method('getAttribute') - ->with('identifier') ->willReturn(SettingIdentifierEnum::IdentifierTableAdminListSelectedColumns->value); $handler = new GetViewSettingHandler( @@ -112,12 +111,12 @@ public function testInvalidAdminProvided(): void */ public function testInvalidSettingProvided(): void { - $authenticationService = $this->createMock(AuthenticationServiceInterface::class); - $adminService = $this->createMock(AdminServiceInterface::class); - $settingService = $this->createMock(SettingServiceInterface::class); - $request = $this->createMock(ServerRequestInterface::class); - $identity = $this->createMock(AdminIdentity::class); - $admin = $this->createMock(Admin::class); + $authenticationService = $this->createStub(AuthenticationServiceInterface::class); + $adminService = $this->createStub(AdminServiceInterface::class); + $settingService = $this->createStub(SettingServiceInterface::class); + $request = $this->createStub(ServerRequestInterface::class); + $identity = $this->createStub(AdminIdentity::class); + $admin = $this->createStub(Admin::class); $identity->method('getId')->willReturn('test'); $authenticationService->method('getIdentity')->willReturn($identity); @@ -125,7 +124,6 @@ public function testInvalidSettingProvided(): void $request ->method('getAttribute') - ->with('identifier') ->willReturn(SettingIdentifierEnum::IdentifierTableAdminListSelectedColumns->value); $handler = new GetViewSettingHandler( @@ -152,18 +150,18 @@ public function testInvalidSettingProvided(): void */ public function testValidDataProvided(): void { - $authenticationService = $this->createMock(AuthenticationServiceInterface::class); - $adminService = $this->createMock(AdminService::class); - $settingService = $this->createMock(SettingService::class); - $adminRepository = $this->createMock(AdminRepository::class); - $request = $this->createMock(ServerRequestInterface::class); - $identity = $this->createMock(AdminIdentity::class); - $admin = $this->createMock(Admin::class); - $setting = $this->createMock(Setting::class); + $authenticationService = $this->createStub(AuthenticationServiceInterface::class); + $adminService = $this->createStub(AdminService::class); + $settingService = $this->createStub(SettingService::class); + $adminRepository = $this->createStub(AdminRepository::class); + $request = $this->createStub(ServerRequestInterface::class); + $identity = $this->createStub(AdminIdentity::class); + $admin = $this->createStub(Admin::class); + $setting = $this->createStub(Setting::class); $identity->method('getId')->willReturn('test'); $authenticationService->method('getIdentity')->willReturn($identity); - $adminRepository->method('findOneBy')->with(['id' => 'test'])->willReturn($admin); + $adminRepository->method('findOneBy')->willReturn($admin); $adminService->method('getAdminRepository')->willReturn($adminRepository); $setting->method('getArrayCopy')->willReturn([ 'identifier' => 'test', @@ -173,7 +171,6 @@ public function testValidDataProvided(): void $request ->method('getAttribute') - ->with('identifier') ->willReturn(SettingIdentifierEnum::IdentifierTableAdminListSelectedColumns->value); $handler = new GetViewSettingHandler( diff --git a/test/Unit/Setting/Handler/StoreSettingHandlerTest.php b/test/Unit/Setting/Handler/StoreSettingHandlerTest.php index 944e06d..21224d4 100644 --- a/test/Unit/Setting/Handler/StoreSettingHandlerTest.php +++ b/test/Unit/Setting/Handler/StoreSettingHandlerTest.php @@ -17,7 +17,7 @@ use Fig\Http\Message\StatusCodeInterface; use Laminas\Authentication\AuthenticationServiceInterface; use PHPUnit\Framework\MockObject\Exception; -use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\MockObject\Stub; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\StreamInterface; @@ -27,13 +27,13 @@ class StoreSettingHandlerTest extends UnitTest { - private MockObject&AuthenticationServiceInterface $authenticationService; - private MockObject&AdminService $adminService; - private MockObject&SettingService $settingService; - private MockObject&ServerRequestInterface $request; - private MockObject&StreamInterface $stream; - private MockObject&AdminIdentity $identity; - private MockObject&Admin $admin; + private Stub&AuthenticationServiceInterface $authenticationService; + private Stub&AdminService $adminService; + private Stub&SettingService $settingService; + private Stub&ServerRequestInterface $request; + private Stub&StreamInterface $stream; + private Stub&AdminIdentity $identity; + private Stub&Admin $admin; /** * @throws Exception @@ -42,13 +42,13 @@ public function setUp(): void { parent::setUp(); - $this->authenticationService = $this->createMock(AuthenticationServiceInterface::class); - $this->adminService = $this->createMock(AdminService::class); - $this->settingService = $this->createMock(SettingService::class); - $this->request = $this->createMock(ServerRequestInterface::class); - $this->stream = $this->createMock(StreamInterface::class); - $this->identity = $this->createMock(AdminIdentity::class); - $this->admin = $this->createMock(Admin::class); + $this->authenticationService = $this->createStub(AuthenticationServiceInterface::class); + $this->adminService = $this->createStub(AdminService::class); + $this->settingService = $this->createStub(SettingService::class); + $this->request = $this->createStub(ServerRequestInterface::class); + $this->stream = $this->createStub(StreamInterface::class); + $this->identity = $this->createStub(AdminIdentity::class); + $this->admin = $this->createStub(Admin::class); } public function testWillCreate(): void @@ -78,7 +78,7 @@ public function testInvalidIdentifierProvided(): void 'value' => 'test', ])); - $this->request->method('getAttribute')->with('identifier')->willReturn('test'); + $this->request->method('getAttribute')->willReturn('test'); $this->request->method('getBody')->willReturn($this->stream); $response = $handler->handle($this->request); @@ -110,10 +110,9 @@ public function testInvalidAdminProvided(): void $this->request ->method('getAttribute') - ->with('identifier') ->willReturn(SettingIdentifierEnum::IdentifierTableAdminListSelectedColumns->value); - $this->request->method('getAttribute')->with('identifier')->willReturn('test'); + $this->request->method('getAttribute')->willReturn('test'); $this->request->method('getBody')->willReturn($this->stream); $handler = new PostStoreSettingHandler( @@ -141,12 +140,12 @@ public function testInvalidAdminProvided(): void */ public function testUpdateSetting(): void { + $settingService = $this->createMock(SettingService::class); + $settingService->method('findOneBy')->willReturn($this->createStub(Setting::class)); + $settingService->expects($this->once())->method('updateSetting'); + $this->identity->method('getId')->willReturn('test'); $this->authenticationService->method('getIdentity')->willReturn($this->identity); - $this->settingService->method('findOneBy')->willReturn( - $this->createMock(Setting::class) - ); - $this->settingService->expects($this->once())->method('updateSetting'); $this->adminService->method('findAdmin')->willReturn($this->admin); $this->stream->method('getContents')->willReturn(json_encode([ 'identifier' => SettingIdentifierEnum::IdentifierTableAdminListSelectedColumns->value, @@ -156,13 +155,12 @@ public function testUpdateSetting(): void $this->request->method('getBody')->willReturn($this->stream); $this->request ->method('getAttribute') - ->with('identifier') ->willReturn(SettingIdentifierEnum::IdentifierTableAdminListSelectedColumns->value); $handler = new PostStoreSettingHandler( $this->authenticationService, $this->adminService, - $this->settingService, + $settingService, ); $response = $handler->handle($this->request); diff --git a/test/Unit/Setting/RoutesDelegatorTest.php b/test/Unit/Setting/RoutesDelegatorTest.php index 99821a2..eac4ba9 100644 --- a/test/Unit/Setting/RoutesDelegatorTest.php +++ b/test/Unit/Setting/RoutesDelegatorTest.php @@ -28,14 +28,14 @@ public function testWillInvoke(): void ->method('get') ->with(RouteCollectorInterface::class) ->willReturn( - $this->createMock(RouteCollectorInterface::class) + $this->createStub(RouteCollectorInterface::class) ); $application = (new RoutesDelegator())( $container, '', function () { - return $this->createMock(Application::class); + return $this->createStub(Application::class); } ); diff --git a/test/Unit/Setting/Service/SettingServiceTest.php b/test/Unit/Setting/Service/SettingServiceTest.php index 66e3d0e..4b7d889 100644 --- a/test/Unit/Setting/Service/SettingServiceTest.php +++ b/test/Unit/Setting/Service/SettingServiceTest.php @@ -16,7 +16,7 @@ class SettingServiceTest extends UnitTest */ public function testWillCreate(): void { - $settingRepository = $this->createMock(SettingRepository::class); + $settingRepository = $this->createStub(SettingRepository::class); $service = new SettingService($settingRepository);