From cb7326020f12bd75a5516c5e9553e190eb7363b2 Mon Sep 17 00:00:00 2001 From: mamazu <14860264+mamazu@users.noreply.github.com> Date: Tue, 7 May 2019 16:43:37 +0200 Subject: [PATCH] Adding tests back in --- .../Cart/CartViewRepositorySpec.php | 39 +++++++++++++++++++ .../Cart/CartViewRepository.php | 9 +---- 2 files changed, 41 insertions(+), 7 deletions(-) create mode 100644 spec/ViewRepository/Cart/CartViewRepositorySpec.php diff --git a/spec/ViewRepository/Cart/CartViewRepositorySpec.php b/spec/ViewRepository/Cart/CartViewRepositorySpec.php new file mode 100644 index 000000000..909d29814 --- /dev/null +++ b/spec/ViewRepository/Cart/CartViewRepositorySpec.php @@ -0,0 +1,39 @@ +beConstructedWith($cartRepository, $cartViewFactory); + } + + function it_is_cart_query(): void + { + $this->shouldImplement(CartViewRepositoryInterface::class); + } + + function it_provides_cart_view( + OrderRepositoryInterface $cartRepository, + CartViewFactoryInterface $cartViewFactory, + OrderInterface $cart, + CartSummaryView $cartView + ): void { + $cartRepository->findOneBy(['tokenValue' => 'ORDERTOKEN', 'state' => 'cart'])->willReturn($cart); + $cart->getLocaleCode()->willReturn('en_GB'); + + $cartViewFactory->create($cart, 'en_GB')->willReturn($cartView); + + $this->getOneByToken('ORDERTOKEN')->shouldReturn($cartView); + } +} diff --git a/src/ViewRepository/Cart/CartViewRepository.php b/src/ViewRepository/Cart/CartViewRepository.php index 5dea01085..e41c4f327 100644 --- a/src/ViewRepository/Cart/CartViewRepository.php +++ b/src/ViewRepository/Cart/CartViewRepository.php @@ -29,13 +29,8 @@ public function __construct( public function getOneByToken(string $token): CartSummaryView { - /** @var OrderInterface $cart */ - $cart = $this->cartRepository->createCartQueryBuilder() - ->andWhere('o.tokenValue = :tokenValue') - ->setParameter('tokenValue', $token) - ->getQuery() - ->getOneOrNullResult(); - + /** @var OrderInterface|null $cart */ + $cart = $this->cartRepository->findOneBy(['tokenValue' => $token, 'state' => OrderInterface::STATE_CART]); Assert::notNull($cart, 'Cart with given id does not exists'); return $this->cartViewFactory->create($cart, $cart->getLocaleCode());