Skip to content

Commit

Permalink
Adding tests back in
Browse files Browse the repository at this point in the history
  • Loading branch information
mamazu committed May 7, 2019
1 parent 9d829c1 commit cb73260
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
39 changes: 39 additions & 0 deletions spec/ViewRepository/Cart/CartViewRepositorySpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

namespace spec\Sylius\ShopApiPlugin\ViewRepository\Cart;

use PhpSpec\ObjectBehavior;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Repository\OrderRepositoryInterface;
use Sylius\ShopApiPlugin\Factory\Cart\CartViewFactoryInterface;
use Sylius\ShopApiPlugin\View\Cart\CartSummaryView;
use Sylius\ShopApiPlugin\ViewRepository\Cart\CartViewRepositoryInterface;

final class CartViewRepositorySpec extends ObjectBehavior
{
function let(OrderRepositoryInterface $cartRepository, CartViewFactoryInterface $cartViewFactory): void
{
$this->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);
}
}
9 changes: 2 additions & 7 deletions src/ViewRepository/Cart/CartViewRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit cb73260

Please sign in to comment.