Skip to content

Commit

Permalink
chore: update PHPUnit version
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentchalamon committed Jan 14, 2025
1 parent 052da93 commit beb5467
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 72 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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/simple-phpunit --colors=always --testdox -c ${{ matrix.phpunit }}
- name: Run Behat tests
run: |
mkdir -p features/app/cache/test/doctrine/orm/Proxies features/app/logs
Expand Down
14 changes: 2 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
Expand Down
10 changes: 0 additions & 10 deletions features/app/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
31 changes: 31 additions & 0 deletions phpunit-legacy.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="features/app/bootstrap.php"
failOnWarning="true"
failOnRisky="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerWarnings="true"
>
<php>
<ini name="display_errors" value="1" />
<ini name="error_reporting" value="-1" />
</php>

<testsuites>
<testsuite name="CoopTilleulsForgotPasswordBundle tests suite">
<directory>tests</directory>
</testsuite>
</testsuites>

<source ignoreSuppressionOfDeprecations="true" ignoreIndirectDeprecations="true">
<include>
<directory>src</directory>
</include>
</source>
</phpunit>
51 changes: 30 additions & 21 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" backupGlobals="false" colors="true" bootstrap="features/app/bootstrap.php">
<coverage>
<include>
<directory>src</directory>
</include>
<exclude>
<directory>tests</directory>
<directory>features</directory>
<directory>vendor</directory>
</exclude>
</coverage>
<php>
<ini name="error_reporting" value="-1"/>
<env name="SYMFONY_PHPUNIT_VERSION" value="9.5"/>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="disabled" />
</php>
<testsuites>
<testsuite name="CoopTilleulsForgotPasswordBundle tests suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="features/app/bootstrap.php"
failOnWarning="true"
failOnRisky="true"
failOnDeprecation="true"
failOnNotice="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerWarnings="true"
>
<php>
<ini name="display_errors" value="1" />
<ini name="error_reporting" value="-1" />
</php>

<testsuites>
<testsuite name="CoopTilleulsForgotPasswordBundle tests suite">
<directory>tests</directory>
</testsuite>
</testsuites>

<source ignoreSuppressionOfDeprecations="true" ignoreIndirectDeprecations="true">
<include>
<directory>src</directory>
</include>
</source>
</phpunit>
Original file line number Diff line number Diff line change
Expand Up @@ -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']],
Expand Down
10 changes: 5 additions & 5 deletions tests/EventListener/RequestEventListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
16 changes: 5 additions & 11 deletions tests/Manager/ForgotPasswordManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => '[email protected]']);
Expand All @@ -79,12 +78,11 @@ public function testResetPasswordNotUser(): void

$this->passwordManagerMock->expects($this->never())->method('findOneByUser')->with(self::any(), $this->providerMock);

$this->manager->resetPassword('email', '[email protected]');
$this->manager->resetPassword('email', '[email protected]', $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');
Expand All @@ -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', '[email protected]');
$this->manager->resetPassword('email', '[email protected]', $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');
Expand All @@ -118,19 +115,17 @@ 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', '[email protected]');
$this->manager->resetPassword('email', '[email protected]', $this->providerMock);
}

/**
* @see https://github.com/coopTilleuls/CoopTilleulsForgotPasswordBundle/issues/37
*/
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' => '[email protected]'])->willReturn($this->userMock);
$this->passwordManagerMock->expects($this->once())->method('findOneByUser')->with($this->userMock, $this->providerMock)->willReturn($this->tokenMock);

Expand All @@ -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', '[email protected]');
$this->manager->resetPassword('email', '[email protected]', $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) {
Expand All @@ -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);
}
}
12 changes: 4 additions & 8 deletions tests/Manager/PasswordTokenManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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));
}
}

Expand Down

0 comments on commit beb5467

Please sign in to comment.