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-2018, 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
|
|
|
protected $modifier; |
26
|
|
|
|
27
|
|
|
const SOME_TEXT = 'some text'; |
28
|
|
|
|
29
|
|
|
protected function setUp() |
30
|
|
|
{ |
31
|
|
|
parent::setUp(); |
32
|
|
|
$this->now = new DateTimeImmutable(); |
33
|
|
|
$this->modifier = new Modifier(); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function testDiscount() |
37
|
|
|
{ |
38
|
|
|
$discount = $this->modifier->discount(); |
39
|
|
|
$this->assertTrue($discount !== $this->modifier); |
40
|
|
|
$this->assertInstanceOf(Discount::class, $discount); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testAddonsCopied() |
44
|
|
|
{ |
45
|
|
|
$this->testAddons(); |
46
|
|
|
$discount = $this->modifier->discount(); |
47
|
|
|
$this->assertReason($discount); |
48
|
|
|
$this->assertSince($discount); |
49
|
|
|
$this->assertTill($discount); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function testAddons() |
53
|
|
|
{ |
54
|
|
|
$this->checkReason(); |
55
|
|
|
$this->checkSince(); |
56
|
|
|
$this->checkTill(); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function testReason() |
60
|
|
|
{ |
61
|
|
|
$this->checkReason(); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function checkReason() |
65
|
|
|
{ |
66
|
|
|
$result = $this->modifier->reason(self::SOME_TEXT); |
67
|
|
|
$this->assertSame($this->modifier, $result); |
68
|
|
|
$this->assertReason($this->modifier); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function assertReason($modifier) |
72
|
|
|
{ |
73
|
|
|
$reason = $modifier->getReason(); |
74
|
|
|
$this->assertInstanceOf(Reason::class, $reason); |
75
|
|
|
$this->assertSame(self::SOME_TEXT, $reason->getValue()); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function testSince() |
79
|
|
|
{ |
80
|
|
|
$this->checkSince(); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function checkSince() |
84
|
|
|
{ |
85
|
|
|
$result = $this->modifier->since($this->now); |
86
|
|
|
$this->assertSame($this->modifier, $result); |
87
|
|
|
$this->assertSince($this->modifier); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function assertSince(Modifier $modifier) |
91
|
|
|
{ |
92
|
|
|
$since = $modifier->getSince(); |
93
|
|
|
$this->assertInstanceOf(Since::class, $since); |
94
|
|
|
$this->assertSame($this->now, $since->getValue()); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function testTill() |
98
|
|
|
{ |
99
|
|
|
$this->checkTill(); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function checkTill() |
103
|
|
|
{ |
104
|
|
|
$result = $this->modifier->till($this->now); |
105
|
|
|
$this->assertSame($this->modifier, $result); |
106
|
|
|
$this->assertTill($this->modifier); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
public function assertTill(Modifier $modifier) |
110
|
|
|
{ |
111
|
|
|
$till = $modifier->getTill(); |
112
|
|
|
$this->assertInstanceOf(Till::class, $till); |
113
|
|
|
$this->assertSame($this->now, $till->getValue()); |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|