Completed
Push — master ( f0c93a...888950 )
by Andrii
05:26
created

FormulaEngineTest::testSimpleDiscount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
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\Reason;
15
use hiqdev\php\billing\charge\modifiers\addons\Since;
16
use hiqdev\php\billing\charge\modifiers\FixedDiscount;
17
use hiqdev\php\billing\formula\FormulaEngine;
18
19
/**
20
 * @author Andrii Vasyliev <[email protected]>
21
 */
22
class FormulaEngineTest extends \PHPUnit\Framework\TestCase
23
{
24
    public function setUp()
25
    {
26
        $this->engine = new FormulaEngine();
27
    }
28
29
    public function testSimpleDiscount()
30
    {
31
        $date = '2018-08-01';
32
        $rate = '2';
33
        $reason = 'test reason';
34
        $formula = $this->engine->build("discount.fixed('$rate%').since('$date').reason('$reason')");
35
36
        $this->assertInstanceOf(FixedDiscount::class, $formula);
37
        $this->assertSame($rate, $formula->getValue());
38
        $this->assertTrue($formula->isRelative());
39
        $this->assertInstanceOf(Since::class, $formula->getSince());
40
        $this->assertEquals(new DateTimeImmutable($date), $formula->getSince()->getValue());
41
        $this->assertInstanceOf(Reason::class, $formula->getReason());
42
        $this->assertSame($reason, $formula->getReason()->getValue());
43
        $this->assertNull($formula->getTill());
44
    }
45
}
46