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

it_is_initializable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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\PromotionEligibilityCheckerInterface;
18
use Sylius\Component\Promotion\Model\PromotionInterface;
19
use Sylius\Component\Promotion\Model\PromotionSubjectInterface;
20
21
/**
22
 * @author Mateusz Zalewski <[email protected]>
23
 */
24
final class PromotionDurationEligibilityCheckerSpec extends ObjectBehavior
25
{
26
    function it_implements_a_promotion_eligibility_checker_interface(): void
27
    {
28
        $this->shouldImplement(PromotionEligibilityCheckerInterface::class);
29
    }
30
31
    function it_returns_false_if_promotion_has_not_started_yet(
32
        PromotionSubjectInterface $promotionSubject,
33
        PromotionInterface $promotion
34
    ): void {
35
        $promotion->getStartsAt()->willReturn(new \DateTime('+3 days'));
36
37
        $this->isEligible($promotionSubject, $promotion)->shouldReturn(false);
38
    }
39
40
    function it_returns_false_if_promotion_has_already_ended(
41
        PromotionSubjectInterface $promotionSubject,
42
        PromotionInterface $promotion
43
    ): void {
44
        $promotion->getStartsAt()->willReturn(new \DateTime('-5 days'));
45
        $promotion->getEndsAt()->willReturn(new \DateTime('-3 days'));
46
47
        $this->isEligible($promotionSubject, $promotion)->shouldReturn(false);
48
    }
49
50
    function it_returns_true_if_promotion_is_currently_available(
51
        PromotionSubjectInterface $promotionSubject,
52
        PromotionInterface $promotion
53
    ): void {
54
        $promotion->getStartsAt()->willReturn(new \DateTime('-2 days'));
55
        $promotion->getEndsAt()->willReturn(new \DateTime('+2 days'));
56
57
        $this->isEligible($promotionSubject, $promotion)->shouldReturn(true);
58
    }
59
60
    function it_returns_true_if_promotion_dates_are_not_specified(
61
        PromotionSubjectInterface $promotionSubject,
62
        PromotionInterface $promotion
63
    ): void {
64
        $promotion->getStartsAt()->willReturn(null);
65
        $promotion->getEndsAt()->willReturn(null);
66
67
        $this->isEligible($promotionSubject, $promotion)->shouldReturn(true);
68
    }
69
}
70