diff --git a/src/Sylius/Behat/Client/ApiPlatformSecurityClient.php b/src/Sylius/Behat/Client/ApiPlatformSecurityClient.php
index 6a4f7540792..a08f5a42970 100644
--- a/src/Sylius/Behat/Client/ApiPlatformSecurityClient.php
+++ b/src/Sylius/Behat/Client/ApiPlatformSecurityClient.php
@@ -44,12 +44,6 @@ public function prepareLoginRequest(): void
$this->request['method'] = 'POST';
}
- public function preparePasswordResetRequest(): void
- {
- $this->request['url'] = sprintf('/api/v2/%s/password-reset-request', $this->section);
- $this->request['method'] = 'POST';
- }
-
public function setEmail(string $email): void
{
$this->request['body']['email'] = $email;
@@ -62,7 +56,14 @@ public function setPassword(string $password): void
public function call(): void
{
- $this->callRequest();
+ $this->client->request(
+ $this->request['method'],
+ $this->request['url'],
+ [],
+ [],
+ ['CONTENT_TYPE' => 'application/json', 'HTTP_ACCEPT' => 'application/json'],
+ json_encode($this->request['body'])
+ );
$response = $this->client->getResponse();
$content = json_decode($response->getContent(), true);
@@ -96,26 +97,4 @@ public function logOut(): void
$this->sharedStorage->set('cart_token', null);
}
}
-
- public function resetPassword(): void
- {
- $this->callRequest();
- }
-
- private function callRequest(): void
- {
- $this->client->request(
- $this->request['method'],
- $this->request['url'],
- [],
- [],
- ['CONTENT_TYPE' => 'application/json', 'HTTP_ACCEPT' => 'application/json'],
- json_encode($this->request['body'])
- );
- }
-
- public function getLastResponse(): Response
- {
- return $this->client->getResponse();
- }
}
diff --git a/src/Sylius/Behat/Client/ApiSecurityClientInterface.php b/src/Sylius/Behat/Client/ApiSecurityClientInterface.php
index fac37d4de78..a570ea75388 100644
--- a/src/Sylius/Behat/Client/ApiSecurityClientInterface.php
+++ b/src/Sylius/Behat/Client/ApiSecurityClientInterface.php
@@ -19,8 +19,6 @@ interface ApiSecurityClientInterface
{
public function prepareLoginRequest(): void;
- public function preparePasswordResetRequest(): void;
-
public function setEmail(string $email): void;
public function setPassword(string $password): void;
@@ -32,8 +30,4 @@ public function isLoggedIn(): bool;
public function getErrorMessage(): string;
public function logOut(): void;
-
- public function resetPassword(): void;
-
- public function getLastResponse(): Response;
}
diff --git a/src/Sylius/Behat/Context/Api/EmailContext.php b/src/Sylius/Behat/Context/Api/EmailContext.php
index f142ec9d3c6..2922ac8342f 100644
--- a/src/Sylius/Behat/Context/Api/EmailContext.php
+++ b/src/Sylius/Behat/Context/Api/EmailContext.php
@@ -17,10 +17,8 @@ class EmailContext implements Context
/** @var TranslatorInterface */
private $translator;
- public function __construct(
- EmailCheckerInterface $emailChecker,
- TranslatorInterface $translator
- ) {
+ public function __construct(EmailCheckerInterface $emailChecker, TranslatorInterface $translator)
+ {
$this->emailChecker = $emailChecker;
$this->translator = $translator;
}
diff --git a/src/Sylius/Behat/Context/Api/Shop/LoginContext.php b/src/Sylius/Behat/Context/Api/Shop/LoginContext.php
index 80a227ba144..c2c7316ed18 100644
--- a/src/Sylius/Behat/Context/Api/Shop/LoginContext.php
+++ b/src/Sylius/Behat/Context/Api/Shop/LoginContext.php
@@ -14,14 +14,23 @@
namespace Sylius\Behat\Context\Api\Shop;
use Behat\Behat\Context\Context;
+use Sylius\Behat\Client\ApiClientInterface;
use Sylius\Behat\Client\ApiSecurityClientInterface;
+use Sylius\Behat\Client\Request;
use Webmozart\Assert\Assert;
+use \Symfony\Component\HttpFoundation\Request as HTTPRequest;
final class LoginContext implements Context
{
/** @var ApiSecurityClientInterface */
private $client;
+ /** @var ApiClientInterface */
+ private $apiClient;
+
+ /** @var Request */
+ private $request;
+
public function __construct(ApiSecurityClientInterface $client)
{
$this->client = $client;
@@ -48,7 +57,7 @@ public function iWantToLogIn(): void
*/
public function iWantToResetPassword(): void
{
- $this->client->preparePasswordResetRequest();
+ $this->request = Request::custom('shop/password-reset-request', HTTPRequest::METHOD_POST);
}
/**
@@ -56,18 +65,25 @@ public function iWantToResetPassword(): void
*/
public function iResetIt(): void
{
- $this->client->resetPassword();
+ $this->apiClient->executeCustomRequest($this->request);
}
/**
* @When I specify the username as :username
- * @When I specify the email as :username
*/
public function iSpecifyTheUsername(string $username): void
{
$this->client->setEmail($username);
}
+ /**
+ * @When I specify the email as :email
+ */
+ public function iSpecifyTheEmail(string $email): void
+ {
+ $this->request->setContent(['email' => $email]);
+ }
+
/**
* @When I specify the password as :password
*/
diff --git a/src/Sylius/Behat/Resources/config/services/contexts/api/shop.xml b/src/Sylius/Behat/Resources/config/services/contexts/api/shop.xml
index 90d3a893771..45f46cbba1e 100644
--- a/src/Sylius/Behat/Resources/config/services/contexts/api/shop.xml
+++ b/src/Sylius/Behat/Resources/config/services/contexts/api/shop.xml
@@ -74,6 +74,7 @@
+
diff --git a/src/Sylius/Bundle/ApiBundle/Command/ResetPasswordRequest.php b/src/Sylius/Bundle/ApiBundle/Command/ResetPassword.php
similarity index 90%
rename from src/Sylius/Bundle/ApiBundle/Command/ResetPasswordRequest.php
rename to src/Sylius/Bundle/ApiBundle/Command/ResetPassword.php
index 5a5250846ec..3b2fd696673 100644
--- a/src/Sylius/Bundle/ApiBundle/Command/ResetPasswordRequest.php
+++ b/src/Sylius/Bundle/ApiBundle/Command/ResetPassword.php
@@ -4,7 +4,7 @@
namespace Sylius\Bundle\ApiBundle\Command;
-class ResetPasswordRequest implements ChannelCodeAwareInterface, LocaleCodeAwareInterface
+class ResetPassword implements ChannelCodeAwareInterface, LocaleCodeAwareInterface
{
/** @var string */
public $email;
diff --git a/src/Sylius/Bundle/ApiBundle/CommandHandler/ResetPasswordRequestHandler.php b/src/Sylius/Bundle/ApiBundle/CommandHandler/ResetPasswordHandler.php
similarity index 89%
rename from src/Sylius/Bundle/ApiBundle/CommandHandler/ResetPasswordRequestHandler.php
rename to src/Sylius/Bundle/ApiBundle/CommandHandler/ResetPasswordHandler.php
index 3d007110394..d241786b672 100644
--- a/src/Sylius/Bundle/ApiBundle/CommandHandler/ResetPasswordRequestHandler.php
+++ b/src/Sylius/Bundle/ApiBundle/CommandHandler/ResetPasswordHandler.php
@@ -4,7 +4,7 @@
namespace Sylius\Bundle\ApiBundle\CommandHandler;
-use Sylius\Bundle\ApiBundle\Command\ResetPasswordRequest;
+use Sylius\Bundle\ApiBundle\Command\ResetPassword;
use Sylius\Bundle\ApiBundle\Event\ResetPasswordRequested;
use Sylius\Component\User\Repository\UserRepositoryInterface;
use Sylius\Component\User\Security\Generator\GeneratorInterface;
@@ -12,7 +12,7 @@
use Symfony\Component\Messenger\Stamp\DispatchAfterCurrentBusStamp;
use Webmozart\Assert\Assert;
-class ResetPasswordRequestHandler
+class ResetPasswordHandler
{
/** @var UserRepositoryInterface */
private $userRepository;
@@ -33,7 +33,7 @@ public function __construct(
$this->generator = $generator;
}
- public function __invoke(ResetPasswordRequest $command): void
+ public function __invoke(ResetPassword $command): void
{
$user = $this->userRepository->findOneByEmail($command->getEmail());
Assert::notNull($user);
@@ -45,7 +45,5 @@ public function __invoke(ResetPasswordRequest $command): void
new ResetPasswordRequested($command->getEmail(), $command->getChannelCode(), $command->getLocaleCode()),
[new DispatchAfterCurrentBusStamp()
]);
-
-
}
}
diff --git a/src/Sylius/Bundle/ApiBundle/Event/ResetPasswordRequested.php b/src/Sylius/Bundle/ApiBundle/Event/ResetPasswordRequested.php
index cebc00a9243..dabb8814bef 100644
--- a/src/Sylius/Bundle/ApiBundle/Event/ResetPasswordRequested.php
+++ b/src/Sylius/Bundle/ApiBundle/Event/ResetPasswordRequested.php
@@ -13,7 +13,7 @@ class ResetPasswordRequested
private $channelCode;
/** @var string */
- private $localeCode;
+ protected $localeCode;
public function __construct(
string $email,
diff --git a/src/Sylius/Bundle/ApiBundle/EventHandler/ResetPasswordRequestedHandler.php b/src/Sylius/Bundle/ApiBundle/EventHandler/ResetPasswordRequestedHandler.php
index ee21ebfca40..c2cc5171a95 100644
--- a/src/Sylius/Bundle/ApiBundle/EventHandler/ResetPasswordRequestedHandler.php
+++ b/src/Sylius/Bundle/ApiBundle/EventHandler/ResetPasswordRequestedHandler.php
@@ -22,7 +22,7 @@ public function __invoke(ResetPasswordRequested $resetPasswordRequested): void
{
$this->commandBus->dispatch(
new SendResetPasswordEmail(
- $resetPasswordRequested->email,
+ $resetPasswordRequested->email(),
$resetPasswordRequested->channelCode(),
$resetPasswordRequested->localeCode()
)
diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/api_resources/Customer.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/api_resources/Customer.xml
index a4279b8058b..d766585f62d 100644
--- a/src/Sylius/Bundle/ApiBundle/Resources/config/api_resources/Customer.xml
+++ b/src/Sylius/Bundle/ApiBundle/Resources/config/api_resources/Customer.xml
@@ -33,6 +33,25 @@
Sylius\Bundle\ApiBundle\Command\RegisterShopUser
false
+
+
+ POST
+ shop/password-reset-request
+ input
+ Sylius\Bundle\ApiBundle\Command\ResetPasswordRequest
+ false
+ 202
+
+ sylius
+ sylius_shop_password_reset
+
+
+ shop:shop_user:password_reset
+
+
+ Request password reset
+
+
diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/api_resources/ShopUser.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/api_resources/ShopUser.xml
deleted file mode 100644
index d3f79f13150..00000000000
--- a/src/Sylius/Bundle/ApiBundle/Resources/config/api_resources/ShopUser.xml
+++ /dev/null
@@ -1,45 +0,0 @@
-
-
-
-
-
-
- sylius
-
-
-
- POST
- shop/password-reset-request
- input
- Sylius\Bundle\ApiBundle\Command\ResetPasswordRequest
- false
- 202
-
- sylius
- sylius_shop_password_reset
-
-
- shop:shop_user:password_reset
-
-
- Request password reset
-
-
-
-
-
-
-
-
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 46747cd6a15..a50dc3c09e2 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 @@
-
+