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\Checker\Eligibility\PromotionEligibilityCheckerInterface; |
19
|
|
|
use Sylius\Component\Promotion\Model\PromotionCouponAwarePromotionSubjectInterface; |
20
|
|
|
use Sylius\Component\Promotion\Model\PromotionCouponInterface; |
21
|
|
|
use Sylius\Component\Promotion\Model\PromotionInterface; |
22
|
|
|
use Sylius\Component\Promotion\Model\PromotionSubjectInterface; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @author Mateusz Zalewski <[email protected]> |
26
|
|
|
*/ |
27
|
|
|
final class PromotionSubjectCouponEligibilityCheckerSpec extends ObjectBehavior |
28
|
|
|
{ |
29
|
|
|
function let(PromotionCouponEligibilityCheckerInterface $promotionCouponEligibilityChecker): void |
30
|
|
|
{ |
31
|
|
|
$this->beConstructedWith($promotionCouponEligibilityChecker); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
function it_implements_a_promotion_eligibility_checker_interface(): void |
35
|
|
|
{ |
36
|
|
|
$this->shouldImplement(PromotionEligibilityCheckerInterface::class); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
function it_returns_true_if_subject_coupons_are_eligible_to_promotion( |
40
|
|
|
PromotionCouponEligibilityCheckerInterface $promotionCouponEligibilityChecker, |
41
|
|
|
PromotionCouponAwarePromotionSubjectInterface $promotionSubject, |
42
|
|
|
PromotionInterface $promotion, |
43
|
|
|
PromotionCouponInterface $promotionCoupon |
44
|
|
|
): void { |
45
|
|
|
$promotion->isCouponBased()->willReturn(true); |
46
|
|
|
|
47
|
|
|
$promotionSubject->getPromotionCoupon()->willReturn($promotionCoupon); |
48
|
|
|
$promotionCoupon->getPromotion()->willReturn($promotion); |
49
|
|
|
|
50
|
|
|
$promotionCouponEligibilityChecker->isEligible($promotionSubject, $promotionCoupon)->willReturn(true); |
51
|
|
|
|
52
|
|
|
$this->isEligible($promotionSubject, $promotion)->shouldReturn(true); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
function it_returns_false_if_subject_is_not_coupon_aware( |
56
|
|
|
PromotionSubjectInterface $promotionSubject, |
57
|
|
|
PromotionInterface $promotion |
58
|
|
|
): void { |
59
|
|
|
$promotion->isCouponBased()->willReturn(true); |
60
|
|
|
|
61
|
|
|
$this->isEligible($promotionSubject, $promotion)->shouldReturn(false); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
function it_returns_false_if_subject_has_no_coupon( |
65
|
|
|
PromotionCouponAwarePromotionSubjectInterface $promotionSubject, |
66
|
|
|
PromotionInterface $promotion |
67
|
|
|
): void { |
68
|
|
|
$promotion->isCouponBased()->willReturn(true); |
69
|
|
|
|
70
|
|
|
$promotionSubject->getPromotionCoupon()->willReturn(null); |
71
|
|
|
|
72
|
|
|
$this->isEligible($promotionSubject, $promotion)->shouldReturn(false); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
function it_returns_false_if_subject_coupons_comes_from_an_another_promotion( |
76
|
|
|
PromotionCouponAwarePromotionSubjectInterface $promotionSubject, |
77
|
|
|
PromotionInterface $promotion, |
78
|
|
|
PromotionInterface $otherPromotion, |
79
|
|
|
PromotionCouponInterface $promotionCoupon |
80
|
|
|
): void { |
81
|
|
|
$promotion->isCouponBased()->willReturn(true); |
82
|
|
|
|
83
|
|
|
$promotionSubject->getPromotionCoupon()->willReturn($promotionCoupon); |
84
|
|
|
$promotionCoupon->getPromotion()->willReturn($otherPromotion); |
85
|
|
|
|
86
|
|
|
$this->isEligible($promotionSubject, $promotion)->shouldReturn(false); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
function it_returns_false_if_subject_coupons_is_not_eligible( |
90
|
|
|
PromotionCouponEligibilityCheckerInterface $promotionCouponEligibilityChecker, |
91
|
|
|
PromotionCouponAwarePromotionSubjectInterface $promotionSubject, |
92
|
|
|
PromotionInterface $promotion, |
93
|
|
|
PromotionCouponInterface $promotionCoupon |
94
|
|
|
): void { |
95
|
|
|
$promotion->isCouponBased()->willReturn(true); |
96
|
|
|
|
97
|
|
|
$promotionSubject->getPromotionCoupon()->willReturn($promotionCoupon); |
98
|
|
|
$promotionCoupon->getPromotion()->willReturn($promotion); |
99
|
|
|
|
100
|
|
|
$promotionCouponEligibilityChecker->isEligible($promotionSubject, $promotionCoupon)->willReturn(false); |
101
|
|
|
|
102
|
|
|
$this->isEligible($promotionSubject, $promotion)->shouldReturn(false); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|