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

PromotionCouponDurationEligibilityCheckerSpec   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 34
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A it_is_a_promotion_coupon_eligibility_checker() 0 4 1
A it_returns_true_if_promotion_coupon_does_not_expire() 0 8 1
A it_returns_true_if_promotion_coupon_has_not_expired_yet() 0 8 1
A it_returns_false_if_promotion_coupon_has_already_expired() 0 8 1
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 PromotionCouponDurationEligibilityCheckerSpec extends ObjectBehavior
25
{
26
    function it_is_a_promotion_coupon_eligibility_checker(): void
27
    {
28
        $this->shouldImplement(PromotionCouponEligibilityCheckerInterface::class);
29
    }
30
31
    function it_returns_true_if_promotion_coupon_does_not_expire(
32
        PromotionSubjectInterface $promotionSubject,
33
        PromotionCouponInterface $promotionCoupon
34
    ): void {
35
        $promotionCoupon->getExpiresAt()->willReturn(null);
36
37
        $this->isEligible($promotionSubject, $promotionCoupon)->shouldReturn(true);
38
    }
39
40
    function it_returns_true_if_promotion_coupon_has_not_expired_yet(
41
        PromotionSubjectInterface $promotionSubject,
42
        PromotionCouponInterface $promotionCoupon
43
    ): void {
44
        $promotionCoupon->getExpiresAt()->willReturn(new \DateTime('tomorrow'));
45
46
        $this->isEligible($promotionSubject, $promotionCoupon)->shouldReturn(true);
47
    }
48
49
    function it_returns_false_if_promotion_coupon_has_already_expired(
50
        PromotionSubjectInterface $promotionSubject,
51
        PromotionCouponInterface $promotionCoupon
52
    ): void {
53
        $promotionCoupon->getExpiresAt()->willReturn(new \DateTime('yesterday'));
54
55
        $this->isEligible($promotionSubject, $promotionCoupon)->shouldReturn(false);
56
    }
57
}
58