Passed
Pull Request — master (#67)
by
unknown
13:46
created

ProgressivePriceTest::testCalculatePrice()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace hiqdev\php\billing\tests\unit\price;
6
7
use hiqdev\php\billing\price\ProgressivePrice;
8
use hiqdev\php\billing\price\ProgressivePriceThresholdsDto;
0 ignored issues
show
Bug introduced by
The type hiqdev\php\billing\price...ssivePriceThresholdsDto was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use hiqdev\php\billing\target\Target;
10
use hiqdev\php\billing\type\Type;
11
use hiqdev\php\units\Quantity;
12
use Money\Money;
13
use Money\Currency;
14
15
class ProgressivePriceTest extends \PHPUnit\Framework\TestCase
16
{
17
18
    protected ProgressivePrice $price;
19
20
    protected Target $target;
21
22
    protected Type $type;
23
24
    protected Quantity $prepaid;
25
26
27
28
    protected function setUp(): void
29
    {
30
        $this->target = new Target('2222', 'overuse,cdn_traf95_max', 'progressive');
31
        $this->type = new Type('2222', 'cdn_traf95_max');
32
        $this->prepaid = Quantity::mbps(0);
33
        $this->price = new ProgressivePrice('2222', $this->type, $this->target, $this->prepaid, $this->getThresholds());
0 ignored issues
show
Bug introduced by
The call to hiqdev\php\billing\price...ivePrice::__construct() has too few arguments starting with thresholds. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

33
        $this->price = /** @scrutinizer ignore-call */ new ProgressivePrice('2222', $this->type, $this->target, $this->prepaid, $this->getThresholds());

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
Bug introduced by
$this->getThresholds() of type array<integer,hiqdev\php...sivePriceThresholdsDto> is incompatible with the type Money\Money expected by parameter $price of hiqdev\php\billing\price...ivePrice::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

33
        $this->price = new ProgressivePrice('2222', $this->type, $this->target, $this->prepaid, /** @scrutinizer ignore-type */ $this->getThresholds());
Loading history...
34
    }
35
36
    protected function tearDown(): void
37
    {
38
    }
39
40
    public function testCalculateUsage()
41
    {
42
        $this->assertEquals(720, $this->price->calculateUsage(Quantity::mbps(720))->getQuantity());
43
    }
44
45
    public function testCalculatePrice()
46
    {
47
        $this->assertSame(json_encode(Money::EUR(594)), json_encode($this->price->calculatePrice(Quantity::mbps(720))));
48
    }
49
50
    public function testJsonSerialize()
51
    {
52
        $this->assertSame(
53
            json_encode([
54
                'id' => '2222',
55
                'type' => [
56
                    'id' => '2222',
57
                    'name' => 'cdn_traf95_max',
58
                ],
59
                'target' => [
60
                    'id' => '2222',
61
                    'type' => 'overuse,cdn_traf95_max',
62
                    'name' => 'progressive'
63
                ],
64
                'thresholds' => $this->getThresholds(),
65
                'prepaid' => [
66
                    'unit' => 'mbps',
67
                    'quantity' => 0,
68
                ],
69
            ]),
70
            json_encode($this->price));
71
    }
72
73
    private function getThresholds()
74
    {
75
        return [
76
            new ProgressivePriceThresholdsDto(0.0085, new Currency('EUR'), 0),
77
            new ProgressivePriceThresholdsDto(0.0080, new Currency('EUR'), 500),
78
            new ProgressivePriceThresholdsDto(0.0075, new Currency('EUR'), 600),
79
            new ProgressivePriceThresholdsDto(0.0070, new Currency('EUR'), 700),
80
            new ProgressivePriceThresholdsDto(0.0060, new Currency('EUR'), 800),
81
        ];
82
    }
83
}
84