GrowingDiscountTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 13
c 1
b 0
f 1
dl 0
loc 21
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A buildDiscount() 0 5 1
A assertCharges() 0 12 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\Charge;
15
use hiqdev\php\billing\charge\modifiers\GrowingDiscount;
16
use hiqdev\php\units\Quantity;
17
18
/**
19
 * @author Andrii Vasyliev <[email protected]>
20
 */
21
class GrowingDiscountTest extends FixedDiscountTest
22
{
23
    protected function buildDiscount($value)
24
    {
25
        $month = (new DateTimeImmutable())->modify('first day of this month midnight');
26
27
        return (new GrowingDiscount($value))->since($month)->every('month')->till('3000-01');
28
    }
29
30
    public function assertCharges($fd, $sum)
31
    {
32
        $action = $this->createAction($this->prepaid->multiply(2));
33
        $charge = $this->calculator->calculateCharge($this->price, $action);
34
        $charges = $fd->modifyCharge($charge, $action);
35
        $this->assertIsArray($charges);
36
        $this->assertSame(2, count($charges));
37
        $this->assertSame($charge, $charges[0]);
38
        $discount = $charges[1];
39
        $this->assertInstanceOf(Charge::class, $discount);
40
        $this->assertEquals(Quantity::items(0), $discount->getUsage());
41
        $this->assertEquals($sum->multiply(-1), $discount->getSum());
42
    }
43
}
44