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\tests\unit\action\ActionTest; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @author Andrii Vasyliev <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class LeasingTest extends ActionTest |
23
|
|
|
{ |
24
|
|
|
protected $reason = 'test reason string'; |
25
|
|
|
|
26
|
|
|
protected function buildLeasing($term) |
27
|
|
|
{ |
28
|
|
|
$month = (new DateTimeImmutable())->modify('first day of this month midnight'); |
29
|
|
|
|
30
|
|
|
return (new Leasing())->since($month)->lasts($term); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
View Code Duplication |
public function testCreateMonth() |
|
|
|
|
34
|
|
|
{ |
35
|
|
|
$leasing = $this->buildLeasing('12 months'); |
36
|
|
|
$period = $leasing->getTerm(); |
37
|
|
|
$this->assertInstanceOf(MonthPeriod::class, $period); |
38
|
|
|
$this->assertSame(12, $period->getValue()); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function testTill() |
42
|
|
|
{ |
43
|
|
|
$this->expectException(\Exception::class); |
44
|
|
|
$this->buildLeasing('month')->till('08.2018'); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testReason() |
48
|
|
|
{ |
49
|
|
|
$leasing = $this->buildLeasing('12 months'); |
50
|
|
|
$this->assertSame($leasing, $leasing->reason($this->reason)); |
51
|
|
|
$this->assertSame($this->reason, $leasing->getReason()->getValue()); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
View Code Duplication |
public function testCreateYear() |
|
|
|
|
55
|
|
|
{ |
56
|
|
|
$leasing = $this->buildLeasing('1 year'); |
57
|
|
|
$period = $leasing->getTerm(); |
58
|
|
|
$this->assertInstanceOf(YearPeriod::class, $period); |
59
|
|
|
$this->assertSame(1, $period->getValue()); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function testModifyCharge() |
63
|
|
|
{ |
64
|
|
|
$leasing = $this->buildLeasing('6 months'); |
65
|
|
|
$action = $this->createAction($this->prepaid->multiply(2)); |
|
|
|
|
66
|
|
|
$charge = $action->calculateCharge($this->price); |
67
|
|
|
$charges = $leasing->modifyCharge($charge, $action); |
|
|
|
|
68
|
|
|
$this->assertInternalType('array', $charges); |
69
|
|
|
$this->assertSame(1, count($charges)); |
70
|
|
|
$this->assertEquals($charge, $charges[0]); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.