Passed
Push — master ( 54e3cc...a9003e )
by Dmitry
14:11
created

ProgressivePriceThresholdTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 26
c 1
b 0
f 0
dl 0
loc 44
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testCreateFromObjects() 0 13 1
A testCreateFromScalar() 0 18 1
A scalarsDataProvider() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace hiqdev\php\billing\tests\unit\price;
6
7
use Generator;
8
use hiqdev\php\billing\Money\MultipliedMoney;
9
use hiqdev\php\billing\price\ProgressivePriceThreshold;
10
use hiqdev\php\units\Quantity;
11
use Money\Currency;
12
use Money\Money;
13
use PHPUnit\Framework\TestCase;
14
15
/**
16
 * Class ProgressivePriceThresholdTest
17
 *
18
 * @author Dmytro Naumenko <[email protected]>
19
 * @covers \hiqdev\php\billing\price\ProgressivePriceThreshold
20
 */
21
class ProgressivePriceThresholdTest extends TestCase
22
{
23
    /**
24
     * @dataProvider scalarsDataProvider
25
     */
26
    public function testCreateFromScalar(string $price, string $currency, string $quantity, string $unit): void
27
    {
28
        $threshold = ProgressivePriceThreshold::createFromScalar($price, $currency, $quantity, $unit);
29
        $this->assertSame($price, $threshold->getRawPrice());
0 ignored issues
show
Bug introduced by
The method assertSame() does not exist on hiqdev\php\billing\tests...ssivePriceThresholdTest. ( Ignorable by Annotation )

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

29
        $this->/** @scrutinizer ignore-call */ 
30
               assertSame($price, $threshold->getRawPrice());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
30
        $this->assertSame($unit, $threshold->quantity()->getUnit()->getName());
31
        $this->assertSame($unit, $threshold->unit()->getName());
32
        $this->assertSame($quantity, $threshold->quantity()->getQuantity());
33
        $this->assertSame([
34
            'price' => $price,
35
            'currency' => $currency,
36
            'quantity' => $quantity,
37
            'unit' => $unit,
38
        ], $threshold->__toArray());
39
40
        $this->assertSame($currency, $threshold->price()->getCurrency()->getCode());
41
        $this->assertInstanceOf(MultipliedMoney::class, $threshold->price());
0 ignored issues
show
Bug introduced by
The method assertInstanceOf() does not exist on hiqdev\php\billing\tests...ssivePriceThresholdTest. ( Ignorable by Annotation )

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

41
        $this->/** @scrutinizer ignore-call */ 
42
               assertInstanceOf(MultipliedMoney::class, $threshold->price());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
42
43
        $this->assertSame(json_encode($threshold->__toArray()), json_encode($threshold));
44
    }
45
46
    public function testCreateFromObjects(): void
47
    {
48
        $threshold = ProgressivePriceThreshold::createFromObjects(
49
            new Money(1022, new Currency('USD')),
50
            Quantity::create('items', 2)
51
        );
52
53
        $this->assertSame([
54
            'price' => '10.22',
55
            'currency' => 'USD',
56
            'quantity' => '2',
57
            'unit' => 'items',
58
        ], $threshold->__toArray());
59
    }
60
61
    public function scalarsDataProvider(): Generator
62
    {
63
        yield ['10', 'USD', '20', 'gpbs'];
64
        yield ['10.24', 'EUR', '0', 'items'];
65
    }
66
}
67