|
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
|
|
|
declare(strict_types=1); |
|
13
|
|
|
|
|
14
|
|
|
namespace spec\Sylius\Component\Promotion\Checker\Eligibility; |
|
15
|
|
|
|
|
16
|
|
|
use PhpSpec\ObjectBehavior; |
|
17
|
|
|
use Sylius\Component\Promotion\Checker\Eligibility\PromotionCouponEligibilityCheckerInterface; |
|
18
|
|
|
use Sylius\Component\Promotion\Model\PromotionCouponInterface; |
|
19
|
|
|
use Sylius\Component\Promotion\Model\PromotionSubjectInterface; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @author Kamil Kokot <[email protected]> |
|
23
|
|
|
*/ |
|
24
|
|
|
final class CompositePromotionCouponEligibilityCheckerSpec extends ObjectBehavior |
|
25
|
|
|
{ |
|
26
|
|
|
function let(PromotionCouponEligibilityCheckerInterface $promotionCouponEligibilityChecker): void |
|
27
|
|
|
{ |
|
28
|
|
|
$this->beConstructedWith([$promotionCouponEligibilityChecker]); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
function it_is_a_promotion_eligibility_checker(): void |
|
32
|
|
|
{ |
|
33
|
|
|
$this->shouldImplement(PromotionCouponEligibilityCheckerInterface::class); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
function it_returns_true_if_all_eligibility_checker_returns_true( |
|
37
|
|
|
PromotionCouponEligibilityCheckerInterface $firstPromotionCouponEligibilityChecker, |
|
38
|
|
|
PromotionCouponEligibilityCheckerInterface $secondPromotionCouponEligibilityChecker, |
|
39
|
|
|
PromotionSubjectInterface $promotionSubject, |
|
40
|
|
|
PromotionCouponInterface $promotionCoupon |
|
41
|
|
|
): void { |
|
42
|
|
|
$this->beConstructedWith([ |
|
43
|
|
|
$firstPromotionCouponEligibilityChecker, |
|
44
|
|
|
$secondPromotionCouponEligibilityChecker, |
|
45
|
|
|
]); |
|
46
|
|
|
|
|
47
|
|
|
$firstPromotionCouponEligibilityChecker->isEligible($promotionSubject, $promotionCoupon)->willReturn(true); |
|
48
|
|
|
$secondPromotionCouponEligibilityChecker->isEligible($promotionSubject, $promotionCoupon)->willReturn(true); |
|
49
|
|
|
|
|
50
|
|
|
$this->isEligible($promotionSubject, $promotionCoupon)->shouldReturn(true); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
function it_returns_false_if_any_eligibility_checker_returns_false( |
|
54
|
|
|
PromotionCouponEligibilityCheckerInterface $firstPromotionCouponEligibilityChecker, |
|
55
|
|
|
PromotionCouponEligibilityCheckerInterface $secondPromotionCouponEligibilityChecker, |
|
56
|
|
|
PromotionSubjectInterface $promotionSubject, |
|
57
|
|
|
PromotionCouponInterface $promotionCoupon |
|
58
|
|
|
): void { |
|
59
|
|
|
$this->beConstructedWith([ |
|
60
|
|
|
$firstPromotionCouponEligibilityChecker, |
|
61
|
|
|
$secondPromotionCouponEligibilityChecker, |
|
62
|
|
|
]); |
|
63
|
|
|
|
|
64
|
|
|
$firstPromotionCouponEligibilityChecker->isEligible($promotionSubject, $promotionCoupon)->willReturn(true); |
|
65
|
|
|
$secondPromotionCouponEligibilityChecker->isEligible($promotionSubject, $promotionCoupon)->willReturn(false); |
|
66
|
|
|
|
|
67
|
|
|
$this->isEligible($promotionSubject, $promotionCoupon)->shouldReturn(false); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
function it_stops_checking_at_the_first_failing_eligibility_checker( |
|
71
|
|
|
PromotionCouponEligibilityCheckerInterface $firstPromotionCouponEligibilityChecker, |
|
72
|
|
|
PromotionCouponEligibilityCheckerInterface $secondPromotionCouponEligibilityChecker, |
|
73
|
|
|
PromotionSubjectInterface $promotionSubject, |
|
74
|
|
|
PromotionCouponInterface $promotionCoupon |
|
75
|
|
|
): void { |
|
76
|
|
|
$this->beConstructedWith([ |
|
77
|
|
|
$firstPromotionCouponEligibilityChecker, |
|
78
|
|
|
$secondPromotionCouponEligibilityChecker, |
|
79
|
|
|
]); |
|
80
|
|
|
|
|
81
|
|
|
$firstPromotionCouponEligibilityChecker->isEligible($promotionSubject, $promotionCoupon)->willReturn(false); |
|
82
|
|
|
$secondPromotionCouponEligibilityChecker->isEligible($promotionSubject, $promotionCoupon)->shouldNotBeCalled(); |
|
83
|
|
|
|
|
84
|
|
|
$this->isEligible($promotionSubject, $promotionCoupon)->shouldReturn(false); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
function it_throws_an_exception_if_no_eligibility_checkers_are_passed(): void |
|
88
|
|
|
{ |
|
89
|
|
|
$this->beConstructedWith([]); |
|
90
|
|
|
|
|
91
|
|
|
$this->shouldThrow(\InvalidArgumentException::class)->duringInstantiation(); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
function it_throws_an_exception_if_passed_array_has_not_only_eligibility_checkers(): void |
|
95
|
|
|
{ |
|
96
|
|
|
$this->beConstructedWith([new \stdClass()]); |
|
97
|
|
|
|
|
98
|
|
|
$this->shouldThrow(\InvalidArgumentException::class)->duringInstantiation(); |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|