Completed
Push — master ( eebd57...9e79a2 )
by Andrii
07:00
created

FormulaEngineTest::testSimpleLeasing()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 13

Duplication

Lines 16
Ratio 100 %

Importance

Changes 0
Metric Value
dl 16
loc 16
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 13
nc 1
nop 0
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\formula;
12
13
use DateTimeImmutable;
14
use hiqdev\php\billing\charge\modifiers\addons\MonthPeriod;
15
use hiqdev\php\billing\charge\modifiers\addons\Reason;
16
use hiqdev\php\billing\charge\modifiers\addons\Since;
17
use hiqdev\php\billing\charge\modifiers\FixedDiscount;
18
use hiqdev\php\billing\charge\modifiers\Leasing;
19
use hiqdev\php\billing\formula\FormulaEngine;
20
21
/**
22
 * @author Andrii Vasyliev <[email protected]>
23
 */
24
class FormulaEngineTest extends \PHPUnit\Framework\TestCase
25
{
26
    public function setUp()
27
    {
28
        $this->engine = new FormulaEngine();
0 ignored issues
show
Bug introduced by
The property engine does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
29
    }
30
31 View Code Duplication
    public function testSimpleDiscount()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
32
    {
33
        $date = '2018-08-01';
34
        $rate = '2';
35
        $reason = 'test reason';
36
        $formula = $this->engine->build("discount.fixed('$rate%').since('$date').reason('$reason')");
37
38
        $this->assertInstanceOf(FixedDiscount::class, $formula);
39
        $this->assertSame($rate, $formula->getValue()->getValue());
40
        $this->assertTrue($formula->isRelative());
41
        $this->assertInstanceOf(Since::class, $formula->getSince());
42
        $this->assertEquals(new DateTimeImmutable($date), $formula->getSince()->getValue());
43
        $this->assertInstanceOf(Reason::class, $formula->getReason());
44
        $this->assertSame($reason, $formula->getReason()->getValue());
45
        $this->assertNull($formula->getTill());
46
    }
47
48 View Code Duplication
    public function testSimpleLeasing()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
49
    {
50
        $date = '2018-08-01';
51
        $num = 2;
52
        $reason = 'test reason';
53
        $formula = $this->engine->build("leasing.since('$date').lasts('$num months').reason('$reason')");
54
55
        $this->assertInstanceOf(Leasing::class, $formula);
56
        $this->assertInstanceOf(MonthPeriod::class, $formula->getTerm());
57
        $this->assertSame($num, $formula->getTerm()->getValue());
58
        $this->assertInstanceOf(Since::class, $formula->getSince());
59
        $this->assertEquals(new DateTimeImmutable($date), $formula->getSince()->getValue());
60
        $this->assertInstanceOf(Reason::class, $formula->getReason());
61
        $this->assertSame($reason, $formula->getReason()->getValue());
62
        $this->assertNull($formula->getTill());
63
    }
64
}
65