Passed
Pull Request — master (#99)
by
unknown
02:46
created

ModifierTest   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 39
c 1
b 0
f 1
dl 0
loc 96
rs 10
wmc 13
1
<?php
2
/**
3
 * PHP Billing Library
4
 *
5
 * @link      https://github.com/hiqdev/php-billing
6
 * @package   php-billing
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2017-2020, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\php\billing\tests\unit\charge\modifiers;
12
13
use DateTimeImmutable;
14
use hiqdev\php\billing\charge\modifiers\addons\Reason;
15
use hiqdev\php\billing\charge\modifiers\addons\Since;
16
use hiqdev\php\billing\charge\modifiers\addons\Till;
17
use hiqdev\php\billing\charge\modifiers\Discount;
18
use hiqdev\php\billing\charge\modifiers\Modifier;
19
20
/**
21
 * @author Andrii Vasyliev <[email protected]>
22
 */
23
class ModifierTest extends \PHPUnit\Framework\TestCase
24
{
25
    private DateTimeImmutable $now;
26
27
    protected Modifier $modifier;
28
29
    const SOME_TEXT = 'some text';
30
31
    protected function setUp(): void
32
    {
33
        parent::setUp();
34
        $this->now = new DateTimeImmutable();
35
        $this->modifier = new Modifier();
36
    }
37
38
    public function testDiscount()
39
    {
40
        $discount = $this->modifier->discount();
41
        $this->assertTrue($discount !== $this->modifier);
42
        $this->assertInstanceOf(Discount::class, $discount);
43
    }
44
45
    public function testAddonsCopied()
46
    {
47
        $modifier = $this->testAddons($this->modifier);
48
        $discount = $modifier->discount();
49
        $this->assertReason($discount);
50
        $this->assertSince($discount);
51
        $this->assertTill($discount);
52
    }
53
54
    public function testAddons()
55
    {
56
        $modifier = $this->checkReason($this->modifier);
57
        $modifier = $this->checkSince($modifier);
58
        $modifier = $this->checkTill($modifier);
59
60
        return $modifier;
61
    }
62
63
    public function testReason()
64
    {
65
        $this->checkReason($this->modifier);
66
    }
67
68
    public function checkReason(Modifier $modifier)
69
    {
70
        $result = $modifier->reason(self::SOME_TEXT);
71
        $this->assertReason($result);
72
73
        return $result;
74
    }
75
76
    public function assertReason(Modifier $modifier)
77
    {
78
        $reason = $modifier->getReason();
79
        $this->assertInstanceOf(Reason::class, $reason);
80
        $this->assertSame(self::SOME_TEXT, $reason->getValue());
81
    }
82
83
    public function testSince()
84
    {
85
        $this->checkSince($this->modifier);
86
    }
87
88
    public function checkSince(Modifier $modifier)
89
    {
90
        $result = $modifier->since($this->now);
91
        $this->assertSince($result);
92
93
        return $result;
94
    }
95
96
    public function assertSince(Modifier $modifier)
97
    {
98
        $since = $modifier->getSince();
99
        $this->assertInstanceOf(Since::class, $since);
100
        $this->assertSame($this->now, $since->getValue());
101
    }
102
103
    public function testTill()
104
    {
105
        $this->checkTill($this->modifier);
106
    }
107
108
    public function checkTill(Modifier $modifier)
109
    {
110
        $result = $modifier->till($this->now);
111
        $this->assertTill($result);
112
113
        return $result;
114
    }
115
116
    public function assertTill(Modifier $modifier)
117
    {
118
        $till = $modifier->getTill();
119
        $this->assertInstanceOf(Till::class, $till);
120
        $this->assertSame($this->now, $till->getValue());
121
    }
122
}
123