Skip to content

Commit

Permalink
Fix TokenValueBasedCartContext and add last fixes for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomanhez committed Apr 9, 2021
1 parent 9b466a1 commit ba50004
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 26 deletions.
2 changes: 1 addition & 1 deletion UPGRADE-1.10.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@

- `product_review:update` changed to: `admin:product_review:update` and `shop:product_review:update`

1. We've removed `Sylius\Bundle\ApiBundle\ApiPlatform\Bridge\Doctrine\ORM\SubresourceDataProvider` is not longer needed because `ApiPlatform\Core\Bridge\Doctrine\Orm\SubresourceDataProvider` is the same file.
1. We've removed `Sylius\Bundle\ApiBundle\ApiPlatform\Bridge\Doctrine\ORM\SubresourceDataProvider`. It's no longer needed because `ApiPlatform\Core\Bridge\Doctrine\Orm\SubresourceDataProvider` has the same logic.
2 changes: 1 addition & 1 deletion src/Sylius/Behat/Context/Api/Shop/AddressContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ public function iShouldBeNotifiedThatTheProvinceNeedsToBeSpecified(): void
{
$response = $this->responseChecker->getResponseContent($this->addressClient->getLastResponse());

Assert::same('Please select proper province.', $response['violations'][0]['message']);
Assert::same($response['violations'][0]['message'], 'Please select proper province.');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function getCart(): OrderInterface
$request = $this->getMasterRequest();
$this->checkApiRequest($request);

$tokenValue = $request->attributes->get('id');
$tokenValue = $request->attributes->get('tokenValue');
if ($tokenValue === null) {
throw new CartNotFoundException('Sylius was not able to find the cart, as there is no passed token value.');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,7 @@ private function applyToItemForGetMethod(

if ($user instanceof ShopUserInterface && in_array('ROLE_USER', $user->getRoles(), true)) {
$queryBuilder
->andWhere($queryBuilder->expr()->orX(
sprintf('%s.customer = :customer', $rootAlias),
sprintf('%s.customer IS NULL', $rootAlias))
)
->andWhere(sprintf('%s.customer = :customer', $rootAlias))
->setParameter('customer', $user->getCustomer()->getId())
;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function it_returns_cart_by_token_value(
Request $request,
OrderInterface $cart
): void {
$request->attributes = new ParameterBag(['id' => 'TOKEN_VALUE']);
$request->attributes = new ParameterBag(['tokenValue' => 'TOKEN_VALUE']);
$request->getRequestUri()->willReturn('/api/v2/orders/TOKEN_VALUE');

$requestStack->getMasterRequest()->willReturn($request);
Expand Down Expand Up @@ -94,7 +94,7 @@ function it_throws_an_exception_if_there_is_no_cart_with_given_token_value(
OrderRepositoryInterface $orderRepository,
Request $request
): void {
$request->attributes = new ParameterBag(['id' => 'TOKEN_VALUE']);
$request->attributes = new ParameterBag(['tokenValue' => 'TOKEN_VALUE']);
$request->getRequestUri()->willReturn('/api/v2/orders/TOKEN_VALUE');

$requestStack->getMasterRequest()->willReturn($request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,12 @@ function it_applies_conditions_to_get_order_with_state_cart_and_without_user_if_
);
}

function it_applies_conditions_to_get_order_with_state_cart_by_authorized_shop_user_that_is_assigns_to_this_order_or_order_with_state_cart_has_not_assigned_customer(
function it_applies_conditions_to_get_order_with_state_cart_by_authorized_shop_user_that_is_assigns_to_this_order(
UserContextInterface $userContext,
QueryBuilder $queryBuilder,
ShopUserInterface $shopUser,
CustomerInterface $customer,
QueryNameGeneratorInterface $queryNameGenerator,
Expr $expr
QueryNameGeneratorInterface $queryNameGenerator
): void {
$queryBuilder->getRootAliases()->willReturn(['o']);

Expand All @@ -98,22 +97,10 @@ function it_applies_conditions_to_get_order_with_state_cart_by_authorized_shop_u
$shopUser->getRoles()->willReturn(['ROLE_USER']);

$queryBuilder
->expr()
->shouldBeCalled()
->willReturn($expr);

$expr
->orX(sprintf('%s.customer = :customer', 'o'), sprintf('%s.customer IS NULL', 'o'))
->shouldBeCalled()
->willReturn(sprintf('%s.customer = :customer OR %s.customer IS NULL', 'o', 'o'))
;

$queryBuilder
->andWhere(sprintf('%s.customer = :customer OR %s.customer IS NULL', 'o', 'o'))
->andWhere(sprintf('%s.customer = :customer', 'o'))
->shouldBeCalled()
->willReturn($queryBuilder)
;

;
$queryBuilder
->setParameter('customer', 1)
->shouldBeCalled()
Expand Down

0 comments on commit ba50004

Please sign in to comment.