ModifierTest   A
last analyzed

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

13 Methods

Rating   Name   Duplication   Size   Complexity  
A testTill() 0 3 1
A testReason() 0 3 1
A testSince() 0 3 1
A checkReason() 0 6 1
A assertSince() 0 5 1
A checkSince() 0 6 1
A assertTill() 0 5 1
A checkTill() 0 6 1
A setUp() 0 5 1
A assertReason() 0 5 1
A testAddons() 0 7 1
A testAddonsCopied() 0 7 1
A testDiscount() 0 5 1
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
    protected $modifier;
26
27
    const SOME_TEXT = 'some text';
28
29
    protected function setUp(): void
30
    {
31
        parent::setUp();
32
        $this->now = new DateTimeImmutable();
0 ignored issues
show
Bug Best Practice introduced by
The property now does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
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
Unused Code introduced by
The call to hiqdev\php\billing\tests...ifierTest::testAddons() has too many arguments starting with $this->modifier. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

45
        /** @scrutinizer ignore-call */ 
46
        $modifier = $this->testAddons($this->modifier);

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.

Loading history...
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