From 76ce9ecdd0604621b07e66b469bc7ca7e9fe9e97 Mon Sep 17 00:00:00 2001 From: Piotr Walkow Date: Wed, 16 Sep 2015 16:14:09 +0100 Subject: [PATCH] Add missing spec for ContainsProductRuleChecker --- .../ContainsProductRuleCheckerSpec.php | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 src/Sylius/Component/Core/spec/Promotion/Checker/ContainsProductRuleCheckerSpec.php diff --git a/src/Sylius/Component/Core/spec/Promotion/Checker/ContainsProductRuleCheckerSpec.php b/src/Sylius/Component/Core/spec/Promotion/Checker/ContainsProductRuleCheckerSpec.php new file mode 100644 index 000000000000..3b11f5b2af5a --- /dev/null +++ b/src/Sylius/Component/Core/spec/Promotion/Checker/ContainsProductRuleCheckerSpec.php @@ -0,0 +1,96 @@ + + */ +class ContainsProductRuleCheckerSpec extends ObjectBehavior +{ + function it_should_be_initializable() + { + $this->shouldHaveType('Sylius\Component\Core\Promotion\Checker\ContainsProductRuleChecker'); + } + + function it_should_be_Sylius_rule_checker() + { + $this->shouldImplement('Sylius\Component\Promotion\Checker\RuleCheckerInterface'); + } + + function it_throw_exception_on_invalid_subject(PromotionSubjectInterface $subject) + { + $this->shouldThrow(UnsupportedTypeException::class)->duringIsEligible($subject, []); + } + + function it_returns_true_if_variant_is_right_and_exclude_is_not_set( + OrderInterface $subject, + OrderItem $orderItem, + ProductVariant $variant + ) { + $subject->getItems()->shouldBeCalled(); + $subject->getItems()->willReturn([$orderItem]); + $orderItem->getVariant()->shouldBeCalled(); + $orderItem->getVariant()->willReturn($variant); + $variant->getId()->willReturn(1); + + $this->isEligible($subject, ['variant' => 1, 'exclude' => false])->shouldReturn(true); + } + + function it_returns_false_if_variant_is_right_and_exclude_is_set( + OrderInterface $subject, + OrderItem $orderItem, + ProductVariant $variant + ) { + $subject->getItems()->shouldBeCalled(); + $subject->getItems()->willReturn([$orderItem]); + $orderItem->getVariant()->shouldBeCalled(); + $orderItem->getVariant()->willReturn($variant); + $variant->getId()->willReturn(1); + + $this->isEligible($subject, ['variant' => 1, 'exclude' => true])->shouldReturn(false); + } + + function it_returns_true_if_variant_is_not_included_and_exclude_is_not_set( + OrderInterface $subject, + OrderItem $orderItem, + ProductVariant $variant + ) { + $subject->getItems()->shouldBeCalled(); + $subject->getItems()->willReturn([$orderItem]); + $orderItem->getVariant()->shouldBeCalled(); + $orderItem->getVariant()->willReturn($variant); + $variant->getId()->willReturn(2); + + $this->isEligible($subject, ['variant' => 1, 'exclude' => true])->shouldReturn(true); + } + + function it_returns_false_if_variant_is_not_included_and_exclude_is_not_set( + OrderInterface $subject, + OrderItem $orderItem, + ProductVariant $variant + ) { + $subject->getItems()->shouldBeCalled(); + $subject->getItems()->willReturn([$orderItem]); + $orderItem->getVariant()->shouldBeCalled(); + $orderItem->getVariant()->willReturn($variant); + $variant->getId()->willReturn(2); + + $this->isEligible($subject, ['variant' => 1, 'exclude' => false])->shouldReturn(false); + } +}