From 10e961304bd36adb5b8b9a78f2d7cac31bd67e70 Mon Sep 17 00:00:00 2001 From: Vincent <407859+vincentchalamon@users.noreply.github.com> Date: Tue, 14 Jan 2025 17:39:46 +0100 Subject: [PATCH] chore: remove deprecations (#149) --- composer.json | 2 +- config/services.xml | 2 -- features/app/AppKernel.php | 7 +---- features/bootstrap/FeatureContext.php | 24 ++++++++-------- phpunit-legacy.xml.dist | 2 +- .../OpenApi/AbstractOpenApiFactory.php | 4 +-- .../Serializer/DocumentationNormalizer.php | 4 +-- src/DependencyInjection/BCExtensionTrait.php | 19 +------------ src/Exception/InvalidJsonHttpException.php | 2 +- src/Exception/MissingFieldHttpException.php | 3 +- src/Exception/NoParameterException.php | 2 +- src/Exception/UnauthorizedFieldException.php | 2 +- src/Exception/UndefinedProviderException.php | 2 +- src/Manager/ForgotPasswordManager.php | 22 +++------------ src/Manager/PasswordTokenManager.php | 28 +++---------------- .../DocumentationNormalizerTest.php | 8 +++--- .../ExceptionEventListenerTest.php | 2 +- tests/Manager/ForgotPasswordManagerTest.php | 4 +-- tests/Manager/PasswordTokenManagerTest.php | 9 ++---- 19 files changed, 43 insertions(+), 105 deletions(-) diff --git a/composer.json b/composer.json index 2a878d1..331c650 100644 --- a/composer.json +++ b/composer.json @@ -51,7 +51,7 @@ "suggest": { "doctrine/doctrine-bundle": "To connect with Doctrine in Symfony project", "doctrine/orm": "To connect with Doctrine", - "api-platform/core": "To connect with API Platform" + "api-platform/openapi": "To connect with API Platform" }, "autoload": { "psr-4": { diff --git a/config/services.xml b/config/services.xml index e6f23dd..b00f9e8 100644 --- a/config/services.xml +++ b/config/services.xml @@ -25,11 +25,9 @@ - - diff --git a/features/app/AppKernel.php b/features/app/AppKernel.php index 4ec39b6..6457d2e 100644 --- a/features/app/AppKernel.php +++ b/features/app/AppKernel.php @@ -61,16 +61,11 @@ public function registerBundles(): array new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(), new FriendsOfBehat\SymfonyExtension\Bundle\FriendsOfBehatSymfonyExtensionBundle(), new CoopTilleuls\ForgotPasswordBundle\CoopTilleulsForgotPasswordBundle(), + new ApiPlatform\Symfony\Bundle\ApiPlatformBundle(), ]; if ('jmsserializer' === $this->getEnvironment()) { $bundles[] = new JMS\SerializerBundle\JMSSerializerBundle(); } - if (class_exists(ApiPlatform\Symfony\Bundle\ApiPlatformBundle::class)) { - $bundles[] = new ApiPlatform\Symfony\Bundle\ApiPlatformBundle(); - } else { - // BC api-platform/core:^2.7 - $bundles[] = new ApiPlatform\Core\Bridge\Symfony\Bundle\ApiPlatformBundle(); - } return $bundles; } diff --git a/features/bootstrap/FeatureContext.php b/features/bootstrap/FeatureContext.php index 6348eb6..ca8b4ed 100644 --- a/features/bootstrap/FeatureContext.php +++ b/features/bootstrap/FeatureContext.php @@ -71,7 +71,7 @@ public function resetDatabase(): void */ public function iHaveAValidToken(): void { - $this->passwordTokenManager->createPasswordToken($this->createUser(), new DateTime('+1 day')); + $this->passwordTokenManager->createPasswordToken($this->createUser(), $this->providerChain->get('user'), new DateTime('+1 day')); } /** @@ -79,7 +79,7 @@ public function iHaveAValidToken(): void */ public function iHaveAnExpiredToken(): void { - $this->passwordTokenManager->createPasswordToken($this->createUser(), new DateTime('-1 minute')); + $this->passwordTokenManager->createPasswordToken($this->createUser(), $this->providerChain->get('user'), new DateTime('-1 minute')); } /** @@ -166,7 +166,7 @@ public function theResponseShouldBeEmpty(): void public function theRequestShouldBeInvalidWithMessage($message): void { Assert::assertEquals( - 400, + 422, $this->client->getResponse()->getStatusCode(), sprintf('Response is not valid: got %d', $this->client->getResponse()->getStatusCode()) ); @@ -213,7 +213,7 @@ public function iResetMyPasswordUsingNoParameter(): void */ public function iUpdateMyPassword(): void { - $token = $this->passwordTokenManager->createPasswordToken($this->createUser(), new DateTime('+1 day')); + $token = $this->passwordTokenManager->createPasswordToken($this->createUser(), $this->providerChain->get('user'), new DateTime('+1 day')); $this->client->request( 'POST', @@ -246,7 +246,7 @@ public function thePasswordShouldHaveBeenUpdated(): void */ public function iUpdateMyPasswordUsingNoPassword(): void { - $token = $this->passwordTokenManager->createPasswordToken($this->createUser(), new DateTime('+1 day')); + $token = $this->passwordTokenManager->createPasswordToken($this->createUser(), $this->providerChain->get('user'), new DateTime('+1 day')); $this->client->request('POST', sprintf('/api/forgot-password/%s', $token->getToken())); } @@ -275,7 +275,7 @@ public function iUpdateMyPasswordUsingAnInvalidToken(): void */ public function iUpdateMyPasswordUsingWrongProvider(): void { - $token = $this->passwordTokenManager->createPasswordToken($this->createAdmin(), new DateTime('+1 day'), $this->providerChain->get('admin')); + $token = $this->passwordTokenManager->createPasswordToken($this->createAdmin(), $this->providerChain->get('admin'), new DateTime('+1 day')); $this->client->request( 'POST', @@ -296,7 +296,7 @@ public function iUpdateMyPasswordUsingWrongProvider(): void */ public function iUpdateMyPasswordUsingAValidProviderButAnInvalidPasswordField(): void { - $token = $this->passwordTokenManager->createPasswordToken($this->createAdmin(), new DateTime('+1 day'), $this->providerChain->get('admin')); + $token = $this->passwordTokenManager->createPasswordToken($this->createAdmin(), $this->providerChain->get('admin'), new DateTime('+1 day')); $this->client->request( 'POST', @@ -317,7 +317,7 @@ public function iUpdateMyPasswordUsingAValidProviderButAnInvalidPasswordField(): */ public function iUpdateMyPasswordUsingAnExpiredToken(): void { - $token = $this->passwordTokenManager->createPasswordToken($this->createUser(), new DateTime('-1 minute')); + $token = $this->passwordTokenManager->createPasswordToken($this->createUser(), $this->providerChain->get('user'), new DateTime('-1 minute')); $this->client->request( 'POST', @@ -338,7 +338,7 @@ public function iUpdateMyPasswordUsingAnExpiredToken(): void */ public function iGetAPasswordToken(): void { - $token = $this->passwordTokenManager->createPasswordToken($this->createUser(), new DateTime('+1 day')); + $token = $this->passwordTokenManager->createPasswordToken($this->createUser(), $this->providerChain->get('user'), new DateTime('+1 day')); $token->setToken('d7xtQlJVyN61TzWtrY6xy37zOxB66BqMSDXEbXBbo2Mw4Jjt9C'); $this->doctrine->getManager()->persist($token); $this->doctrine->getManager()->flush(); @@ -363,7 +363,7 @@ public function iShouldGetAPasswordToken(): void */ public function iGetAPasswordTokenUsingAnExpiredToken(): void { - $token = $this->passwordTokenManager->createPasswordToken($this->createUser(), new DateTime('-1 minute')); + $token = $this->passwordTokenManager->createPasswordToken($this->createUser(), $this->providerChain->get('user'), new DateTime('-1 minute')); $this->client->request('GET', sprintf('/api/forgot-password/%s', $token->getToken())); } @@ -472,7 +472,7 @@ private function getOpenApiPaths(): array 204 => [ 'description' => 'Valid email address, no matter if user exists or not', ], - 400 => [ + 422 => [ 'description' => 'Missing email parameter or invalid format', ], ], @@ -547,7 +547,7 @@ private function getOpenApiPaths(): array 204 => [ 'description' => 'Email address format valid, no matter if user exists or not', ], - 400 => [ + 422 => [ 'description' => 'Missing password parameter', ], 404 => [ diff --git a/phpunit-legacy.xml.dist b/phpunit-legacy.xml.dist index f0bdeab..bb0963f 100644 --- a/phpunit-legacy.xml.dist +++ b/phpunit-legacy.xml.dist @@ -23,7 +23,7 @@ - + src diff --git a/src/Bridge/ApiPlatform/OpenApi/AbstractOpenApiFactory.php b/src/Bridge/ApiPlatform/OpenApi/AbstractOpenApiFactory.php index 15d130f..e22bbcd 100644 --- a/src/Bridge/ApiPlatform/OpenApi/AbstractOpenApiFactory.php +++ b/src/Bridge/ApiPlatform/OpenApi/AbstractOpenApiFactory.php @@ -90,7 +90,7 @@ public function __invoke(array $context = []) 204 => [ 'description' => 'Valid email address, no matter if user exists or not', ], - 400 => [ + 422 => [ 'description' => 'Missing email parameter or invalid format', ], ]) @@ -174,7 +174,7 @@ public function __invoke(array $context = []) 204 => [ 'description' => 'Email address format valid, no matter if user exists or not', ], - 400 => [ + 422 => [ 'description' => 'Missing password parameter', ], 404 => [ diff --git a/src/Bridge/ApiPlatform/Serializer/DocumentationNormalizer.php b/src/Bridge/ApiPlatform/Serializer/DocumentationNormalizer.php index a0268ef..8f1ad6e 100644 --- a/src/Bridge/ApiPlatform/Serializer/DocumentationNormalizer.php +++ b/src/Bridge/ApiPlatform/Serializer/DocumentationNormalizer.php @@ -74,7 +74,7 @@ public function normalize($object, $format = null, array $context = []): array 204 => [ 'description' => 'Valid email address, no matter if user exists or not', ], - 400 => [ + 422 => [ 'description' => 'Missing email parameter or invalid format', ], ], @@ -146,7 +146,7 @@ public function normalize($object, $format = null, array $context = []): array 204 => [ 'description' => 'Email address format valid, no matter if user exists or not', ], - 400 => [ + 422 => [ 'description' => 'Missing password parameter', ], 404 => [ diff --git a/src/DependencyInjection/BCExtensionTrait.php b/src/DependencyInjection/BCExtensionTrait.php index a5ab545..42bcd41 100644 --- a/src/DependencyInjection/BCExtensionTrait.php +++ b/src/DependencyInjection/BCExtensionTrait.php @@ -37,23 +37,6 @@ public function load(array $configs, ContainerBuilder $container): void throw new InvalidConfigurationException('Multiple "ForgotPassword" providers have been defined but none of them is set as default. Did you forget to set "default" option?'); } - // Build parameters - $container->setParameter('coop_tilleuls_forgot_password.password_token_class', $defaultProvider['password_token']['class']); - trigger_deprecation('tilleuls/forgot-password-bundle', '1.5', 'Container parameter "%s" is deprecated since 1.5 and will be removed without replacement in 2.0.', 'coop_tilleuls_forgot_password.password_token_class'); - $container->setParameter('coop_tilleuls_forgot_password.password_token_expires_in', $defaultProvider['password_token']['expires_in']); - trigger_deprecation('tilleuls/forgot-password-bundle', '1.5', 'Container parameter "%s" is deprecated since 1.5 and will be removed without replacement in 2.0.', 'coop_tilleuls_forgot_password.password_token_expires_in'); - $container->setParameter('coop_tilleuls_forgot_password.password_token_user_field', $defaultProvider['password_token']['user_field']); - trigger_deprecation('tilleuls/forgot-password-bundle', '1.5', 'Container parameter "%s" is deprecated since 1.5 and will be removed without replacement in 2.0.', 'coop_tilleuls_forgot_password.password_token_user_field'); - $container->setParameter('coop_tilleuls_forgot_password.password_token_serialization_groups', $defaultProvider['password_token']['serialization_groups']); - trigger_deprecation('tilleuls/forgot-password-bundle', '1.5', 'Container parameter "%s" is deprecated since 1.5 and will be removed without replacement in 2.0.', 'coop_tilleuls_forgot_password.password_token_serialization_groups'); - $container->setParameter('coop_tilleuls_forgot_password.user_class', $defaultProvider['user']['class']); - trigger_deprecation('tilleuls/forgot-password-bundle', '1.5', 'Container parameter "%s" is deprecated since 1.5 and will be removed without replacement in 2.0.', 'coop_tilleuls_forgot_password.user_class'); - $authorizedFields = array_unique(array_merge($defaultProvider['user']['authorized_fields'], [$defaultProvider['user']['email_field']])); - $container->setParameter('coop_tilleuls_forgot_password.user_authorized_fields', $authorizedFields); - trigger_deprecation('tilleuls/forgot-password-bundle', '1.5', 'Container parameter "%s" is deprecated since 1.5 and will be removed without replacement in 2.0.', 'coop_tilleuls_forgot_password.user_authorized_fields'); - $container->setParameter('coop_tilleuls_forgot_password.user_password_field', $defaultProvider['user']['password_field']); - trigger_deprecation('tilleuls/forgot-password-bundle', '1.5', 'Container parameter "%s" is deprecated since 1.5 and will be removed without replacement in 2.0.', 'coop_tilleuls_forgot_password.user_password_field'); - $this->buildProvider($config, $container); $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../../config')); @@ -78,7 +61,7 @@ public function load(array $configs, ContainerBuilder $container): void $container ->getDefinition('coop_tilleuls_forgot_password.manager.password_token') - ->replaceArgument(1, new Reference($config['token_generator'])); + ->replaceArgument(0, new Reference($config['token_generator'])); } private function buildProvider(array $config, ContainerBuilder $container): void diff --git a/src/Exception/InvalidJsonHttpException.php b/src/Exception/InvalidJsonHttpException.php index a58e199..afc0453 100644 --- a/src/Exception/InvalidJsonHttpException.php +++ b/src/Exception/InvalidJsonHttpException.php @@ -19,6 +19,6 @@ final class InvalidJsonHttpException extends HttpException implements JsonHttpEx { public function __construct() { - parent::__construct(400, 'Invalid JSON data.'); + parent::__construct(422, 'Invalid JSON data.'); } } diff --git a/src/Exception/MissingFieldHttpException.php b/src/Exception/MissingFieldHttpException.php index 8e37987..1c893ce 100644 --- a/src/Exception/MissingFieldHttpException.php +++ b/src/Exception/MissingFieldHttpException.php @@ -22,7 +22,6 @@ final class MissingFieldHttpException extends HttpException implements JsonHttpE { public function __construct($fieldName) { - trigger_deprecation('tilleuls/forgot-password-bundle', '1.5', 'Status code will change to "%s" in 2.0.', 422); - parent::__construct(400, \sprintf('Parameter "%s" is missing.', $fieldName)); + parent::__construct(422, \sprintf('Parameter "%s" is missing.', $fieldName)); } } diff --git a/src/Exception/NoParameterException.php b/src/Exception/NoParameterException.php index 2b04f83..df160b3 100644 --- a/src/Exception/NoParameterException.php +++ b/src/Exception/NoParameterException.php @@ -19,6 +19,6 @@ final class NoParameterException extends HttpException implements JsonHttpExcept { public function __construct() { - parent::__construct(400, 'No parameter sent.'); + parent::__construct(422, 'No parameter sent.'); } } diff --git a/src/Exception/UnauthorizedFieldException.php b/src/Exception/UnauthorizedFieldException.php index b582ecf..fa35366 100644 --- a/src/Exception/UnauthorizedFieldException.php +++ b/src/Exception/UnauthorizedFieldException.php @@ -19,6 +19,6 @@ final class UnauthorizedFieldException extends HttpException implements JsonHttp { public function __construct($propertyName) { - parent::__construct(400, \sprintf('The parameter "%s" is not authorized in your configuration.', $propertyName)); + parent::__construct(422, \sprintf('The parameter "%s" is not authorized in your configuration.', $propertyName)); } } diff --git a/src/Exception/UndefinedProviderException.php b/src/Exception/UndefinedProviderException.php index 9619bc3..fdfb977 100644 --- a/src/Exception/UndefinedProviderException.php +++ b/src/Exception/UndefinedProviderException.php @@ -19,6 +19,6 @@ final class UndefinedProviderException extends HttpException implements JsonHttp { public function __construct(string $message = 'This provider is not defined.') { - parent::__construct(400, $message); + parent::__construct(422, $message); } } diff --git a/src/Manager/ForgotPasswordManager.php b/src/Manager/ForgotPasswordManager.php index 96437db..2346d84 100644 --- a/src/Manager/ForgotPasswordManager.php +++ b/src/Manager/ForgotPasswordManager.php @@ -18,8 +18,6 @@ use CoopTilleuls\ForgotPasswordBundle\Event\ForgotPasswordEvent; use CoopTilleuls\ForgotPasswordBundle\Event\UpdatePasswordEvent; use CoopTilleuls\ForgotPasswordBundle\Event\UserNotFoundEvent; -use CoopTilleuls\ForgotPasswordBundle\Provider\Provider; -use CoopTilleuls\ForgotPasswordBundle\Provider\ProviderChainInterface; use CoopTilleuls\ForgotPasswordBundle\Provider\ProviderInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Contracts\EventDispatcher\EventDispatcherInterface as ContractsEventDispatcherInterface; @@ -29,18 +27,12 @@ */ class ForgotPasswordManager { - public function __construct(private readonly PasswordTokenManager $passwordTokenManager, private readonly EventDispatcherInterface $dispatcher, private readonly ProviderChainInterface $providerChain) + public function __construct(private readonly PasswordTokenManager $passwordTokenManager, private readonly EventDispatcherInterface $dispatcher) { } - public function resetPassword($propertyName, $value, ?ProviderInterface $provider = null): void + public function resetPassword($propertyName, $value, ProviderInterface $provider): void { - /* @var null|Provider $provider */ - if (!$provider) { - trigger_deprecation('tilleuls/forgot-password-bundle', '1.5', 'Parameter "%s" in method "%s" is recommended since 1.5 and will be mandatory in 2.0.', '$provider', __METHOD__); - $provider = $this->providerChain->get(); - } - $context = [$propertyName => $value]; $user = $provider->getManager()->findOneBy($provider->getUserClass(), $context); @@ -62,7 +54,7 @@ public function resetPassword($propertyName, $value, ?ProviderInterface $provide $expiredAt = new \DateTime($provider->getPasswordTokenExpiredIn()); $expiredAt->setTime((int) $expiredAt->format('H'), (int) $expiredAt->format('i'), (int) $expiredAt->format('s'), 0); - $token = $this->passwordTokenManager->createPasswordToken($user, $expiredAt, $provider); + $token = $this->passwordTokenManager->createPasswordToken($user, $provider, $expiredAt); } // Generate password token @@ -78,14 +70,8 @@ public function resetPassword($propertyName, $value, ?ProviderInterface $provide * * @return bool */ - public function updatePassword(AbstractPasswordToken $passwordToken, $password, ?ProviderInterface $provider = null) + public function updatePassword(AbstractPasswordToken $passwordToken, $password, ProviderInterface $provider) { - /* @var null|Provider $provider */ - if (!$provider) { - trigger_deprecation('tilleuls/forgot-password-bundle', '1.5', 'Parameter "%s" in method "%s" is recommended since 1.5 and will be mandatory in 2.0.', '$provider', __METHOD__); - $provider = $this->providerChain->get(); - } - // Update user password if ($this->dispatcher instanceof ContractsEventDispatcherInterface) { $this->dispatcher->dispatch(new UpdatePasswordEvent($passwordToken, $password)); diff --git a/src/Manager/PasswordTokenManager.php b/src/Manager/PasswordTokenManager.php index 258c3ff..bd212bf 100644 --- a/src/Manager/PasswordTokenManager.php +++ b/src/Manager/PasswordTokenManager.php @@ -14,8 +14,6 @@ namespace CoopTilleuls\ForgotPasswordBundle\Manager; use CoopTilleuls\ForgotPasswordBundle\Entity\AbstractPasswordToken; -use CoopTilleuls\ForgotPasswordBundle\Provider\Provider; -use CoopTilleuls\ForgotPasswordBundle\Provider\ProviderChainInterface; use CoopTilleuls\ForgotPasswordBundle\Provider\ProviderInterface; use CoopTilleuls\ForgotPasswordBundle\TokenGenerator\TokenGeneratorInterface; @@ -24,21 +22,15 @@ */ class PasswordTokenManager { - public function __construct(private readonly ProviderChainInterface $providerChain, private readonly TokenGeneratorInterface $tokenGenerator) + public function __construct(private readonly TokenGeneratorInterface $tokenGenerator) { } /** * @return AbstractPasswordToken */ - public function createPasswordToken($user, ?\DateTime $expiresAt = null, ?ProviderInterface $provider = null) + public function createPasswordToken($user, ProviderInterface $provider, ?\DateTime $expiresAt = null) { - /* @var Provider $provider */ - if (!$provider) { - trigger_deprecation('tilleuls/forgot-password-bundle', '1.5', 'Parameter "%s" in method "%s" is recommended since 1.5 and will be mandatory in 2.0.', '$provider', __METHOD__); - $provider = $this->providerChain->get(); - } - if (!$expiresAt) { $expiresAt = new \DateTime($provider->getPasswordTokenExpiredIn()); $expiresAt->setTime((int) $expiresAt->format('H'), (int) $expiresAt->format('i'), (int) $expiresAt->format('s'), 0); @@ -61,28 +53,16 @@ public function createPasswordToken($user, ?\DateTime $expiresAt = null, ?Provid * * @return AbstractPasswordToken */ - public function findOneByToken($token, ?ProviderInterface $provider = null) + public function findOneByToken($token, ProviderInterface $provider) { - /* @var null|Provider $provider */ - if (!$provider) { - trigger_deprecation('tilleuls/forgot-password-bundle', '1.5', 'Parameter "%s" in method "%s" is recommended since 1.5 and will be mandatory in 2.0.', '$provider', __METHOD__); - $provider = $this->providerChain->get(); - } - return $provider->getManager()->findOneBy($provider->getPasswordTokenClass(), ['token' => $token]); } /** * @return AbstractPasswordToken */ - public function findOneByUser($user, ?ProviderInterface $provider = null) + public function findOneByUser($user, ProviderInterface $provider) { - /* @var null|Provider $provider */ - if (!$provider) { - trigger_deprecation('tilleuls/forgot-password-bundle', '1.5', 'Parameter "%s" in method "%s" is recommended since 1.5 and will be mandatory in 2.0.', '$provider', __METHOD__); - $provider = $this->providerChain->get(); - } - return $provider->getManager()->findOneBy($provider->getPasswordTokenClass(), [$provider->getPasswordTokenUserField() => $user]); } } diff --git a/tests/Bridge/ApiPlatform/Serializer/DocumentationNormalizerTest.php b/tests/Bridge/ApiPlatform/Serializer/DocumentationNormalizerTest.php index 6f9a7eb..edc1808 100755 --- a/tests/Bridge/ApiPlatform/Serializer/DocumentationNormalizerTest.php +++ b/tests/Bridge/ApiPlatform/Serializer/DocumentationNormalizerTest.php @@ -129,7 +129,7 @@ public function testItDecoratesNormalizedData(): void 204 => [ 'description' => 'Valid credentials', ], - 400 => [ + 422 => [ 'description' => 'Invalid credentials', ], ], @@ -176,7 +176,7 @@ public function testItDecoratesNormalizedData(): void 204 => [ 'description' => 'Valid credentials', ], - 400 => [ + 422 => [ 'description' => 'Invalid credentials', ], ], @@ -201,7 +201,7 @@ public function testItDecoratesNormalizedData(): void 204 => [ 'description' => 'Valid email address, no matter if user exists or not', ], - 400 => [ + 422 => [ 'description' => 'Missing email parameter or invalid format', ], ], @@ -264,7 +264,7 @@ public function testItDecoratesNormalizedData(): void 204 => [ 'description' => 'Email address format valid, no matter if user exists or not', ], - 400 => [ + 422 => [ 'description' => 'Missing password parameter', ], 404 => [ diff --git a/tests/EventListener/ExceptionEventListenerTest.php b/tests/EventListener/ExceptionEventListenerTest.php index d9614ea..c845688 100755 --- a/tests/EventListener/ExceptionEventListenerTest.php +++ b/tests/EventListener/ExceptionEventListenerTest.php @@ -90,7 +90,7 @@ public function testOnKernelException(): void ['message' => 'Parameter "foo" is missing.'], 15 ) === $response->getContent() - && 400 === $response->getStatusCode())); + && 422 === $response->getStatusCode())); $listener = new ExceptionEventListener(); $listener->onKernelException($eventMock); diff --git a/tests/Manager/ForgotPasswordManagerTest.php b/tests/Manager/ForgotPasswordManagerTest.php index 9930b1d..2e1d62a 100755 --- a/tests/Manager/ForgotPasswordManagerTest.php +++ b/tests/Manager/ForgotPasswordManagerTest.php @@ -88,7 +88,7 @@ public function testResetPasswordWithNoPreviousToken(): void $this->providerMock->expects($this->once())->method('getPasswordTokenExpiredIn')->willReturn('+1 day'); $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(null); - $this->passwordManagerMock->expects($this->once())->method('createPasswordToken')->with($this->userMock, $this->isInstanceOf(\DateTimeInterface::class), $this->providerMock)->willReturn($this->tokenMock); + $this->passwordManagerMock->expects($this->once())->method('createPasswordToken')->with($this->userMock, $this->providerMock, $this->isInstanceOf(\DateTimeInterface::class))->willReturn($this->tokenMock); if ($this->eventDispatcherMock instanceof ContractsEventDispatcherInterface) { $this->eventDispatcherMock->expects($this->once())->method('dispatch')->with($this->callback(fn ($event) => $event instanceof CreateTokenEvent && null === $event->getPassword() && $this->tokenMock === $event->getPasswordToken())); @@ -107,7 +107,7 @@ public function testResetPasswordWithExpiredPreviousToken(): void $this->tokenMock->expects($this->once())->method('isExpired')->willReturn(true); $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); - $this->passwordManagerMock->expects($this->once())->method('createPasswordToken')->with($this->userMock, $this->isInstanceOf(\DateTimeInterface::class), $this->providerMock)->willReturn($this->tokenMock); + $this->passwordManagerMock->expects($this->once())->method('createPasswordToken')->with($this->userMock, $this->providerMock, $this->isInstanceOf(\DateTimeInterface::class))->willReturn($this->tokenMock); if ($this->eventDispatcherMock instanceof ContractsEventDispatcherInterface) { $this->eventDispatcherMock->expects($this->once())->method('dispatch')->with($this->callback(fn ($event) => $event instanceof CreateTokenEvent && null === $event->getPassword() && $this->tokenMock === $event->getPasswordToken())); diff --git a/tests/Manager/PasswordTokenManagerTest.php b/tests/Manager/PasswordTokenManagerTest.php index 21de648..6ed685d 100755 --- a/tests/Manager/PasswordTokenManagerTest.php +++ b/tests/Manager/PasswordTokenManagerTest.php @@ -16,7 +16,6 @@ use CoopTilleuls\ForgotPasswordBundle\Entity\AbstractPasswordToken; use CoopTilleuls\ForgotPasswordBundle\Manager\Bridge\ManagerInterface; use CoopTilleuls\ForgotPasswordBundle\Manager\PasswordTokenManager; -use CoopTilleuls\ForgotPasswordBundle\Provider\ProviderChainInterface; use CoopTilleuls\ForgotPasswordBundle\Provider\ProviderInterface; use CoopTilleuls\ForgotPasswordBundle\TokenGenerator\TokenGeneratorInterface; use PHPUnit\Framework\TestCase; @@ -34,7 +33,6 @@ final class PasswordTokenManagerTest extends TestCase private $managerMock; private $userMock; private $tokenMock; - private $providerChainMock; private $providerMock; private $tokenGeneratorMock; @@ -43,11 +41,10 @@ protected function setUp(): void $this->managerMock = $this->createMock(ManagerInterface::class); $this->userMock = $this->createMock(UserInterface::class); $this->tokenMock = $this->createMock(AbstractPasswordToken::class); - $this->providerChainMock = $this->createMock(ProviderChainInterface::class); $this->providerMock = $this->createMock(ProviderInterface::class); $this->tokenGeneratorMock = $this->createMock(TokenGeneratorInterface::class); - $this->manager = new PasswordTokenManager($this->providerChainMock, $this->tokenGeneratorMock); + $this->manager = new PasswordTokenManager($this->tokenGeneratorMock); } public function testCreatePasswordToken(): void @@ -61,7 +58,7 @@ public function testCreatePasswordToken(): void $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->providerMock); + $this->manager->createPasswordToken($this->userMock, $this->providerMock, new \DateTime('2016-10-11 10:00:00')); } public function testCreatePasswordTokenWithoutExpirationDate(): void @@ -74,7 +71,7 @@ public function testCreatePasswordTokenWithoutExpirationDate(): void $this->providerMock->expects($this->once())->method('getManager')->willReturn($this->managerMock); $this->tokenGeneratorMock->expects($this->once())->method('generate')->willReturn('12345'); - $this->manager->createPasswordToken($this->userMock, null, $this->providerMock); + $this->manager->createPasswordToken($this->userMock, $this->providerMock); } public function testFindOneByToken(): void