From 5bc148c02feef799497d5251f84499c87ac88bbf Mon Sep 17 00:00:00 2001 From: arti0090 Date: Fri, 19 Feb 2021 09:24:31 +0100 Subject: [PATCH] add copyright blocks, add phpspec for handler, fix issues --- src/Sylius/Behat/Context/Api/EmailContext.php | 9 +++ .../Behat/Context/Api/Shop/LoginContext.php | 2 +- .../config/services/contexts/api.xml | 4 +- ...word.php => RequestResetPasswordToken.php} | 11 ++- .../Command/SendResetPasswordEmail.php | 9 +++ ...p => RequestResetPasswordTokenHandler.php} | 19 +++-- .../SendResetPasswordEmailHandler.php | 14 +++- .../Event/ResetPasswordRequested.php | 9 +++ .../ResetPasswordRequestedHandler.php | 12 +++- .../config/api_resources/Customer.xml | 6 +- .../Commands/Account/ResetPassword.xml | 4 +- .../config/services/command_handlers.xml | 2 +- .../config/validation/ResetPassword.xml | 2 +- .../SendResetPasswordEmailHandlerSpec.php | 71 +++++++++++++++++++ 14 files changed, 154 insertions(+), 20 deletions(-) rename src/Sylius/Bundle/ApiBundle/Command/{ResetPassword.php => RequestResetPasswordToken.php} (72%) rename src/Sylius/Bundle/ApiBundle/CommandHandler/{ResetPasswordHandler.php => RequestResetPasswordTokenHandler.php} (74%) create mode 100644 src/Sylius/Bundle/ApiBundle/spec/CommandHandler/SendResetPasswordEmailHandlerSpec.php diff --git a/src/Sylius/Behat/Context/Api/EmailContext.php b/src/Sylius/Behat/Context/Api/EmailContext.php index 2922ac8342f..4c68f30034a 100644 --- a/src/Sylius/Behat/Context/Api/EmailContext.php +++ b/src/Sylius/Behat/Context/Api/EmailContext.php @@ -1,5 +1,14 @@ request = Request::create('shop', 'password-reset-request', 'Bearer'); + $this->request = Request::create('shop', 'request-reset-password', 'Bearer'); } /** diff --git a/src/Sylius/Behat/Resources/config/services/contexts/api.xml b/src/Sylius/Behat/Resources/config/services/contexts/api.xml index 8c4266275f9..22594485204 100644 --- a/src/Sylius/Behat/Resources/config/services/contexts/api.xml +++ b/src/Sylius/Behat/Resources/config/services/contexts/api.xml @@ -16,8 +16,6 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd" > - - - + diff --git a/src/Sylius/Bundle/ApiBundle/Command/ResetPassword.php b/src/Sylius/Bundle/ApiBundle/Command/RequestResetPasswordToken.php similarity index 72% rename from src/Sylius/Bundle/ApiBundle/Command/ResetPassword.php rename to src/Sylius/Bundle/ApiBundle/Command/RequestResetPasswordToken.php index 3b2fd696673..9437cb6f8ae 100644 --- a/src/Sylius/Bundle/ApiBundle/Command/ResetPassword.php +++ b/src/Sylius/Bundle/ApiBundle/Command/RequestResetPasswordToken.php @@ -1,10 +1,19 @@ generator = $generator; } - public function __invoke(ResetPassword $command): void + public function __invoke(RequestResetPasswordToken $command): void { $user = $this->userRepository->findOneByEmail($command->getEmail()); Assert::notNull($user); @@ -43,7 +52,7 @@ public function __invoke(ResetPassword $command): void $this->eventBus->dispatch( new ResetPasswordRequested($command->getEmail(), $command->getChannelCode(), $command->getLocaleCode()), - [new DispatchAfterCurrentBusStamp() - ]); + [new DispatchAfterCurrentBusStamp()] + ); } } diff --git a/src/Sylius/Bundle/ApiBundle/CommandHandler/SendResetPasswordEmailHandler.php b/src/Sylius/Bundle/ApiBundle/CommandHandler/SendResetPasswordEmailHandler.php index 7457d4a1a5e..279ceaf480f 100644 --- a/src/Sylius/Bundle/ApiBundle/CommandHandler/SendResetPasswordEmailHandler.php +++ b/src/Sylius/Bundle/ApiBundle/CommandHandler/SendResetPasswordEmailHandler.php @@ -1,5 +1,14 @@ $user, 'localeCode' => $command->localeCode(), - 'channel' => $channel + 'channel' => $channel, ] ); } diff --git a/src/Sylius/Bundle/ApiBundle/Event/ResetPasswordRequested.php b/src/Sylius/Bundle/ApiBundle/Event/ResetPasswordRequested.php index dabb8814bef..bb55a654901 100644 --- a/src/Sylius/Bundle/ApiBundle/Event/ResetPasswordRequested.php +++ b/src/Sylius/Bundle/ApiBundle/Event/ResetPasswordRequested.php @@ -1,5 +1,14 @@ POST - shop/password-reset-request + shop/request-reset-password input - Sylius\Bundle\ApiBundle\Command\ResetPassword + Sylius\Bundle\ApiBundle\Command\RequestResetPasswordToken false 202 @@ -46,7 +46,7 @@ sylius_shop_password_reset - shop:customer:password_reset + shop:password_reset:create Request password reset diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/Commands/Account/ResetPassword.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/Commands/Account/ResetPassword.xml index a8f7f064269..194ac5cd5b9 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/Commands/Account/ResetPassword.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/Commands/Account/ResetPassword.xml @@ -17,10 +17,10 @@ > - shop:customer:password_reset + shop:password_reset:create - shop:customer:password_reset + shop:password_reset:create diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/services/command_handlers.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/services/command_handlers.xml index ac6bebaec18..531d285161e 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/services/command_handlers.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/services/command_handlers.xml @@ -102,7 +102,7 @@ - + diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/validation/ResetPassword.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/validation/ResetPassword.xml index 23ab56caa00..e22a04d6c04 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/validation/ResetPassword.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/validation/ResetPassword.xml @@ -15,7 +15,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/services/constraint-mapping-1.0.xsd"> - + diff --git a/src/Sylius/Bundle/ApiBundle/spec/CommandHandler/SendResetPasswordEmailHandlerSpec.php b/src/Sylius/Bundle/ApiBundle/spec/CommandHandler/SendResetPasswordEmailHandlerSpec.php new file mode 100644 index 00000000000..10ff2de8882 --- /dev/null +++ b/src/Sylius/Bundle/ApiBundle/spec/CommandHandler/SendResetPasswordEmailHandlerSpec.php @@ -0,0 +1,71 @@ +beConstructedWith($emailSender, $channelRepository, $userRepository); + } + + function it_is_a_message_handler(): void + { + $this->shouldImplement(MessageHandlerInterface::class); + } + + function it_sends_message_with_reset_password_token( + SenderInterface $sender, + UserRepositoryInterface $userRepository, + SendResetPasswordEmail $sendResetPasswordEmail, + UserInterface $user, + ChannelRepositoryInterface $channelRepository, + ChannelInterface $channel + ): void { + $sendResetPasswordEmail->email()->willReturn('iAmAnEmail@spaghettiCode.php'); + + $userRepository->findOneByEmail('iAmAnEmail@spaghettiCode.php')->willReturn($user); + + $sendResetPasswordEmail->channelCode()->willReturn('WEB'); + + $channelRepository->findOneByCode('WEB')->willReturn($channel); + + $sendResetPasswordEmail->localeCode()->willReturn('en_US'); + + $sender->send( + Emails::PASSWORD_RESET, + ['iAmAnEmail@spaghettiCode.php'], + [ + 'user' => $user->getWrappedObject(), + 'localeCode' => 'en_US', + 'channel' => $channel->getWrappedObject(), + ] + ); + + $this(new SendResetPasswordEmail('iAmAnEmail@spaghettiCode.php', 'WEB', 'en_US')); + } +}