From 641bc40e578e458cca0c1e9fbd285f25364c2a3c Mon Sep 17 00:00:00 2001 From: mamazu Date: Fri, 23 Nov 2018 16:57:17 +0100 Subject: [PATCH] Renaming the exception --- spec/Handler/CompleteOrderHandlerSpec.php | 4 ++-- src/Controller/Checkout/CompleteOrderAction.php | 9 +++------ .../{NotLoggedInException.php => WrongUserException.php} | 2 +- src/Handler/CompleteOrderHandler.php | 4 ++-- 4 files changed, 8 insertions(+), 11 deletions(-) rename src/Exception/{NotLoggedInException.php => WrongUserException.php} (68%) diff --git a/spec/Handler/CompleteOrderHandlerSpec.php b/spec/Handler/CompleteOrderHandlerSpec.php index 4a0f15b62..c957c2a05 100644 --- a/spec/Handler/CompleteOrderHandlerSpec.php +++ b/spec/Handler/CompleteOrderHandlerSpec.php @@ -15,7 +15,7 @@ use Sylius\Component\Core\Repository\OrderRepositoryInterface; use Sylius\Component\Resource\Factory\FactoryInterface; use Sylius\ShopApiPlugin\Command\CompleteOrder; -use Sylius\ShopApiPlugin\Exception\NotLoggedInException; +use Sylius\ShopApiPlugin\Exception\WrongUserException; use Sylius\ShopApiPlugin\Provider\LoggedInUserProviderInterface; final class CompleteOrderHandlerSpec extends ObjectBehavior @@ -139,7 +139,7 @@ function it_throws_an_exception_if_the_user_is_not_logged_in( $order->setCustomer($customer)->shouldNotBeCalled(); $stateMachine->apply('complete')->shouldNotBeCalled(); - $this->shouldThrow(NotLoggedInException::class) + $this->shouldThrow(WrongUserException::class) ->during('handle', [new CompleteOrder('ORDERTOKEN', 'example@customer.com', 'Some notes')]) ; } diff --git a/src/Controller/Checkout/CompleteOrderAction.php b/src/Controller/Checkout/CompleteOrderAction.php index ddd95292f..5366d570a 100644 --- a/src/Controller/Checkout/CompleteOrderAction.php +++ b/src/Controller/Checkout/CompleteOrderAction.php @@ -8,7 +8,7 @@ use FOS\RestBundle\View\ViewHandlerInterface; use League\Tactician\CommandBus; use Sylius\ShopApiPlugin\Command\CompleteOrder; -use Sylius\ShopApiPlugin\Exception\NotLoggedInException; +use Sylius\ShopApiPlugin\Exception\WrongUserException; use Sylius\ShopApiPlugin\Provider\LoggedInUserProviderInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -47,7 +47,7 @@ public function __invoke(Request $request): Response $request->request->get('notes') ) ); - } catch (NotLoggedInException $notLoggedInException) { + } catch (WrongUserException $notLoggedInException) { return $this->viewHandler->handle( View::create( 'You need to be logged in with the same user that wants to complete the order', @@ -56,10 +56,7 @@ public function __invoke(Request $request): Response ); } catch (TokenNotFoundException $notLoggedInException) { return $this->viewHandler->handle( - View::create( - 'You need to be logged in with the same user that wants to complete the order', - Response::HTTP_UNAUTHORIZED - ) + View::create('You need to be logged in', Response::HTTP_UNAUTHORIZED) ); } diff --git a/src/Exception/NotLoggedInException.php b/src/Exception/WrongUserException.php similarity index 68% rename from src/Exception/NotLoggedInException.php rename to src/Exception/WrongUserException.php index a2d857419..6522443ed 100644 --- a/src/Exception/NotLoggedInException.php +++ b/src/Exception/WrongUserException.php @@ -6,6 +6,6 @@ use Exception; -class NotLoggedInException extends Exception +class WrongUserException extends Exception { } diff --git a/src/Handler/CompleteOrderHandler.php b/src/Handler/CompleteOrderHandler.php index d2fc76f17..638d74301 100644 --- a/src/Handler/CompleteOrderHandler.php +++ b/src/Handler/CompleteOrderHandler.php @@ -12,7 +12,7 @@ use Sylius\Component\Core\Repository\OrderRepositoryInterface; use Sylius\Component\Resource\Factory\FactoryInterface; use Sylius\ShopApiPlugin\Command\CompleteOrder; -use Sylius\ShopApiPlugin\Exception\NotLoggedInException; +use Sylius\ShopApiPlugin\Exception\WrongUserException; use Sylius\ShopApiPlugin\Provider\LoggedInUserProviderInterface; use Webmozart\Assert\Assert; @@ -83,7 +83,7 @@ private function getCustomer(string $emailAddress): CustomerInterface $loggedInUser = $this->loggedInUserProvider->provide(); if ($loggedInUser->getCustomer() !== $customer) { - throw new NotLoggedInException(); + throw new WrongUserException(); } return $customer;