/
CashRoundingTest.php
137 lines (115 loc) · 4.96 KB
/
CashRoundingTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php declare(strict_types=1);
namespace Shopware\Tests\Unit\Core\Checkout\Cart\Price;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Shopware\Core\Checkout\Cart\Price\CashRounding;
use Shopware\Core\Framework\DataAbstractionLayer\Pricing\CashRoundingConfig;
/**
* @internal
*/
#[CoversClass(CashRounding::class)]
class CashRoundingTest extends TestCase
{
#[DataProvider('provider_german')]
public function testGerman(float $price, float $expected): void
{
$service = new CashRounding();
$config = new CashRoundingConfig(2, 0.01, true);
$actual = $service->cashRound($price, $config);
static::assertEquals($expected, $actual);
}
#[DataProvider('provider_hong_kong')]
public function testHongKong(float $price, float $expected): void
{
$service = new CashRounding();
$config = new CashRoundingConfig(2, 0.10, true);
$actual = $service->cashRound($price, $config);
static::assertEquals($expected, $actual);
}
#[DataProvider('provider_denmark')]
public function testDenmark(float $price, float $expected): void
{
$service = new CashRounding();
$config = new CashRoundingConfig(2, 0.50, true);
$actual = $service->cashRound($price, $config);
static::assertEquals($expected, $actual);
}
#[DataProvider('provider_italy')]
public function testItaly(float $price, float $expected): void
{
$service = new CashRounding();
$config = new CashRoundingConfig(2, 0.05, true);
$actual = $service->cashRound($price, $config);
static::assertEquals($expected, $actual);
}
#[DataProvider('provider_sweden')]
public function testSweden(float $price, float $expected): void
{
$service = new CashRounding();
$config = new CashRoundingConfig(2, 1.0, true);
$actual = $service->cashRound($price, $config);
static::assertEquals($expected, $actual);
}
public static function provider_german(): \Generator
{
yield '19.990 should be 19.99' => [19.990, 19.99];
yield '19.991 should be 19.99' => [19.991, 19.99];
yield '19.994 should be 19.99' => [19.994, 19.99];
yield '19.995 should be 20.00' => [19.995, 20.00];
yield '19.999 should be 20.00' => [19.999, 20.00];
}
public static function provider_hong_kong(): \Generator
{
yield '19.40 should be 19.40' => [19.40, 19.40];
yield '19.41 should be 19.40' => [19.41, 19.40];
yield '19.44 should be 19.40' => [19.44, 19.40];
yield '19.444 should be 19.40' => [19.444, 19.40];
yield '19.445 should be 19.50' => [19.445, 19.50];
yield '19.45 should be 19.50' => [19.45, 19.50];
yield '19.49 should be 19.50' => [19.49, 19.50];
}
public static function provider_denmark(): \Generator
{
yield '19.01 should be 19.00' => [19.01, 19.00];
yield '19.24 should be 19.00' => [19.24, 19.00];
yield '19.244 should be 19.00' => [19.244, 19.00];
yield '19.245 should be 19.50' => [19.245, 19.50];
yield '19.25 should be 19.50' => [19.25, 19.50];
yield '19.49 should be 19.50' => [19.49, 19.50];
yield '19.50 should be 19.50' => [19.50, 19.50];
yield '19.51 should be 19.50' => [19.51, 19.50];
yield '19.74 should be 19.50' => [19.74, 19.50];
yield '19.744 should be 19.50' => [19.744, 19.50];
yield '19.745 should be 20.00' => [19.745, 20.00];
yield '19.75 should be 20.00' => [19.75, 20.00];
yield '19.99 should be 20.00' => [19.99, 20.00];
}
public static function provider_italy(): \Generator
{
yield '19.50 should be 19.50' => [19.50, 19.50];
yield '19.51 should be 19.50' => [19.51, 19.50];
yield '19.52 should be 19.50' => [19.52, 19.50];
yield '19.524 should be 19.50' => [19.524, 19.50];
yield '19.525 should be 19.55' => [19.525, 19.55];
yield '19.53 should be 19.55' => [19.53, 19.55];
yield '19.54 should be 19.55' => [19.54, 19.55];
yield '19.55 should be 19.55' => [19.55, 19.55];
yield '19.56 should be 19.55' => [19.56, 19.55];
yield '19.57 should be 19.55' => [19.57, 19.55];
yield '19.574 should be 19.55' => [19.574, 19.55];
yield '19.575 should be 19.60' => [19.575, 19.60];
yield '19.58 should be 19.60' => [19.58, 19.60];
yield '19.59 should be 19.60' => [19.59, 19.60];
}
public static function provider_sweden(): \Generator
{
yield '19.00 should be 19.00' => [19.00, 19.00];
yield '19.01 should be 19.00' => [19.01, 19.00];
yield '19.49 should be 19.00' => [19.49, 19.00];
yield '19.491 should be 19.00' => [19.491, 19.00];
yield '19.495 should be 20.00' => [19.495, 20.00];
yield '19.50 should be 20.00' => [19.50, 20.00];
yield '19.99 should be 20.00' => [19.99, 20.00];
}
}