Passed
Pull Request — master (#8)
by Klochok
11:18
created

LeasingTest::testTill()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 4
rs 10
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\MonthPeriod;
15
use hiqdev\php\billing\charge\modifiers\addons\YearPeriod;
16
use hiqdev\php\billing\charge\modifiers\Leasing;
17
use hiqdev\php\billing\price\SinglePrice;
18
use hiqdev\php\billing\tests\unit\action\ActionTest;
19
use hiqdev\php\billing\type\Type;
20
21
/**
22
 * @author Andrii Vasyliev <[email protected]>
23
 */
24
class LeasingTest extends ActionTest
25
{
26
    protected $reason = 'test reason string';
27
28
    protected function setUp()
29
    {
30
        parent::setUp();
31
        $this->type = new Type(Type::ANY, 'monthly,leasing');
32
        $this->price = new SinglePrice(5, $this->type, $this->target, null, $this->prepaid, $this->money);
33
    }
34
35
    protected function buildLeasing($term)
36
    {
37
        $month = (new DateTimeImmutable())->modify('first day of this month midnight');
38
39
        return (new Leasing())->since($month)->lasts($term);
40
    }
41
42
    public function testCreateMonth()
43
    {
44
        $leasing = $this->buildLeasing('12 months');
45
        $period = $leasing->getTerm();
46
        $this->assertInstanceOf(MonthPeriod::class, $period);
47
        $this->assertSame(12, $period->getValue());
48
    }
49
50
    public function testTill()
51
    {
52
        $this->expectException(\Exception::class);
53
        $this->buildLeasing('month')->till('08.2018');
54
    }
55
56
    public function testReason()
57
    {
58
        $leasing = $this->buildLeasing('12 months');
59
        $leasing = $leasing->reason($this->reason);
60
        $this->assertSame($this->reason, $leasing->getReason()->getValue());
61
    }
62
63
    public function testCreateYear()
64
    {
65
        $leasing = $this->buildLeasing('1 year');
66
        $period = $leasing->getTerm();
67
        $this->assertInstanceOf(YearPeriod::class, $period);
68
        $this->assertSame(1, $period->getValue());
69
    }
70
71
    public function testModifyCharge()
72
    {
73
        $leasing = $this->buildLeasing('6 months');
74
        $action = $this->createAction($this->prepaid->multiply(2));
75
        $charge = $this->calculator->calculateCharge($this->price, $action);
76
        $charges = $leasing->modifyCharge($charge, $action);
77
        $this->assertInternalType('array', $charges);
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit\Framework\Assert::assertInternalType() has been deprecated: https://github.com/sebastianbergmann/phpunit/issues/3369 ( Ignorable by Annotation )

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

77
        /** @scrutinizer ignore-deprecated */ $this->assertInternalType('array', $charges);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
78
        $this->assertSame(1, count($charges));
79
        $this->assertEquals($charge, $charges[0]);
80
    }
81
}
82