Passed
Pull Request — master (#62)
by
unknown
13:12
created

InstallmentTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 29
dl 0
loc 58
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testReason() 0 5 1
A testTill() 0 4 1
A testModifyCharge() 0 11 1
A testCreateYear() 0 6 1
A testCreateMonth() 0 6 1
A setUp() 0 5 1
A buildInstallment() 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\MonthPeriod;
15
use hiqdev\php\billing\charge\modifiers\addons\YearPeriod;
16
use hiqdev\php\billing\charge\modifiers\event\InstallmentWasStarted;
17
use hiqdev\php\billing\charge\modifiers\Leasing;
0 ignored issues
show
Bug introduced by
The type hiqdev\php\billing\charge\modifiers\Leasing was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
use hiqdev\php\billing\price\SinglePrice;
19
use hiqdev\php\billing\tests\unit\action\ActionTest;
20
use hiqdev\php\billing\type\Type;
21
22
/**
23
 * @author Andrii Vasyliev <[email protected]>
24
 */
25
class InstallmentTest extends ActionTest
26
{
27
    protected $reason = 'test reason string';
28
29
    protected function setUp(): void
30
    {
31
        parent::setUp();
32
        $this->type = new Type(Type::ANY, 'monthly,installment');
33
        $this->price = new SinglePrice(5, $this->type, $this->target, null, $this->prepaid, $this->money);
34
    }
35
36
    protected function buildInstallment($term)
37
    {
38
        $month = (new DateTimeImmutable())->modify('first day of this month midnight');
39
40
        return (new Installment())->since($month)->lasts($term);
41
    }
42
43
    public function testCreateMonth()
44
    {
45
        $installment = $this->buildInstallment('12 months');
46
        $period = $installment->getTerm();
47
        $this->assertInstanceOf(MonthPeriod::class, $period);
48
        $this->assertSame(12, $period->getValue());
49
    }
50
51
    public function testTill()
52
    {
53
        $this->expectException(\Exception::class);
54
        $this->buildInstallment('month')->till('08.2024');
55
    }
56
57
    public function testReason()
58
    {
59
        $installment = $this->buildInstallment('12 months');
60
        $installment = $installment->reason($this->reason);
61
        $this->assertSame($this->reason, $installment->getReason()->getValue());
62
    }
63
64
    public function testCreateYear()
65
    {
66
        $installment = $this->buildInstallment('1 year');
67
        $period = $installment->getTerm();
68
        $this->assertInstanceOf(YearPeriod::class, $period);
69
        $this->assertSame(1, $period->getValue());
70
    }
71
72
    public function testModifyCharge()
73
    {
74
        $installment = $this->buildInstallment('6 months');
75
        $action = $this->createAction($this->prepaid->multiply(2));
76
        $charge = $this->calculator->calculateCharge($this->price, $action);
77
        $charges = $installment->modifyCharge($charge, $action);
78
        $event = $charges[0]->releaseEvents()[0];
79
        $this->assertInstanceOf(InstallmentWasStarted::class, $event);
80
        $this->assertIsArray($charges);
81
        $this->assertSame(1, count($charges));
82
        $this->assertEquals($charge, $charges[0]);
83
    }
84
}
85