Completed
Push — scalar-types/taxonomy ( 4d330b )
by Kamil
23:21
created

CompositePromotionEligibilityCheckerSpec   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 0
loc 77
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 4 1
A it_is_a_promotion_eligibility_checker() 0 4 1
A it_returns_true_if_all_eligibility_checker_returns_true() 0 16 1
A it_returns_false_if_any_eligibility_checker_returns_false() 0 16 1
A it_stops_chcecking_at_the_first_failing_eligibility_checker() 0 16 1
A it_throws_an_exception_if_no_eligibility_checkers_are_passed() 0 6 1
A it_throws_an_exception_if_passed_array_has_not_only_eligibility_checkers() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace spec\Sylius\Component\Promotion\Checker\Eligibility;
6
7
use PhpSpec\ObjectBehavior;
8
use Sylius\Component\Promotion\Checker\Eligibility\PromotionEligibilityCheckerInterface;
9
use Sylius\Component\Promotion\Model\PromotionInterface;
10
use Sylius\Component\Promotion\Model\PromotionSubjectInterface;
11
12
/**
13
 * @author Kamil Kokot <[email protected]>
14
 */
15
final class CompositePromotionEligibilityCheckerSpec extends ObjectBehavior
16
{
17
    function let(PromotionEligibilityCheckerInterface $promotionEligibilityChecker): void
18
    {
19
        $this->beConstructedWith([$promotionEligibilityChecker]);
20
    }
21
22
    function it_is_a_promotion_eligibility_checker(): void
23
    {
24
        $this->shouldImplement(PromotionEligibilityCheckerInterface::class);
25
    }
26
27
    function it_returns_true_if_all_eligibility_checker_returns_true(
28
        PromotionEligibilityCheckerInterface $firstPromotionEligibilityChecker,
29
        PromotionEligibilityCheckerInterface $secondPromotionEligibilityChecker,
30
        PromotionSubjectInterface $promotionSubject,
31
        PromotionInterface $promotion
32
    ): void {
33
        $this->beConstructedWith([
34
            $firstPromotionEligibilityChecker,
35
            $secondPromotionEligibilityChecker,
36
        ]);
37
38
        $firstPromotionEligibilityChecker->isEligible($promotionSubject, $promotion)->willReturn(true);
39
        $secondPromotionEligibilityChecker->isEligible($promotionSubject, $promotion)->willReturn(true);
40
41
        $this->isEligible($promotionSubject, $promotion)->shouldReturn(true);
42
    }
43
44
    function it_returns_false_if_any_eligibility_checker_returns_false(
45
        PromotionEligibilityCheckerInterface $firstPromotionEligibilityChecker,
46
        PromotionEligibilityCheckerInterface $secondPromotionEligibilityChecker,
47
        PromotionSubjectInterface $promotionSubject,
48
        PromotionInterface $promotion
49
    ): void {
50
        $this->beConstructedWith([
51
            $firstPromotionEligibilityChecker,
52
            $secondPromotionEligibilityChecker,
53
        ]);
54
55
        $firstPromotionEligibilityChecker->isEligible($promotionSubject, $promotion)->willReturn(true);
56
        $secondPromotionEligibilityChecker->isEligible($promotionSubject, $promotion)->willReturn(false);
57
58
        $this->isEligible($promotionSubject, $promotion)->shouldReturn(false);
59
    }
60
61
    function it_stops_chcecking_at_the_first_failing_eligibility_checker(
62
        PromotionEligibilityCheckerInterface $firstPromotionEligibilityChecker,
63
        PromotionEligibilityCheckerInterface $secondPromotionEligibilityChecker,
64
        PromotionSubjectInterface $promotionSubject,
65
        PromotionInterface $promotion
66
    ): void {
67
        $this->beConstructedWith([
68
            $firstPromotionEligibilityChecker,
69
            $secondPromotionEligibilityChecker,
70
        ]);
71
72
        $firstPromotionEligibilityChecker->isEligible($promotionSubject, $promotion)->willReturn(false);
73
        $secondPromotionEligibilityChecker->isEligible($promotionSubject, $promotion)->shouldNotBeCalled();
74
75
        $this->isEligible($promotionSubject, $promotion)->shouldReturn(false);
76
    }
77
78
    function it_throws_an_exception_if_no_eligibility_checkers_are_passed(): void
79
    {
80
        $this->beConstructedWith([]);
81
82
        $this->shouldThrow(\InvalidArgumentException::class)->duringInstantiation();
83
    }
84
85
    function it_throws_an_exception_if_passed_array_has_not_only_eligibility_checkers(): void
86
    {
87
        $this->beConstructedWith([new \stdClass()]);
88
89
        $this->shouldThrow(\InvalidArgumentException::class)->duringInstantiation();
90
    }
91
}
92