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

PromotionCouponUsageLimitEligibilityCheckerSpec   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 36
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_usage_limit_is_not_defined() 0 8 1
A it_returns_true_if_usage_limit_has_not_been_reached_yet() 0 9 1
A it_returns_false_if_usage_limit_has_been_reached() 0 9 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 PromotionCouponUsageLimitEligibilityCheckerSpec 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_usage_limit_is_not_defined(
32
        PromotionSubjectInterface $promotionSubject,
33
        PromotionCouponInterface $promotionCoupon
34
    ): void {
35
        $promotionCoupon->getUsageLimit()->willReturn(null);
36
37
        $this->isEligible($promotionSubject, $promotionCoupon)->shouldReturn(true);
38
    }
39
40
    function it_returns_true_if_usage_limit_has_not_been_reached_yet(
41
        PromotionSubjectInterface $promotionSubject,
42
        PromotionCouponInterface $promotionCoupon
43
    ): void {
44
        $promotionCoupon->getUsageLimit()->willReturn(42);
45
        $promotionCoupon->getUsed()->willReturn(41);
46
47
        $this->isEligible($promotionSubject, $promotionCoupon)->shouldReturn(true);
48
    }
49
50
    function it_returns_false_if_usage_limit_has_been_reached(
51
        PromotionSubjectInterface $promotionSubject,
52
        PromotionCouponInterface $promotionCoupon
53
    ): void {
54
        $promotionCoupon->getUsageLimit()->willReturn(42);
55
        $promotionCoupon->getUsed()->willReturn(42);
56
57
        $this->isEligible($promotionSubject, $promotionCoupon)->shouldReturn(false);
58
    }
59
}
60