From 240b39c068a753bae21447e763288178fc0b2ccb Mon Sep 17 00:00:00 2001 From: Vincent <407859+vincentchalamon@users.noreply.github.com> Date: Tue, 14 Jan 2025 17:14:05 +0100 Subject: [PATCH] chore: update PHPUnit version (#148) --- .github/workflows/ci.yml | 5 +- composer.json | 14 +---- features/app/bootstrap.php | 10 ---- phpunit-legacy.xml.dist | 31 +++++++++++ phpunit.xml.dist | 51 +++++++++++-------- .../DocumentationNormalizerTest.php | 13 +++-- .../RequestEventListenerTest.php | 10 ++-- tests/Manager/ForgotPasswordManagerTest.php | 16 ++---- tests/Manager/PasswordTokenManagerTest.php | 12 ++--- 9 files changed, 90 insertions(+), 72 deletions(-) create mode 100644 phpunit-legacy.xml.dist diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d8374ea..b802adc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,6 +37,9 @@ jobs: - '^3.4' - '^4.0' include: + - phpunit: 'phpunit.xml.dist' + - php: '8.1' + phpunit: 'phpunit-legacy.xml.dist' - php: '8.4' symfony: '7.1.*' api-platform: '^4.0' @@ -76,7 +79,7 @@ jobs: - name: Update project dependencies run: composer update --no-progress --ansi --prefer-stable --prefer-dist --no-scripts - name: Run PHPUnit tests - run: vendor/bin/simple-phpunit --colors=always --testdox + run: vendor/bin/phpunit --colors=always --testdox -c ${{ matrix.phpunit }} - name: Run Behat tests run: | mkdir -p features/app/cache/test/doctrine/orm/Proxies features/app/logs diff --git a/composer.json b/composer.json index e2206f1..2a878d1 100644 --- a/composer.json +++ b/composer.json @@ -36,12 +36,11 @@ "jms/serializer-bundle": "^1.4 || ^2.3 || ^3.0 || ^4.0 || ^5.0", "laminas/laminas-code": "^3.4 || ^4.0", "ocramius/proxy-manager": "^2.0.4", - "sebastian/comparator": "^3.0", + "phpunit/phpunit": "^10.0 || ^11.0", "symfony/asset": "^5.1 || ^6.0 || ^7.0", "symfony/browser-kit": "^5.1 || ^6.0 || ^7.0", "symfony/framework-bundle": "^5.1 || ^6.0 || ^7.0", "symfony/mailer": "^5.1 || ^6.0 || ^7.0", - "symfony/phpunit-bridge": "^5.1 || ^6.0 || ^7.0", "symfony/property-access": "^5.1 || ^6.0 || ^7.0", "symfony/security-bundle": "^5.1 || ^6.0 || ^7.0", "symfony/stopwatch": "^5.1 || ^6.0 || ^7.0", @@ -62,18 +61,9 @@ "autoload-dev": { "psr-4": { "CoopTilleuls\\ForgotPasswordBundle\\Tests\\": "tests", - "App\\": "features/app/src", - "PHPUnit\\": "vendor/bin/.phpunit/phpunit/src" + "App\\": "features/app/src" } }, - "scripts": { - "post-install-cmd": [ - "vendor/bin/simple-phpunit --version" - ], - "post-update-cmd": [ - "vendor/bin/simple-phpunit --version" - ] - }, "extra": { "branch-alias": { "dev-main": "1.5.x-dev" diff --git a/features/app/bootstrap.php b/features/app/bootstrap.php index 00c1f27..bf77713 100644 --- a/features/app/bootstrap.php +++ b/features/app/bootstrap.php @@ -16,16 +16,6 @@ date_default_timezone_set('UTC'); -// PHPUnit's autoloader -if (!file_exists($phpUnitAutoloaderPath = __DIR__.'/../../vendor/bin/.phpunit/phpunit/vendor/autoload.php')) { - exit('PHPUnit is not installed. Please run vendor/bin/simple-phpunit --version to install it'); -} - -$phpunitLoader = require $phpUnitAutoloaderPath; -// Don't register the PHPUnit autoloader before the normal autoloader to prevent weird issues -$phpunitLoader->unregister(); -$phpunitLoader->register(); - $loader = require __DIR__.'/../../vendor/autoload.php'; BypassFinals::enable(); require 'AppKernel.php'; diff --git a/phpunit-legacy.xml.dist b/phpunit-legacy.xml.dist new file mode 100644 index 0000000..f0bdeab --- /dev/null +++ b/phpunit-legacy.xml.dist @@ -0,0 +1,31 @@ + + + + + + + + + + + tests + + + + + + src + + + diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 17326c1..bc08687 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,24 +1,33 @@ - - - - src - - - tests - features - vendor - - - - - - - - - - tests - - + + + + + + + + + tests + + + + + + src + + diff --git a/tests/Bridge/ApiPlatform/Serializer/DocumentationNormalizerTest.php b/tests/Bridge/ApiPlatform/Serializer/DocumentationNormalizerTest.php index 4ba359c..6f9a7eb 100755 --- a/tests/Bridge/ApiPlatform/Serializer/DocumentationNormalizerTest.php +++ b/tests/Bridge/ApiPlatform/Serializer/DocumentationNormalizerTest.php @@ -101,16 +101,21 @@ public function testItDecoratesNormalizedData(): void { $this->routerMock->expects($this->once())->method('getRouteCollection')->willReturn($this->routeCollectionMock); $this->routeCollectionMock->expects($this->exactly(3))->method('get') - ->withConsecutive(['coop_tilleuls_forgot_password.reset'], ['coop_tilleuls_forgot_password.get_token'], ['coop_tilleuls_forgot_password.update']) - ->willReturn($this->routeMock); - $this->routeMock->expects($this->exactly(3))->method('getPath')->willReturnOnConsecutiveCalls('/api/forgot-password/', '/api/forgot-password/{tokenValue}', '/api/forgot-password/{tokenValue}'); + ->willReturnCallback(function (string $arg) { + if (!\in_array($arg, ['coop_tilleuls_forgot_password.reset', 'coop_tilleuls_forgot_password.get_token', 'coop_tilleuls_forgot_password.update'], true)) { + throw new \InvalidArgumentException(); + } + + return $this->routeMock; + }); + $this->routeMock->expects($this->exactly(3))->method('getPath')->willReturn('/api/forgot-password/', '/api/forgot-password/{tokenValue}', '/api/forgot-password/{tokenValue}'); $this->providerChainMock->expects($this->once())->method('all')->willReturn([ 'user' => $this->providerMock, 'admin' => $this->providerMock, ]); $this->providerMock->expects($this->exactly(2))->method('getUserPasswordField')->willReturn('password'); - $this->providerMock->expects($this->exactly(2))->method('getUserAuthorizedFields')->willReturnOnConsecutiveCalls(['email'], ['username', 'email']); + $this->providerMock->expects($this->exactly(2))->method('getUserAuthorizedFields')->willReturn(['email'], ['username', 'email']); $this->normalizerMock->expects($this->once())->method('normalize')->with(new \stdClass(), 'bar', [])->willReturn([ 'tags' => [['name' => 'Login']], diff --git a/tests/EventListener/RequestEventListenerTest.php b/tests/EventListener/RequestEventListenerTest.php index d1b46cb..f3bcddf 100755 --- a/tests/EventListener/RequestEventListenerTest.php +++ b/tests/EventListener/RequestEventListenerTest.php @@ -160,7 +160,7 @@ public function testDecodeRequest(): void $this->providerMock->expects($this->never())->method('getUserAuthorizedFields'); $this->providerMock->expects($this->once())->method('getUserPasswordField')->willReturn('password'); $this->parameterBagMock->expects($this->once())->method('get')->with('_route')->willReturn('coop_tilleuls_forgot_password.update'); - $this->parameterBagMock->expects($this->exactly(2))->method('set')->withConsecutive(['provider', $this->providerMock], ['password', 'bar']); + $this->parameterBagMock->expects($this->exactly(2))->method('set'); if (method_exists(KernelEvent::class, 'isMainRequest')) { $this->eventMock->expects($this->once())->method('isMainRequest')->willReturn(true); @@ -191,7 +191,7 @@ public function testGetTokenFromRequestNoTokenException(): void $this->headerBagMock->expects($this->once())->method('get')->with('FP-provider')->willReturn('admin'); $this->providerChainMock->expects($this->once())->method('get')->with('admin')->willReturn($this->providerMock); - $this->parameterBagMock->expects($this->exactly(2))->method('get')->withConsecutive(['_route'], ['tokenValue'])->willReturnOnConsecutiveCalls('coop_tilleuls_forgot_password.update', 'foo'); + $this->parameterBagMock->expects($this->exactly(2))->method('get')->willReturn('coop_tilleuls_forgot_password.update', 'foo'); if (method_exists(KernelEvent::class, 'isMainRequest')) { $this->eventMock->expects($this->once())->method('isMainRequest')->willReturn(true); @@ -211,7 +211,7 @@ public function testGetTokenFromRequestInvalidTokenException(): void $this->headerBagMock->expects($this->once())->method('get')->with('FP-provider')->willReturn('admin'); $this->providerChainMock->expects($this->once())->method('get')->with('admin')->willReturn($this->providerMock); - $this->parameterBagMock->expects($this->exactly(2))->method('get')->withConsecutive(['_route'], ['tokenValue'])->willReturnOnConsecutiveCalls('coop_tilleuls_forgot_password.update', 'foo'); + $this->parameterBagMock->expects($this->exactly(2))->method('get')->willReturn('coop_tilleuls_forgot_password.update', 'foo'); if (method_exists(KernelEvent::class, 'isMainRequest')) { $this->eventMock->expects($this->once())->method('isMainRequest')->willReturn(true); @@ -229,8 +229,8 @@ public function testGetTokenFromRequest(): void $tokenMock = $this->createMock(AbstractPasswordToken::class); $this->headerBagMock->expects($this->once())->method('get')->with('FP-provider')->willReturn('user'); $this->providerChainMock->expects($this->once())->method('get')->with('user')->willReturn($this->providerMock); - $this->parameterBagMock->expects($this->exactly(2))->method('get')->withConsecutive(['_route'], ['tokenValue'])->willReturnOnConsecutiveCalls('coop_tilleuls_forgot_password.update', 'foo'); - $this->parameterBagMock->expects($this->exactly(2))->method('set')->withConsecutive(['token', $tokenMock], ['provider', $this->providerMock]); + $this->parameterBagMock->expects($this->exactly(2))->method('get')->willReturn('coop_tilleuls_forgot_password.update', 'foo'); + $this->parameterBagMock->expects($this->exactly(2))->method('set'); if (method_exists(KernelEvent::class, 'isMainRequest')) { $this->eventMock->expects($this->once())->method('isMainRequest')->willReturn(true); diff --git a/tests/Manager/ForgotPasswordManagerTest.php b/tests/Manager/ForgotPasswordManagerTest.php index a162a00..9930b1d 100755 --- a/tests/Manager/ForgotPasswordManagerTest.php +++ b/tests/Manager/ForgotPasswordManagerTest.php @@ -67,7 +67,6 @@ protected function setUp(): void public function testResetPasswordNotUser(): void { - $this->providerChainMock->expects($this->once())->method('get')->willReturn($this->providerMock); $this->providerMock->expects($this->once())->method('getManager')->willReturn($this->managerMock); $this->providerMock->expects($this->once())->method('getUserClass')->willReturn(User::class); $this->managerMock->expects($this->once())->method('findOneBy')->with(User::class, ['email' => 'foo@example.com']); @@ -79,12 +78,11 @@ public function testResetPasswordNotUser(): void $this->passwordManagerMock->expects($this->never())->method('findOneByUser')->with(self::any(), $this->providerMock); - $this->manager->resetPassword('email', 'foo@example.com'); + $this->manager->resetPassword('email', 'foo@example.com', $this->providerMock); } public function testResetPasswordWithNoPreviousToken(): void { - $this->providerChainMock->expects($this->once())->method('get')->willReturn($this->providerMock); $this->providerMock->expects($this->once())->method('getManager')->willReturn($this->managerMock); $this->providerMock->expects($this->once())->method('getUserClass')->willReturn(User::class); $this->providerMock->expects($this->once())->method('getPasswordTokenExpiredIn')->willReturn('+1 day'); @@ -98,12 +96,11 @@ public function testResetPasswordWithNoPreviousToken(): void $this->eventDispatcherMock->expects($this->once())->method('dispatch')->with(ForgotPasswordEvent::CREATE_TOKEN, $this->callback(fn ($event) => $event instanceof CreateTokenEvent && null === $event->getPassword() && $this->tokenMock === $event->getPasswordToken())); } - $this->manager->resetPassword('email', 'foo@example.com'); + $this->manager->resetPassword('email', 'foo@example.com', $this->providerMock); } public function testResetPasswordWithExpiredPreviousToken(): void { - $this->providerChainMock->expects($this->once())->method('get')->willReturn($this->providerMock); $this->providerMock->expects($this->once())->method('getManager')->willReturn($this->managerMock); $this->providerMock->expects($this->once())->method('getUserClass')->willReturn(User::class); $this->providerMock->expects($this->once())->method('getPasswordTokenExpiredIn')->willReturn('+1 day'); @@ -118,7 +115,7 @@ public function testResetPasswordWithExpiredPreviousToken(): void $this->eventDispatcherMock->expects($this->once())->method('dispatch')->with(ForgotPasswordEvent::CREATE_TOKEN, $this->callback(fn ($event) => $event instanceof CreateTokenEvent && null === $event->getPassword() && $this->tokenMock === $event->getPasswordToken())); } - $this->manager->resetPassword('email', 'foo@example.com'); + $this->manager->resetPassword('email', 'foo@example.com', $this->providerMock); } /** @@ -126,11 +123,9 @@ public function testResetPasswordWithExpiredPreviousToken(): void */ public function testResetPasswordWithUnexpiredTokenHttp(): void { - $this->providerChainMock->expects($this->once())->method('get')->willReturn($this->providerMock); $this->providerMock->expects($this->once())->method('getManager')->willReturn($this->managerMock); $this->providerMock->expects($this->once())->method('getUserClass')->willReturn(User::class); $this->tokenMock->expects($this->once())->method('isExpired')->willReturn(false); - $this->providerChainMock->expects($this->once())->method('get')->willReturn($this->providerMock); $this->managerMock->expects($this->once())->method('findOneBy')->with(User::class, ['email' => 'foo@example.com'])->willReturn($this->userMock); $this->passwordManagerMock->expects($this->once())->method('findOneByUser')->with($this->userMock, $this->providerMock)->willReturn($this->tokenMock); @@ -140,12 +135,11 @@ public function testResetPasswordWithUnexpiredTokenHttp(): void $this->eventDispatcherMock->expects($this->once())->method('dispatch')->with(ForgotPasswordEvent::CREATE_TOKEN, $this->callback(fn ($event) => $event instanceof CreateTokenEvent && null === $event->getPassword() && $this->tokenMock === $event->getPasswordToken())); } - $this->manager->resetPassword('email', 'foo@example.com'); + $this->manager->resetPassword('email', 'foo@example.com', $this->providerMock); } public function testUpdatePassword(): void { - $this->providerChainMock->expects($this->once())->method('get')->willReturn($this->providerMock); $this->providerMock->expects($this->once())->method('getManager')->willReturn($this->managerMock); if ($this->eventDispatcherMock instanceof ContractsEventDispatcherInterface) { @@ -155,6 +149,6 @@ public function testUpdatePassword(): void } $this->managerMock->expects($this->once())->method('remove')->with($this->tokenMock); - $this->manager->updatePassword($this->tokenMock, 'bar'); + $this->manager->updatePassword($this->tokenMock, 'bar', $this->providerMock); } } diff --git a/tests/Manager/PasswordTokenManagerTest.php b/tests/Manager/PasswordTokenManagerTest.php index c43dac9..21de648 100755 --- a/tests/Manager/PasswordTokenManagerTest.php +++ b/tests/Manager/PasswordTokenManagerTest.php @@ -57,12 +57,11 @@ public function testCreatePasswordToken(): void && '12345' === $object->getToken() && $this->userMock === $object->getUser())); - $this->providerChainMock->expects($this->once())->method('get')->willReturn($this->providerMock); $this->providerMock->expects($this->once())->method('getPasswordTokenClass')->willReturn(PasswordToken::class); $this->providerMock->expects($this->once())->method('getManager')->willReturn($this->managerMock); $this->tokenGeneratorMock->expects($this->once())->method('generate')->willReturn('12345'); - $this->manager->createPasswordToken($this->userMock, new \DateTime('2016-10-11 10:00:00')); + $this->manager->createPasswordToken($this->userMock, new \DateTime('2016-10-11 10:00:00'), $this->providerMock); } public function testCreatePasswordTokenWithoutExpirationDate(): void @@ -71,35 +70,32 @@ public function testCreatePasswordTokenWithoutExpirationDate(): void && '12345' === $object->getToken() && $this->userMock === $object->getUser())); - $this->providerChainMock->expects($this->once())->method('get')->willReturn($this->providerMock); $this->providerMock->expects($this->once())->method('getPasswordTokenClass')->willReturn(PasswordToken::class); $this->providerMock->expects($this->once())->method('getManager')->willReturn($this->managerMock); $this->tokenGeneratorMock->expects($this->once())->method('generate')->willReturn('12345'); - $this->manager->createPasswordToken($this->userMock); + $this->manager->createPasswordToken($this->userMock, null, $this->providerMock); } public function testFindOneByToken(): void { $this->managerMock->expects($this->once())->method('findOneBy')->with(PasswordToken::class, ['token' => 'foo'])->willReturn('bar'); - $this->providerChainMock->expects($this->once())->method('get')->willReturn($this->providerMock); $this->providerMock->expects($this->once())->method('getPasswordTokenClass')->willReturn(PasswordToken::class); $this->providerMock->expects($this->once())->method('getManager')->willReturn($this->managerMock); - $this->assertEquals('bar', $this->manager->findOneByToken('foo')); + $this->assertEquals('bar', $this->manager->findOneByToken('foo', $this->providerMock)); } public function testFindOneByUser(): void { $this->managerMock->expects($this->once())->method('findOneBy')->with(PasswordToken::class, ['user' => $this->userMock])->willReturn('bar'); - $this->providerChainMock->expects($this->once())->method('get')->willReturn($this->providerMock); $this->providerMock->expects($this->once())->method('getPasswordTokenClass')->willReturn(PasswordToken::class); $this->providerMock->expects($this->once())->method('getPasswordTokenUserField')->willReturn('user'); $this->providerMock->expects($this->once())->method('getManager')->willReturn($this->managerMock); - $this->assertEquals('bar', $this->manager->findOneByUser($this->userMock)); + $this->assertEquals('bar', $this->manager->findOneByUser($this->userMock, $this->providerMock)); } }