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 12, 2021
1 parent 9b466a1 commit f6816bd
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 30 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 composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"ext-exif": "*",
"ext-fileinfo": "*",
"ext-gd": "*",
"api-platform/core": "^2.5",
"api-platform/core": "^2.6",
"babdev/pagerfanta-bundle": "^2.5",
"behat/transliterator": "^1.3",
"doctrine/collections": "^1.6",
Expand Down
7 changes: 4 additions & 3 deletions src/Sylius/Behat/Context/Api/Shop/AddressContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,10 @@ public function iShouldBeNotifiedAboutErrors(int $expectedCount): void
*/
public function iShouldBeNotifiedThatTheProvinceNeedsToBeSpecified(): void
{
$response = $this->responseChecker->getResponseContent($this->addressClient->getLastResponse());

Assert::same('Please select proper province.', $response['violations'][0]['message']);
Assert::true($this->responseChecker->hasViolationWithMessage(
$this->addressClient->getLastResponse(),
'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
2 changes: 1 addition & 1 deletion src/Sylius/Bundle/ApiBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
],
"require": {
"php": "^7.4",
"api-platform/core": "^2.5",
"api-platform/core": "^2.6",
"lexik/jwt-authentication-bundle": "^2.6",
"sylius/core-bundle": "^1.7",
"symfony/messenger": "^4.4 || ^5.2"
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 f6816bd

Please sign in to comment.