Completed
Push — master ( 26132b...c9e982 )
by Kamil
31:04 queued 12:47
created

ItemTotalRuleCheckerSpec::it_is_initializable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace spec\Sylius\Component\Core\Promotion\Checker\Rule;
13
14
use PhpSpec\ObjectBehavior;
15
use Sylius\Bundle\PromotionBundle\Form\Type\Rule\ItemTotalConfigurationType;
16
use Sylius\Component\Core\Model\ChannelInterface;
17
use Sylius\Component\Core\Model\OrderInterface;
18
use Sylius\Component\Core\Promotion\Checker\Rule\ChannelBasedRuleCheckerInterface;
19
use Sylius\Component\Core\Promotion\Checker\Rule\ItemTotalRuleChecker;
20
use Sylius\Component\Promotion\Checker\Rule\RuleCheckerInterface;
21
use Sylius\Component\Promotion\Model\PromotionSubjectInterface;
22
23
/**
24
 * @author Mateusz Zalewski <[email protected]>
25
 */
26
final class ItemTotalRuleCheckerSpec extends ObjectBehavior
27
{
28
    function let(RuleCheckerInterface $itemTotalRuleChecker)
29
    {
30
        $this->beConstructedWith($itemTotalRuleChecker);
31
    }
32
33
    function it_is_initializable()
34
    {
35
        $this->shouldHaveType(ItemTotalRuleChecker::class);
36
    }
37
38
    function it_is_be_a_rule_checker()
39
    {
40
        $this->shouldImplement(RuleCheckerInterface::class);
41
    }
42
43
    function it_implements_channel_aware_rule_checker_interface()
44
    {
45
        $this->shouldImplement(ChannelBasedRuleCheckerInterface::class);
46
    }
47
48
    function it_uses_decorated_checker_to_check_eligibility_for_order_channel(
49
        ChannelInterface $channel,
50
        OrderInterface $order,
51
        RuleCheckerInterface $itemTotalRuleChecker
52
    ) {
53
        $order->getChannel()->willReturn($channel);
54
        $channel->getCode()->willReturn('WEB_US');
55
56
        $itemTotalRuleChecker->isEligible($order, ['amount' => 1000])->willReturn(true);
57
58
        $this->isEligible($order, ['WEB_US' => ['amount' => 1000]])->shouldReturn(true);
59
    }
60
61
    function it_returns_false_if_there_is_no_configuration_for_order_channel(
62
        ChannelInterface $channel,
63
        OrderInterface $order
64
    ) {
65
        $order->getChannel()->willReturn($channel);
66
        $channel->getCode()->willReturn('WEB_US');
67
68
        $this->isEligible($order, [])->shouldReturn(false);
69
    }
70
71
    function it_throws_exception_if_passed_subject_is_not_order(PromotionSubjectInterface $promotionSubject)
72
    {
73
        $this
74
            ->shouldThrow(\InvalidArgumentException::class)
75
            ->during('isEligible', [$promotionSubject, []])
76
        ;
77
    }
78
79
    function it_returns_a_total_configuration_form_type()
80
    {
81
        $this->getConfigurationFormType()->shouldReturn(ItemTotalConfigurationType::class);
82
    }
83
}
84