Skip to content

Commit

Permalink
Renaming the exception
Browse files Browse the repository at this point in the history
  • Loading branch information
mamazu committed Nov 23, 2018
1 parent 2751cd3 commit 641bc40
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 11 deletions.
4 changes: 2 additions & 2 deletions spec/Handler/CompleteOrderHandlerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')])
;
}
Expand Down
9 changes: 3 additions & 6 deletions src/Controller/Checkout/CompleteOrderAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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',
Expand All @@ -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)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

use Exception;

class NotLoggedInException extends Exception
class WrongUserException extends Exception
{
}
4 changes: 2 additions & 2 deletions src/Handler/CompleteOrderHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 641bc40

Please sign in to comment.