Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[API][Order] Fixed wrong where condition when looking for order #11895

Merged
merged 3 commits into from
Nov 12, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[API][Order] Fixed wrong where condition when looking for order
  • Loading branch information
stloyd committed Nov 5, 2020
commit c0e5939388b0b5a8614852aa37c4f474f05118b7
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ private function applyUserRulesToItem(
$queryBuilder
->leftJoin(sprintf('%s.customer', $rootAlias), 'customer')
->leftJoin('customer.user', 'user')
->andWhere('user IS NULL')
->orWhere(sprintf('%s.customer IS NULL', $rootAlias))
->andWhere($queryBuilder->expr()->orX('user IS NULL', sprintf('%s.customer IS NULL', $rootAlias)))
->andWhere(sprintf('%s.state = :state', $rootAlias))
->setParameter('state', OrderInterface::STATE_CART)
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace spec\Sylius\Bundle\ApiBundle\Doctrine\QueryItemExtension;

use ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryNameGeneratorInterface;
use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\QueryBuilder;
use PhpSpec\ObjectBehavior;
use Sylius\Bundle\ApiBundle\Context\UserContextInterface;
Expand All @@ -35,7 +36,8 @@ function let(UserContextInterface $userContext): void
function it_applies_conditions_to_delete_order_with_state_cart_and_with_null_user_and_customer_if_present_user_and_customer_are_null(
UserContextInterface $userContext,
QueryBuilder $queryBuilder,
QueryNameGeneratorInterface $queryNameGenerator
QueryNameGeneratorInterface $queryNameGenerator,
Expr $expr
): void {
$queryBuilder->getRootAliases()->willReturn(['o']);

Expand All @@ -54,13 +56,18 @@ function it_applies_conditions_to_delete_order_with_state_cart_and_with_null_use
;

$queryBuilder
->andWhere('user IS NULL')
->expr()
->shouldBeCalled()
->willReturn($queryBuilder)
->willReturn($expr);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
->willReturn($expr);
->willReturn($expr)
;


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

$queryBuilder
->orWhere(sprintf('%s.customer IS NULL', 'o'))
->andWhere(sprintf('user IS NULL OR %s.customer IS NULL', 'o'))
->shouldBeCalled()
->willReturn($queryBuilder)
;
Expand Down Expand Up @@ -90,7 +97,8 @@ function it_applies_conditions_to_delete_order_with_state_cart_and_with_null_use
function it_applies_conditions_to_patch_order_with_state_cart_and_with_null_user_and_customer_if_present_user_and_customer_are_null(
UserContextInterface $userContext,
QueryBuilder $queryBuilder,
QueryNameGeneratorInterface $queryNameGenerator
QueryNameGeneratorInterface $queryNameGenerator,
Expr $expr
): void {
$queryBuilder->getRootAliases()->willReturn(['o']);

Expand All @@ -109,13 +117,18 @@ function it_applies_conditions_to_patch_order_with_state_cart_and_with_null_user
;

$queryBuilder
->andWhere('user IS NULL')
->expr()
->shouldBeCalled()
->willReturn($queryBuilder)
->willReturn($expr);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
->willReturn($expr);
->willReturn($expr)
;


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

$queryBuilder
->orWhere(sprintf('%s.customer IS NULL', 'o'))
->andWhere(sprintf('user IS NULL OR %s.customer IS NULL', 'o'))
->shouldBeCalled()
->willReturn($queryBuilder)
;
Expand Down Expand Up @@ -145,7 +158,8 @@ function it_applies_conditions_to_patch_order_with_state_cart_and_with_null_user
function it_applies_conditions_to_put_order_with_state_cart_and_with_null_user_and_customer_if_present_user_and_customer_are_null(
UserContextInterface $userContext,
QueryBuilder $queryBuilder,
QueryNameGeneratorInterface $queryNameGenerator
QueryNameGeneratorInterface $queryNameGenerator,
Expr $expr
): void {
$queryBuilder->getRootAliases()->willReturn(['o']);

Expand All @@ -164,13 +178,18 @@ function it_applies_conditions_to_put_order_with_state_cart_and_with_null_user_a
;

$queryBuilder
->andWhere('user IS NULL')
->expr()
->shouldBeCalled()
->willReturn($queryBuilder)
->willReturn($expr);

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

$queryBuilder
->orWhere(sprintf('%s.customer IS NULL', 'o'))
->andWhere(sprintf('user IS NULL OR %s.customer IS NULL', 'o'))
->shouldBeCalled()
->willReturn($queryBuilder)
;
Expand Down Expand Up @@ -217,6 +236,7 @@ function it_applies_conditions_to_put_order_with_state_cart_and_with_null_user_a
->shouldBeCalled()
->willReturn($queryBuilder)
;

$queryBuilder
->setParameter('customer', 1)
->shouldBeCalled()
Expand Down Expand Up @@ -313,6 +333,7 @@ function it_applies_conditions_to_delete_order_with_state_cart_and_with_null_use
->shouldBeCalled()
->willReturn($queryBuilder)
;

$queryBuilder
->setParameter('customer', 1)
->shouldBeCalled()
Expand Down Expand Up @@ -361,6 +382,7 @@ function it_applies_conditions_to_delete_order_with_state_cart_by_authorized_sho
->shouldBeCalled()
->willReturn($queryBuilder)
;

$queryBuilder
->setParameter('customer', 1)
->shouldBeCalled()
Expand Down Expand Up @@ -409,6 +431,7 @@ function it_applies_conditions_to_patch_order_with_state_cart_by_authorized_shop
->shouldBeCalled()
->willReturn($queryBuilder)
;

$queryBuilder
->setParameter('customer', 1)
->shouldBeCalled()
Expand Down Expand Up @@ -457,6 +480,7 @@ function it_applies_conditions_to_put_order_with_state_cart_by_authorized_shop_u
->shouldBeCalled()
->willReturn($queryBuilder)
;

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