diff --git a/docs/book/promotions.rst b/docs/book/promotions.rst index 749ebbb3f0..6fbf73af94 100644 --- a/docs/book/promotions.rst +++ b/docs/book/promotions.rst @@ -52,7 +52,6 @@ The types of rules that are configured in **Sylius** by default are: * **Item Total** - checks if items in the cart cost a given amount of money, * **Taxon** - checks if there is at least one item from given taxons in the cart, * **Items From Taxon Total** - checks in the cart if items from a given taxon cost a given amount of money, -* **Contains Taxon** - checks if there is a given amount of items from a given taxon in the cart, * **Nth Order** - checks if this is for example the second order made by the customer, * **Shipping Country** - checks if the order's shipping address is in a given country. diff --git a/features/promotion/applying_promotion_rules/receiving_discount_based_on_number_of_items_from_specific_taxon.feature b/features/promotion/applying_promotion_rules/receiving_discount_based_on_number_of_items_from_specific_taxon.feature deleted file mode 100644 index 1aa7a9baf2..0000000000 --- a/features/promotion/applying_promotion_rules/receiving_discount_based_on_number_of_items_from_specific_taxon.feature +++ /dev/null @@ -1,55 +0,0 @@ -@applying_promotion_rules -Feature: Receiving a discount based on the number of products from a specific taxon - In order to pay less while buying required number of goods from a promoted taxon - As a Customer - I want to receive a discount for my purchase - - Background: - Given the store operates on a single channel in "United States" - And the store classifies its products as "T-Shirts" and "Mugs" - And the store has a product "PHP T-Shirt" priced at "$100.00" - And this product belongs to "T-Shirts" - And the store has a product "Symfony T-Shirt" priced at "$150.00" - And this product belongs to "T-Shirts" - And the store has a product "PHP Mug" priced at "$20.00" - And this product belongs to "Mugs" - And there is a promotion "T-Shirts promotion" - - @ui - Scenario: Receiving a discount on order while buying the required number of products from a promoted taxon - Given the promotion gives "$50.00" off if order contains 2 products classified as "T-Shirts" - When I add 3 products "PHP T-Shirt" to the cart - Then my cart total should be "$250.00" - And my discount should be "-$50.00" - - @ui - Scenario: Receiving a discount on order while buying exactly the required number of products from a promoted taxon - Given the promotion gives "$50.00" off if order contains 2 products classified as "T-Shirts" - When I add 2 products "PHP T-Shirt" to the cart - Then my cart total should be "$150.00" - And my discount should be "-$50.00" - - @ui - Scenario: Receiving no discount on order while buying less than required number of products from a promoted taxon - Given the promotion gives "$50.00" off if order contains 2 products classified as "T-Shirts" - When I add product "PHP T-Shirt" to the cart - Then my cart total should be "$100.00" - And there should be no discount - - @ui - Scenario: Receiving a discount on order while buying multiple items with products from a promoted taxon which fit number criteria - Given the promotion gives "$100.00" off if order contains 4 products classified as "T-Shirts" - When I add 3 products "PHP T-Shirt" to the cart - And I add 2 products "Symfony T-Shirt" to the cart - Then my cart total should be "$500.00" - And my discount should be "-$100.00" - - @ui - Scenario: Receiving different discounts on different promotions checking number of products from the specific taxon - Given the promotion gives "$50.00" off if order contains 2 products classified as "T-Shirts" - And there is a promotion "Mugs promotion" - And it gives "$10.00" off if order contains 3 products classified as "Mugs" - When I add 3 products "PHP T-Shirt" to the cart - And I add 3 products "PHP Mug" to the cart - Then my cart total should be "$300.00" - And my discount should be "-$60.00" diff --git a/features/promotion/complex_promotions.feature b/features/promotion/complex_promotions.feature index 9038d6333a..5452eddb65 100644 --- a/features/promotion/complex_promotions.feature +++ b/features/promotion/complex_promotions.feature @@ -25,15 +25,6 @@ Feature: Receiving a discount based on a configured promotion Then my cart total should be "$40.00" And my discount should be "-$10.00" - @ui - Scenario: Receiving a discount on products from a specific taxon if an order contains products from an another taxon - Given there is a promotion "Jacket-trousers pack" - And it gives "10%" off on every product classified as "Jackets" if an order contains any product classified as "Trousers" - When I add product "Iron Maiden trousers" to the cart - And I add product "Black Sabbath jacket" to the cart - Then product "Black Sabbath jacket" price should be decreased by "$10.00" - And my cart total should be "$170.00" - @ui Scenario: Receiving a discount on items and shipping from one promotion based on items total Given the store has "DHL" shipping method with "$10.00" fee diff --git a/features/promotion/managing_promotions/adding_promotion_with_rule.feature b/features/promotion/managing_promotions/adding_promotion_with_rule.feature index 695b62790a..efe10c760d 100644 --- a/features/promotion/managing_promotions/adding_promotion_with_rule.feature +++ b/features/promotion/managing_promotions/adding_promotion_with_rule.feature @@ -9,22 +9,12 @@ Feature: Adding a new promotion with rule And the store classifies its products as "T-Shirts" and "Mugs" And I am logged in as an administrator - @ui @javascript - Scenario: Adding a new promotion with contains items from taxon rule - Given I want to create a new promotion - When I specify its code as "T_SHIRTS_PROMOTION" - And I name it "T-Shirts promotion" - And I add the "Contains number of items from taxon" rule configured with 4 "T-Shirts" - And I add it - Then I should be notified that it has been successfully created - And the "T-Shirts promotion" promotion should appear in the registry - @ui @javascript Scenario: Adding a new promotion with taxon rule Given I want to create a new promotion When I specify its code as "HOLIDAY_SALE" And I name it "Holiday sale" - And I add the "Taxon" rule configured with "T-Shirts" and "Mugs" + And I add the "Has at least one from taxons" rule configured with "T-Shirts" and "Mugs" And I add it Then I should be notified that it has been successfully created And the "Holiday sale" promotion should appear in the registry diff --git a/src/Sylius/Behat/Context/Setup/PromotionContext.php b/src/Sylius/Behat/Context/Setup/PromotionContext.php index 41a1379201..a59d27f04e 100644 --- a/src/Sylius/Behat/Context/Setup/PromotionContext.php +++ b/src/Sylius/Behat/Context/Setup/PromotionContext.php @@ -399,7 +399,7 @@ final class PromotionContext implements Context $discount, TaxonInterface $taxon ) { - $rule = $this->ruleFactory->createTaxon([$taxon->getCode()]); + $rule = $this->ruleFactory->createHasTaxon([$taxon->getCode()]); $this->createFixedPromotion($promotion, $discount, [], $rule); } @@ -412,7 +412,7 @@ final class PromotionContext implements Context $discount, array $taxons ) { - $rule = $this->ruleFactory->createTaxon([$taxons[0]->getCode(), $taxons[1]->getCode()]); + $rule = $this->ruleFactory->createHasTaxon([$taxons[0]->getCode(), $taxons[1]->getCode()]); $this->createFixedPromotion($promotion, $discount, [], $rule); } @@ -431,20 +431,6 @@ final class PromotionContext implements Context $this->createFixedPromotion($promotion, $discount, [], $rule); } - /** - * @Given /^([^"]+) gives ("(?:€|£|\$)[^"]+") off if order contains (\d+) products (classified as "[^"]+")$/ - */ - public function thePromotionGivesOffIfOrderContainsNumberOfProductsClassifiedAs( - PromotionInterface $promotion, - $discount, - $count, - TaxonInterface $taxon - ) { - $rule = $this->ruleFactory->createContainsTaxon($taxon->getCode(), $count); - - $this->createFixedPromotion($promotion, $discount, [], $rule); - } - /** * @Given /^([^"]+) gives ("(?:€|£|\$)[^"]+") off customer's (\d)(?:st|nd|rd|th) order$/ */ @@ -465,20 +451,6 @@ final class PromotionContext implements Context $this->createPercentagePromotion($promotion, $discount, [], $rule); } - /** - * @Given /^([^"]+) gives ("[^"]+%") off on every product (classified as "[^"]+") if an order contains any product (classified as "[^"]+")$/ - */ - public function itGivesPercentageOffOnEveryProductClassifiedAsIfAnOrderContainsAnyProductClassifiedAs( - PromotionInterface $promotion, - $discount, - TaxonInterface $discountTaxon, - TaxonInterface $targetTaxon - ) { - $rule = $this->ruleFactory->createContainsTaxon($targetTaxon->getCode(), 1); - - $this->createUnitPercentagePromotion($promotion, $discount, $this->getTaxonFilterConfiguration([$discountTaxon->getCode()]), $rule); - } - /** * @Given /^([^"]+) gives ("[^"]+%") off on every product (classified as "[^"]+") and ("(?:€|£|\$)[^"]+") discount on every order$/ */ @@ -544,7 +516,7 @@ final class PromotionContext implements Context $discountTaxonsCodes = [$discountTaxons[0]->getCode(), $discountTaxons[1]->getCode()]; $targetTaxonsCodes = [$targetTaxons[0]->getCode(), $targetTaxons[1]->getCode()]; - $rule = $this->ruleFactory->createTaxon($targetTaxonsCodes); + $rule = $this->ruleFactory->createHasTaxon($targetTaxonsCodes); $this->createUnitPercentagePromotion( $promotion, diff --git a/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php b/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php index 7cf50d227f..a944fbf5ab 100644 --- a/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php +++ b/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php @@ -143,22 +143,12 @@ final class ManagingPromotionsContext implements Context } /** - * @Given I add the "Contains number of items from taxon" rule configured with :count :taxonName + * @Given I add the "Has at least one from taxons" rule configured with :firstTaxon + * @Given I add the "Has at least one from taxons" rule configured with :firstTaxon and :secondTaxon */ - public function iAddTheContainsTaxonRuleConfiguredWith($count, $taxonName) + public function iAddTheHasTaxonRuleConfiguredWith(...$taxons) { - $this->createPage->addRule('Contains number of items from taxon'); - $this->createPage->selectRuleOption('Taxon', $taxonName); - $this->createPage->fillRuleOption('Count', $count); - } - - /** - * @Given I add the "Taxon" rule configured with :firstTaxon - * @Given I add the "Taxon" rule configured with :firstTaxon and :secondTaxon - */ - public function iAddTheTaxonRuleConfiguredWith(...$taxons) - { - $this->createPage->addRule('Taxon'); + $this->createPage->addRule('Has at least one from taxons'); foreach ($taxons as $taxon) { $this->createPage->selectRuleOption('Taxons', $taxon, true); diff --git a/src/Sylius/Bundle/CoreBundle/Form/Type/Promotion/Rule/ContainsTaxonConfigurationType.php b/src/Sylius/Bundle/CoreBundle/Form/Type/Promotion/Rule/ContainsTaxonConfigurationType.php deleted file mode 100644 index f3c94c4aab..0000000000 --- a/src/Sylius/Bundle/CoreBundle/Form/Type/Promotion/Rule/ContainsTaxonConfigurationType.php +++ /dev/null @@ -1,63 +0,0 @@ - - */ -class ContainsTaxonConfigurationType extends AbstractType -{ - /** - * @var TaxonRepositoryInterface - */ - private $taxonRepository; - - /** - * @param TaxonRepositoryInterface $taxonRepository - */ - public function __construct(TaxonRepositoryInterface $taxonRepository) - { - $this->taxonRepository = $taxonRepository; - } - - /** - * {@inheritdoc} - */ - public function buildForm(FormBuilderInterface $builder, array $options) - { - $builder - ->add('taxon', 'sylius_taxon_from_identifier', [ - 'label' => 'sylius.form.promotion_rule.contains_taxon.taxon', - 'class' => $this->taxonRepository->getClassName(), - 'query_builder' => function () { - return $this->taxonRepository->getFormQueryBuilder(); - }, - 'identifier' => 'code', - ]) - ->add('count', 'integer', [ - 'label' => 'sylius.form.promotion_rule.contains_taxon.count', - ]) - ; - } - - /** - * {@inheritdoc} - */ - public function getName() - { - return 'sylius_promotion_rule_contains_taxon_configuration'; - } -} diff --git a/src/Sylius/Bundle/CoreBundle/Form/Type/Promotion/Rule/TaxonConfigurationType.php b/src/Sylius/Bundle/CoreBundle/Form/Type/Promotion/Rule/HasTaxonConfigurationType.php similarity index 91% rename from src/Sylius/Bundle/CoreBundle/Form/Type/Promotion/Rule/TaxonConfigurationType.php rename to src/Sylius/Bundle/CoreBundle/Form/Type/Promotion/Rule/HasTaxonConfigurationType.php index 202edb2bdb..b7530d78d2 100644 --- a/src/Sylius/Bundle/CoreBundle/Form/Type/Promotion/Rule/TaxonConfigurationType.php +++ b/src/Sylius/Bundle/CoreBundle/Form/Type/Promotion/Rule/HasTaxonConfigurationType.php @@ -18,7 +18,7 @@ use Symfony\Component\Form\FormBuilderInterface; /** * @author Saša Stamenković */ -class TaxonConfigurationType extends AbstractType +class HasTaxonConfigurationType extends AbstractType { /** * @var DataTransformerInterface @@ -53,6 +53,6 @@ class TaxonConfigurationType extends AbstractType */ public function getName() { - return 'sylius_promotion_rule_taxon_configuration'; + return 'sylius_promotion_rule_has_taxon_configuration'; } } diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/form.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/form.xml index c2c2ca562b..1013deeb9c 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/services/form.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/form.xml @@ -86,13 +86,9 @@ - + - - - - - + diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/services/promotion.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/services/promotion.xml index 3a13e1af02..2e5f7e07b8 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/services/promotion.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/services/promotion.xml @@ -30,12 +30,8 @@ - - - - - - + + diff --git a/src/Sylius/Bundle/CoreBundle/Resources/translations/messages.en.yml b/src/Sylius/Bundle/CoreBundle/Resources/translations/messages.en.yml index bc7d514e4c..a6d0cf4de8 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/translations/messages.en.yml +++ b/src/Sylius/Bundle/CoreBundle/Resources/translations/messages.en.yml @@ -120,9 +120,6 @@ sylius: product_association_type: name: Name promotion_rule: - contains_taxon: - taxon: Taxon - count: Count taxon: taxons: Taxons product: diff --git a/src/Sylius/Component/Core/Factory/PromotionRuleFactory.php b/src/Sylius/Component/Core/Factory/PromotionRuleFactory.php index 26b6973aa3..142c1c235b 100644 --- a/src/Sylius/Component/Core/Factory/PromotionRuleFactory.php +++ b/src/Sylius/Component/Core/Factory/PromotionRuleFactory.php @@ -12,9 +12,8 @@ namespace Sylius\Component\Core\Factory; use Sylius\Component\Core\Promotion\Checker\Rule\ContainsProductRuleChecker; -use Sylius\Component\Core\Promotion\Checker\Rule\ContainsTaxonRuleChecker; use Sylius\Component\Core\Promotion\Checker\Rule\NthOrderRuleChecker; -use Sylius\Component\Core\Promotion\Checker\Rule\TaxonRuleChecker; +use Sylius\Component\Core\Promotion\Checker\Rule\HasTaxonRuleChecker; use Sylius\Component\Core\Promotion\Checker\Rule\TotalOfItemsFromTaxonRuleChecker; use Sylius\Component\Promotion\Checker\Rule\CartQuantityRuleChecker; use Sylius\Component\Promotion\Checker\Rule\ItemTotalRuleChecker; @@ -76,11 +75,11 @@ class PromotionRuleFactory implements PromotionRuleFactoryInterface /** * {@inheritdoc} */ - public function createTaxon(array $taxons) + public function createHasTaxon(array $taxons) { /** @var PromotionRuleInterface $rule */ $rule = $this->createNew(); - $rule->setType(TaxonRuleChecker::TYPE); + $rule->setType(HasTaxonRuleChecker::TYPE); $rule->setConfiguration(['taxons' => $taxons]); return $rule; @@ -99,19 +98,6 @@ class PromotionRuleFactory implements PromotionRuleFactoryInterface return $rule; } - /** - * {@inheritdoc} - */ - public function createContainsTaxon($taxonCode, $count) - { - /** @var PromotionRuleInterface $rule */ - $rule = $this->createNew(); - $rule->setType(ContainsTaxonRuleChecker::TYPE); - $rule->setConfiguration(['taxon' => $taxonCode, 'count' => $count]); - - return $rule; - } - /** * {@inheritdoc} */ diff --git a/src/Sylius/Component/Core/Factory/PromotionRuleFactoryInterface.php b/src/Sylius/Component/Core/Factory/PromotionRuleFactoryInterface.php index ef0bec0ca4..23906d4467 100644 --- a/src/Sylius/Component/Core/Factory/PromotionRuleFactoryInterface.php +++ b/src/Sylius/Component/Core/Factory/PromotionRuleFactoryInterface.php @@ -38,7 +38,7 @@ interface PromotionRuleFactoryInterface extends FactoryInterface * * @return PromotionRuleInterface */ - public function createTaxon(array $taxons); + public function createHasTaxon(array $taxons); /** * @param string $taxonCode @@ -48,14 +48,6 @@ interface PromotionRuleFactoryInterface extends FactoryInterface */ public function createItemsFromTaxonTotal($taxonCode, $amount); - /** - * @param string $taxonCode - * @param int $count - * - * @return PromotionRuleInterface - */ - public function createContainsTaxon($taxonCode, $count); - /** * @param int $nth * diff --git a/src/Sylius/Component/Core/Promotion/Checker/Rule/ContainsTaxonRuleChecker.php b/src/Sylius/Component/Core/Promotion/Checker/Rule/ContainsTaxonRuleChecker.php deleted file mode 100644 index c81b7688cd..0000000000 --- a/src/Sylius/Component/Core/Promotion/Checker/Rule/ContainsTaxonRuleChecker.php +++ /dev/null @@ -1,77 +0,0 @@ - - */ -final class ContainsTaxonRuleChecker implements RuleCheckerInterface -{ - const TYPE = 'contains_taxon'; - - /** - * @var TaxonRepositoryInterface - */ - private $taxonRepository; - - /** - * @param TaxonRepositoryInterface $taxonRepository - */ - public function __construct(TaxonRepositoryInterface $taxonRepository) - { - $this->taxonRepository = $taxonRepository; - } - - /** - * {@inheritdoc} - */ - public function isEligible(PromotionSubjectInterface $subject, array $configuration) - { - if (!$subject instanceof OrderInterface) { - throw new UnexpectedTypeException($subject, OrderInterface::class); - } - - if (!isset($configuration['taxon']) || !isset($configuration['count'])) { - return false; - } - - $targetTaxon = $this->taxonRepository->findOneBy(['code' => $configuration['taxon']]); - if (null === $targetTaxon) { - return false; - } - - $validProducts = 0; - foreach ($subject->getItems() as $item) { - if (!$item->getProduct()->hasTaxon($targetTaxon)) { - continue; - } - - $validProducts += $item->getQuantity(); - } - - return $validProducts >= $configuration['count']; - } - - /** - * @return string - */ - public function getConfigurationFormType() - { - return 'sylius_promotion_rule_contains_taxon_configuration'; - } -} diff --git a/src/Sylius/Component/Core/Promotion/Checker/Rule/TaxonRuleChecker.php b/src/Sylius/Component/Core/Promotion/Checker/Rule/HasTaxonRuleChecker.php similarity index 90% rename from src/Sylius/Component/Core/Promotion/Checker/Rule/TaxonRuleChecker.php rename to src/Sylius/Component/Core/Promotion/Checker/Rule/HasTaxonRuleChecker.php index 53c0e40715..b0053ce534 100644 --- a/src/Sylius/Component/Core/Promotion/Checker/Rule/TaxonRuleChecker.php +++ b/src/Sylius/Component/Core/Promotion/Checker/Rule/HasTaxonRuleChecker.php @@ -20,9 +20,9 @@ use Sylius\Component\Promotion\Model\PromotionSubjectInterface; /** * @author Saša Stamenković */ -final class TaxonRuleChecker implements RuleCheckerInterface +final class HasTaxonRuleChecker implements RuleCheckerInterface { - const TYPE = 'taxon'; + const TYPE = 'has_taxon'; /** * {@inheritdoc} @@ -54,6 +54,6 @@ final class TaxonRuleChecker implements RuleCheckerInterface */ public function getConfigurationFormType() { - return 'sylius_promotion_rule_taxon_configuration'; + return 'sylius_promotion_rule_has_taxon_configuration'; } } diff --git a/src/Sylius/Component/Core/spec/Factory/PromotionRuleFactorySpec.php b/src/Sylius/Component/Core/spec/Factory/PromotionRuleFactorySpec.php index 36f672bb60..db7a28515b 100644 --- a/src/Sylius/Component/Core/spec/Factory/PromotionRuleFactorySpec.php +++ b/src/Sylius/Component/Core/spec/Factory/PromotionRuleFactorySpec.php @@ -15,9 +15,8 @@ use PhpSpec\ObjectBehavior; use Sylius\Component\Core\Factory\PromotionRuleFactory; use Sylius\Component\Core\Factory\PromotionRuleFactoryInterface; use Sylius\Component\Core\Promotion\Checker\Rule\ContainsProductRuleChecker; -use Sylius\Component\Core\Promotion\Checker\Rule\ContainsTaxonRuleChecker; use Sylius\Component\Core\Promotion\Checker\Rule\NthOrderRuleChecker; -use Sylius\Component\Core\Promotion\Checker\Rule\TaxonRuleChecker; +use Sylius\Component\Core\Promotion\Checker\Rule\HasTaxonRuleChecker; use Sylius\Component\Core\Promotion\Checker\Rule\TotalOfItemsFromTaxonRuleChecker; use Sylius\Component\Promotion\Checker\Rule\CartQuantityRuleChecker; use Sylius\Component\Promotion\Checker\Rule\ItemTotalRuleChecker; @@ -71,13 +70,13 @@ final class PromotionRuleFactorySpec extends ObjectBehavior $this->createItemTotal(1000)->shouldReturn($rule); } - function it_creates_a_taxon_rule(FactoryInterface $decoratedFactory, PromotionRuleInterface $rule) + function it_creates_a_has_taxon_rule(FactoryInterface $decoratedFactory, PromotionRuleInterface $rule) { $decoratedFactory->createNew()->willReturn($rule); - $rule->setType(TaxonRuleChecker::TYPE)->shouldBeCalled(); + $rule->setType(HasTaxonRuleChecker::TYPE)->shouldBeCalled(); $rule->setConfiguration(['taxons' => [1, 6]])->shouldBeCalled(); - $this->createTaxon([1, 6])->shouldReturn($rule); + $this->createHasTaxon([1, 6])->shouldReturn($rule); } function it_creates_a_total_of_items_from_taxon_rule( @@ -91,15 +90,6 @@ final class PromotionRuleFactorySpec extends ObjectBehavior $this->createItemsFromTaxonTotal('spears', 1000)->shouldReturn($rule); } - function it_creates_a_contains_taxon_rule(FactoryInterface $decoratedFactory, PromotionRuleInterface $rule) - { - $decoratedFactory->createNew()->willReturn($rule); - $rule->setType(ContainsTaxonRuleChecker::TYPE)->shouldBeCalled(); - $rule->setConfiguration(['taxon' => 'bows', 'count' => 10])->shouldBeCalled(); - - $this->createContainsTaxon('bows', 10)->shouldReturn($rule); - } - function it_creates_a_nth_order_rule(FactoryInterface $decoratedFactory, PromotionRuleInterface $rule) { $decoratedFactory->createNew()->willReturn($rule); diff --git a/src/Sylius/Component/Core/spec/Promotion/Checker/Rule/ContainsTaxonRuleCheckerSpec.php b/src/Sylius/Component/Core/spec/Promotion/Checker/Rule/ContainsTaxonRuleCheckerSpec.php deleted file mode 100644 index 2b60e5ae6b..0000000000 --- a/src/Sylius/Component/Core/spec/Promotion/Checker/Rule/ContainsTaxonRuleCheckerSpec.php +++ /dev/null @@ -1,154 +0,0 @@ - - */ -final class ContainsTaxonRuleCheckerSpec extends ObjectBehavior -{ - function let(TaxonRepositoryInterface $taxonRepository) - { - $this->beConstructedWith($taxonRepository); - } - - function it_is_initializable() - { - $this->shouldHaveType(ContainsTaxonRuleChecker::class); - } - - function it_implements_a_rule_checker_interface() - { - $this->shouldImplement(RuleCheckerInterface::class); - } - - function it_returns_true_if_order_has_required_number_of_products_from_configured_taxon( - OrderInterface $order, - OrderItemInterface $compositeBowItem, - OrderItemInterface $longbowItem, - ProductInterface $compositeBow, - ProductInterface $longbow, - TaxonInterface $bows, - TaxonRepositoryInterface $taxonRepository - ) { - $order - ->getItems() - ->willReturn(new \ArrayIterator([$compositeBowItem->getWrappedObject(), $longbowItem->getWrappedObject()])) - ; - - $taxonRepository->findOneBy(['code' => 'bows'])->willReturn($bows); - - $compositeBowItem->getProduct()->willReturn($compositeBow); - $compositeBow->hasTaxon($bows)->willReturn(true); - $compositeBowItem->getQuantity()->willReturn(4); - - $longbowItem->getProduct()->willReturn($longbow); - $longbow->hasTaxon($bows)->willReturn(true); - $longbowItem->getQuantity()->willReturn(5); - - $this->isEligible($order, ['taxon' => 'bows', 'count' => 5])->shouldReturn(true); - } - - function it_returns_false_if_an_order_does_not_have_the_required_number_of_products_from_a_configured_taxon( - OrderInterface $order, - OrderItemInterface $compositeBowItem, - OrderItemInterface $longbowItem, - ProductInterface $compositeBow, - ProductInterface $longbow, - TaxonInterface $bows, - TaxonRepositoryInterface $taxonRepository - ) { - $order - ->getItems() - ->willReturn(new \ArrayIterator([$compositeBowItem->getWrappedObject(), $longbowItem->getWrappedObject()])) - ; - - $taxonRepository->findOneBy(['code' => 'bows'])->willReturn($bows); - - $compositeBowItem->getProduct()->willReturn($compositeBow); - $compositeBow->hasTaxon($bows)->willReturn(true); - $compositeBowItem->getQuantity()->willReturn(4); - - $longbowItem->getProduct()->willReturn($longbow); - $longbow->hasTaxon($bows)->willReturn(true); - $longbowItem->getQuantity()->willReturn(5); - - $this->isEligible($order, ['taxon' => 'bows', 'count' => 15])->shouldReturn(false); - } - - function it_does_not_check_an_item_if_its_product_has_no_required_taxon( - OrderInterface $order, - OrderItemInterface $compositeBowItem, - OrderItemInterface $longswordItem, - ProductInterface $compositeBow, - ProductInterface $longsword, - TaxonInterface $bows, - TaxonRepositoryInterface $taxonRepository - ) { - $order - ->getItems() - ->willReturn(new \ArrayIterator([$compositeBowItem->getWrappedObject(), $longswordItem->getWrappedObject()])) - ; - - $taxonRepository->findOneBy(['code' => 'bows'])->willReturn($bows); - - $compositeBowItem->getProduct()->willReturn($compositeBow); - $compositeBow->hasTaxon($bows)->willReturn(true); - $compositeBowItem->getQuantity()->willReturn(4); - - $longswordItem->getProduct()->willReturn($longsword); - $longsword->hasTaxon($bows)->willReturn(false); - $longswordItem->getQuantity()->shouldNotBeCalled(); - - $this->isEligible($order, ['taxon' => 'bows', 'count' => 5])->shouldReturn(false); - } - - function it_returns_false_if_configuration_is_invalid(OrderInterface $order) - { - $this->isEligible($order, ['taxon' => 'bows'])->shouldReturn(false); - $this->isEligible($order, ['count' => 10])->shouldReturn(false); - $this->isEligible($order, [])->shouldReturn(false); - } - - function it_returns_false_if_taxon_with_configured_code_does_not_exist( - OrderInterface $order, - TaxonRepositoryInterface $taxonRepository - ) { - $taxonRepository->findOneBy(['code' => 'bows'])->willReturn(null); - - $this->isEligible($order, ['taxon' => 'bows', 'count' => 10])->shouldReturn(false); - } - - function it_throws_an_exception_if_the_promotion_subject_is_not_an_order(PromotionSubjectInterface $subject) - { - $this - ->shouldThrow(new UnexpectedTypeException($subject->getWrappedObject(), OrderInterface::class)) - ->during('isEligible', [$subject, []]) - ; - } - - function it_has_a_configuration_type() - { - $this->getConfigurationFormType()->shouldReturn('sylius_promotion_rule_contains_taxon_configuration'); - } -} diff --git a/src/Sylius/Component/Core/spec/Promotion/Checker/Rule/TaxonRuleCheckerSpec.php b/src/Sylius/Component/Core/spec/Promotion/Checker/Rule/HasTaxonRuleCheckerSpec.php similarity index 94% rename from src/Sylius/Component/Core/spec/Promotion/Checker/Rule/TaxonRuleCheckerSpec.php rename to src/Sylius/Component/Core/spec/Promotion/Checker/Rule/HasTaxonRuleCheckerSpec.php index b785b54c59..16144bc1e8 100644 --- a/src/Sylius/Component/Core/spec/Promotion/Checker/Rule/TaxonRuleCheckerSpec.php +++ b/src/Sylius/Component/Core/spec/Promotion/Checker/Rule/HasTaxonRuleCheckerSpec.php @@ -17,7 +17,7 @@ use Sylius\Component\Core\Model\OrderInterface; use Sylius\Component\Core\Model\OrderItemInterface; use Sylius\Component\Core\Model\ProductInterface; use Sylius\Component\Core\Model\TaxonInterface; -use Sylius\Component\Core\Promotion\Checker\Rule\TaxonRuleChecker; +use Sylius\Component\Core\Promotion\Checker\Rule\HasTaxonRuleChecker; use Sylius\Component\Promotion\Checker\Rule\RuleCheckerInterface; use Sylius\Component\Promotion\Exception\UnsupportedTypeException; use Sylius\Component\Promotion\Model\PromotionSubjectInterface; @@ -26,11 +26,11 @@ use Sylius\Component\Promotion\Model\PromotionSubjectInterface; * @author Joseph Bielawski * @author Mateusz Zalewski */ -final class TaxonRuleCheckerSpec extends ObjectBehavior +final class HasTaxonRuleCheckerSpec extends ObjectBehavior { function it_is_initializable() { - $this->shouldHaveType(TaxonRuleChecker::class); + $this->shouldHaveType(HasTaxonRuleChecker::class); } function it_is_a_rule_checker()