|
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()); |
|
|
|
|
|
|
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()); |
|
|
|
|
|
|
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
|
|
|
|
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.