Completed
Push — master ( f56bff...fdb40a )
by Andrii
02:24
created

CalculatorTest::setUp()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.2
c 0
b 0
f 0
cc 4
eloc 10
nc 4
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, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\php\billing\tests\unit\order;
12
13
use hiqdev\php\billing\tests\unit\plan\PlanTest;
14
use hiqdev\php\billing\tests\unit\plan\SimplePlanRepository;
15
use hiqdev\php\billing\action\SimpleAction;
16
use hiqdev\php\billing\charge\Charge;
17
use hiqdev\php\billing\order\Calculator;
18
use hiqdev\php\billing\order\Order;
19
use hiqdev\php\units\Quantity;
20
21
class CalculatorTest extends PlanTest
22
{
23
    protected function setUp()
24
    {
25
        parent::setUp();
26
        $this->repository = new SimplePlanRepository($this->plan);
27
        $this->calculator = new Calculator($this->repository);
28
        $actions = [];
29
        foreach ($this->plan->types as $type) {
30
            foreach ($this->plan->targets as $target) {
31
                foreach ([1, 2, 3] as $years) {
32
                    $actions[] = new SimpleAction(null, $type, $target, Quantity::year($years));
33
                }
34
            }
35
        }
36
        $this->order = new Order(null, $this->plan->customer, $actions);
37
    }
38
39
    public function testCalculateCharges()
40
    {
41
        $charges = $this->calculator->calculateCharges($this->order);
42
        foreach ($this->order->getActions() as $actionKey => $action) {
43
            $this->checkCharges($action, $charges[$actionKey]);
44
        }
45
    }
46
}
47