Completed
Push — master ( 865c46...71786e )
by Andrii
02:06
created

FixedDiscountTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 21
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
A testCreateAbsolute() 7 7 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-2018, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\php\billing\tests\unit\charge\modifiers;
12
13
use hiqdev\php\billing\charge\Charge;
14
use hiqdev\php\billing\charge\modifiers\FixedDiscount;
15
use hiqdev\php\billing\tests\unit\action\ActionTest;
16
use hiqdev\php\units\Quantity;
17
use Money\Money;
18
19
/**
20
 * @author Andrii Vasyliev <[email protected]>
21
 */
22
class FixedDiscountTest extends ActionTest
23
{
24
    protected function setUp()
25
    {
26
        parent::setUp();
27
        $this->value = Money::USD(1000);
28
        $this->rate = 10;
29
    }
30
31 View Code Duplication
    public function testCreateAbsolute()
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
        $abs = new FixedDiscount($this->value);
34
        $this->assertSame($this->value, $abs->getValue());
35
        $this->assertTrue($abs->isAbsolute());
36
        $this->assertFalse($abs->isRelative());
37
    }
38
39 View Code Duplication
    public function testCreateRelative()
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...
40
    {
41
        $rel = new FixedDiscount($this->rate);
42
        $this->assertSame($this->rate, $rel->getValue());
43
        $this->assertTrue($rel->isRelative());
44
        $this->assertFalse($rel->isAbsolute());
45
    }
46
47
    public function testAbsModifyCharge()
48
    {
49
        $abs = new FixedDiscount($this->value);
50
        $this->assertFixedDiscountCharges($abs, $this->value);
51
    }
52
53
    public function testRelModifyCharge()
54
    {
55
        $rel = new FixedDiscount($this->rate);
56
        $this->assertFixedDiscountCharges($rel, $this->value);
57
    }
58
59
    public function assertFixedDiscountCharges($fd, $sum)
60
    {
61
        $action = $this->createAction($this->prepaid->multiply(2));
62
        $charge = $action->calculateCharge($this->price);
63
        $charges = $fd->modifyCharge($charge, $action);
64
        $this->assertInternalType('array', $charges);
65
        $this->assertSame(2, count($charges));
66
        $this->assertSame($charge, $charges[0]);
67
        $discount = $charges[1];
68
        $this->assertInstanceOf(Charge::class, $discount);
69
        $this->assertEquals(Quantity::items(1), $discount->getUsage());
70
        $this->assertEquals($sum, $discount->getSum());
71
    }
72
}
73