Skip to content

Commit

Permalink
Rename CartEmpty constraint and validator to CartNotEmpty
Browse files Browse the repository at this point in the history
  • Loading branch information
Nenad Stefanovic authored and Nenad Stefanovic committed Dec 9, 2020
1 parent 7a49242 commit bc22fa8
Show file tree
Hide file tree
Showing 20 changed files with 27 additions and 57 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"license": "MIT",
"require": {
"php": "^7.3",
"sylius/sylius": "^1.8",
"sylius/sylius": "^1.7",
"lexik/jwt-authentication-bundle": "^2.5",
"symfony/messenger": "^4.4"
},
Expand Down
2 changes: 1 addition & 1 deletion spec/Validator/Cart/CartEligibilityValidatorSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
use Doctrine\Common\Collections\ArrayCollection;
use PhpSpec\ObjectBehavior;
use Prophecy\Promise\ReturnPromise;
use Sylius\Component\Core\Model\OrderItemInterface;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Model\OrderItemInterface;
use Sylius\Component\Core\Model\ProductInterface;
use Sylius\Component\Core\Model\ProductVariantInterface;
use Sylius\Component\Core\Repository\OrderRepositoryInterface;
Expand Down
2 changes: 1 addition & 1 deletion spec/Validator/Cart/CartItemEligibilityValidatorSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

use PhpSpec\ObjectBehavior;
use Sylius\Component\Core\Model\OrderItemInterface;
use Sylius\Component\Core\Model\Product;
use Sylius\Component\Core\Model\ProductVariant;
use Sylius\Component\Order\Repository\OrderItemRepositoryInterface;
use Sylius\Component\Core\Model\Product;
use Sylius\ShopApiPlugin\Validator\Constraints\CartItemEligibility;
use Symfony\Component\Validator\Context\ExecutionContextInterface;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
use PhpSpec\ObjectBehavior;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Repository\OrderRepositoryInterface;
use Sylius\ShopApiPlugin\Validator\Constraints\CartEmpty;
use Sylius\ShopApiPlugin\Validator\Constraints\CartNotEmpty;
use Symfony\Component\Validator\Context\ExecutionContextInterface;

final class CartEmptyValidatorSpec extends ObjectBehavior
final class CartNotEmptyValidatorSpec extends ObjectBehavior
{
function let(
OrderRepositoryInterface $repository,
Expand All @@ -34,7 +34,7 @@ function it_add_no_violation_if_cart_is_not_empty(

$context->addViolation('sylius.shop_api.checkout.cart.empty')->shouldNotBeCalled();

$this->validate('CART_TOKEN', new CartEmpty());
$this->validate('CART_TOKEN', new CartNotEmpty());
}

function it_add_violation_if_cart_is_empty(
Expand All @@ -50,6 +50,6 @@ function it_add_violation_if_cart_is_empty(

$context->addViolation('sylius.shop_api.checkout.cart.empty')->shouldBeCalled();

$this->validate('CART_TOKEN', new CartEmpty());
$this->validate('CART_TOKEN', new CartNotEmpty());
}
}
2 changes: 0 additions & 2 deletions spec/Validator/Product/ProductEligibilityValidatorSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace spec\Sylius\ShopApiPlugin\Validator\Product;

use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Sylius\Component\Core\Model\ProductInterface;
use Sylius\Component\Core\Repository\ProductRepositoryInterface;
use Sylius\ShopApiPlugin\Validator\Constraints\ProductEligibility;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace spec\Sylius\ShopApiPlugin\Validator\Product;

use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Sylius\Component\Core\Model\ProductVariantInterface;
use Sylius\Component\Core\Repository\ProductVariantRepositoryInterface;
use Sylius\ShopApiPlugin\Validator\Constraints\ProductVariantEligibility;
Expand Down
6 changes: 3 additions & 3 deletions src/Resources/config/services/validators/cart.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@
<tag name="validator.constraint_validator" alias="sylius_shop_api_cart_eligibility_validator" />
</service>

<service id="sylius.shop_api_plugin.validator.cart.cart_empty_validator"
class="Sylius\ShopApiPlugin\Validator\Cart\CartEmptyValidator">
<service id="sylius.shop_api_plugin.validator.cart.cart_not_empty_validator"
class="Sylius\ShopApiPlugin\Validator\Cart\CartNotEmptyValidator">
<argument type="service" id="sylius.repository.order" />
<tag name="validator.constraint_validator" alias="sylius_shop_api_cart_empty_validator" />
<tag name="validator.constraint_validator" alias="sylius_shop_api_cart_not_empty_validator" />
</service>
</services>
</container>
2 changes: 1 addition & 1 deletion src/Resources/config/validation/cart/AddCouponRequest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<option name="message">sylius.shop_api.token.not_null</option>
</constraint>
<constraint name="Sylius\ShopApiPlugin\Validator\Constraints\CartExists" />
<constraint name="Sylius\ShopApiPlugin\Validator\Constraints\CartEmpty" />
<constraint name="Sylius\ShopApiPlugin\Validator\Constraints\CartNotEmpty" />
</property>
</class>
</constraint-mapping>
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<option name="message">sylius.shop_api.token.not_null</option>
</constraint>
<constraint name="Sylius\ShopApiPlugin\Validator\Constraints\CartExists" />
<constraint name="Sylius\ShopApiPlugin\Validator\Constraints\CartEmpty" />
<constraint name="Sylius\ShopApiPlugin\Validator\Constraints\CartNotEmpty" />
</property>
<property name="quantity">
<constraint name="Type">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<option name="message">sylius.shop_api.token.not_null</option>
</constraint>
<constraint name="Sylius\ShopApiPlugin\Validator\Constraints\CartExists"/>
<constraint name="Sylius\ShopApiPlugin\Validator\Constraints\CartEmpty"/>
<constraint name="Sylius\ShopApiPlugin\Validator\Constraints\CartNotEmpty"/>
</property>

<property name="countryCode">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<option name="message">sylius.shop_api.token.not_null</option>
</constraint>
<constraint name="Sylius\ShopApiPlugin\Validator\Constraints\CartExists" />
<constraint name="Sylius\ShopApiPlugin\Validator\Constraints\CartEmpty" />
<constraint name="Sylius\ShopApiPlugin\Validator\Constraints\CartNotEmpty" />
</property>

<property name="shippingAddress">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<option name="message">sylius.shop_api.token.not_null</option>
</constraint>
<constraint name="Sylius\ShopApiPlugin\Validator\Constraints\CartExists"/>
<constraint name="Sylius\ShopApiPlugin\Validator\Constraints\CartEmpty"/>
<constraint name="Sylius\ShopApiPlugin\Validator\Constraints\CartNotEmpty"/>
</property>

<property name="method">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<option name="message">sylius.shop_api.token.not_null</option>
</constraint>
<constraint name="Sylius\ShopApiPlugin\Validator\Constraints\CartExists" />
<constraint name="Sylius\ShopApiPlugin\Validator\Constraints\CartEmpty" />
<constraint name="Sylius\ShopApiPlugin\Validator\Constraints\CartNotEmpty" />
<constraint name="Sylius\ShopApiPlugin\Validator\Constraints\CartReadyForCheckout" />
<constraint name="Sylius\ShopApiPlugin\Validator\Constraints\CartEligibility" />
</property>
Expand Down
11 changes: 2 additions & 9 deletions src/Validator/Cart/CartEligibilityValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,11 @@

final class CartEligibilityValidator extends ConstraintValidator
{
/**
* @var OrderRepositoryInterface
*/
/** @var OrderRepositoryInterface */
private $_cartRepository;

/**
* CartEligibilityValidator constructor.
*
* @param OrderRepositoryInterface $cartRepository
*/
public function __construct(OrderRepositoryInterface $cartRepository)
{
Expand All @@ -33,9 +29,6 @@ public function __construct(OrderRepositoryInterface $cartRepository)

/**
* @param mixed $token
* @param Constraint $constraint
*
* @return void
*/
public function validate($token, Constraint $constraint): void
{
Expand All @@ -44,7 +37,7 @@ public function validate($token, Constraint $constraint): void
$cart = $this->_cartRepository->findOneBy(
[
'tokenValue' => $token,
'state' => OrderInterface::STATE_CART
'state' => OrderInterface::STATE_CART,
]
);

Expand Down
9 changes: 1 addition & 8 deletions src/Validator/Cart/CartItemEligibilityValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,11 @@

final class CartItemEligibilityValidator extends ConstraintValidator
{
/**
* @var OrderItemRepositoryInterface
*/
/** @var OrderItemRepositoryInterface */
private $_orderItemRepository;

/**
* CartItemEligibilityValidator constructor.
*
* @param OrderItemRepositoryInterface $orderItemRepository
*/
public function __construct(OrderItemRepositoryInterface $orderItemRepository)
{
Expand All @@ -32,9 +28,6 @@ public function __construct(OrderItemRepositoryInterface $orderItemRepository)

/**
* @param mixed $id
* @param Constraint $constraint
*
* @return void
*/
public function validate($id, Constraint $constraint): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,18 @@

use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Repository\OrderRepositoryInterface;
use Sylius\ShopApiPlugin\Validator\Constraints\CartEmpty;
use Sylius\ShopApiPlugin\Validator\Constraints\CartNotEmpty;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Webmozart\Assert\Assert;

final class CartEmptyValidator extends ConstraintValidator
final class CartNotEmptyValidator extends ConstraintValidator
{
/**
* @var OrderRepositoryInterface
*/
/** @var OrderRepositoryInterface */
private $_cartRepository;

/**
* CartEmptyValidator constructor.
*
* @param OrderRepositoryInterface $cartRepository
* CartNotEmptyValidator constructor.
*/
public function __construct(OrderRepositoryInterface $cartRepository)
{
Expand All @@ -30,18 +26,15 @@ public function __construct(OrderRepositoryInterface $cartRepository)

/**
* @param mixed $token
* @param Constraint $constraint
*
* @return void
*/
public function validate($token, Constraint $constraint): void
{
Assert::isInstanceOf($constraint, CartEmpty::class);
Assert::isInstanceOf($constraint, CartNotEmpty::class);

$cart = $this->_cartRepository->findOneBy(
[
'tokenValue' => $token,
'state' => OrderInterface::STATE_CART
'state' => OrderInterface::STATE_CART,
]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Symfony\Component\Validator\Constraint;

final class CartEmpty extends Constraint
final class CartNotEmpty extends Constraint
{
/** @var string */
public $emptyCartMessage = 'sylius.shop_api.checkout.cart.empty';
Expand All @@ -20,6 +20,6 @@ public function getTargets()
/** {@inheritdoc} */
public function validatedBy(): string
{
return 'sylius_shop_api_cart_empty_validator';
return 'sylius_shop_api_cart_not_empty_validator';
}
}
1 change: 0 additions & 1 deletion src/Validator/Product/ProductEligibilityValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Sylius\Component\Product\Model\Product;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Webmozart\Assert\Assert;

final class ProductEligibilityValidator extends ConstraintValidator
{
Expand Down
2 changes: 0 additions & 2 deletions tests/Controller/Cart/ChangeItemQuantityApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Sylius\ShopApiPlugin\Command\Cart\PickupCart;
use Sylius\ShopApiPlugin\Command\Cart\PutSimpleItemToCart;
use Sylius\ShopApiPlugin\Command\Cart\PutVariantBasedConfigurableItemToCart;
use Sylius\ShopApiPlugin\Command\Cart\RemoveItemFromCart;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Messenger\MessageBusInterface;
use Tests\Sylius\ShopApiPlugin\Controller\JsonApiTestCase;
Expand Down Expand Up @@ -215,7 +214,6 @@ public function it_does_not_allow_to_change_quantity_if_cart_item_variant_is_dis
$this->assertResponse($response, 'cart/validation_cart_item_variant_not_eligible_response', Response::HTTP_BAD_REQUEST);
}


private function getFirstOrderItemId(string $orderToken): string
{
/** @var OrderRepositoryInterface $orderRepository */
Expand Down
3 changes: 0 additions & 3 deletions tests/Controller/Checkout/CompleteOrderApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,6 @@ public function it_disallows_to_complete_checkout_if_product_is_disabled(): void
$bus->dispatch(new ChooseShippingMethod($token, 0, 'DHL'));
$bus->dispatch(new ChoosePaymentMethod($token, 0, 'PBC'));


/** @var ProductRepository $productRepository */
$productRepository = $this->get('sylius.repository.product');

Expand All @@ -470,7 +469,6 @@ public function it_disallows_to_complete_checkout_if_product_is_disabled(): void
$productManager->persist($product);
$productManager->flush();


$data =
<<<JSON
{
Expand Down Expand Up @@ -599,7 +597,6 @@ public function it_disallows_to_complete_checkout_if_chart_is_empty(): void
$this->assertResponse($response, 'checkout/cart_empty_response', Response::HTTP_BAD_REQUEST);
}


private function complete(string $token, ?string $data = null): Response
{
$this->client->request(
Expand Down

0 comments on commit bc22fa8

Please sign in to comment.