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
|
|
|
|