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 | $modifier = $this->testAddons($this->modifier); |
||
0 ignored issues
–
show
|
|||
46 | $discount = $modifier->discount(); |
||
47 | $this->assertReason($discount); |
||
48 | $this->assertSince($discount); |
||
49 | $this->assertTill($discount); |
||
50 | } |
||
51 | |||
52 | public function testAddons() |
||
53 | { |
||
54 | $modifier = $this->checkReason($this->modifier); |
||
55 | $modifier = $this->checkSince($modifier); |
||
56 | $modifier = $this->checkTill($modifier); |
||
57 | |||
58 | return $modifier; |
||
59 | } |
||
60 | |||
61 | public function testReason() |
||
62 | { |
||
63 | $this->checkReason($this->modifier); |
||
64 | } |
||
65 | |||
66 | public function checkReason(Modifier $modifier) |
||
67 | { |
||
68 | $result = $modifier->reason(self::SOME_TEXT); |
||
69 | $this->assertReason($result); |
||
70 | |||
71 | return $result; |
||
72 | } |
||
73 | |||
74 | public function assertReason(Modifier $modifier) |
||
75 | { |
||
76 | $reason = $modifier->getReason(); |
||
77 | $this->assertInstanceOf(Reason::class, $reason); |
||
78 | $this->assertSame(self::SOME_TEXT, $reason->getValue()); |
||
79 | } |
||
80 | |||
81 | public function testSince() |
||
82 | { |
||
83 | $this->checkSince($this->modifier); |
||
84 | } |
||
85 | |||
86 | public function checkSince(Modifier $modifier) |
||
87 | { |
||
88 | $result = $modifier->since($this->now); |
||
89 | $this->assertSince($result); |
||
90 | |||
91 | return $result; |
||
92 | } |
||
93 | |||
94 | public function assertSince(Modifier $modifier) |
||
95 | { |
||
96 | $since = $modifier->getSince(); |
||
97 | $this->assertInstanceOf(Since::class, $since); |
||
98 | $this->assertSame($this->now, $since->getValue()); |
||
99 | } |
||
100 | |||
101 | public function testTill() |
||
102 | { |
||
103 | $this->checkTill($this->modifier); |
||
104 | } |
||
105 | |||
106 | public function checkTill(Modifier $modifier) |
||
107 | { |
||
108 | $result = $modifier->till($this->now); |
||
109 | $this->assertTill($result); |
||
110 | |||
111 | return $result; |
||
112 | } |
||
113 | |||
114 | public function assertTill(Modifier $modifier) |
||
115 | { |
||
116 | $till = $modifier->getTill(); |
||
117 | $this->assertInstanceOf(Till::class, $till); |
||
118 | $this->assertSame($this->now, $till->getValue()); |
||
119 | } |
||
120 | } |
||
121 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.