8
8
use Money \Exception \InvalidArgumentException ;
9
9
use Money \Money ;
10
10
use PHPUnit \Framework \TestCase ;
11
+ use Tests \Money \Locale ;
11
12
use Tests \Money \RoundExamples ;
12
13
13
14
use function preg_replace ;
14
15
use function rtrim ;
15
16
use function substr ;
16
17
18
+ use const LC_ALL ;
19
+
17
20
abstract class CalculatorTestCase extends TestCase
18
21
{
19
22
use RoundExamples;
23
+ use Locale;
20
24
21
25
/**
22
26
* @return Calculator
@@ -35,6 +39,10 @@ abstract protected function getCalculator(): string;
35
39
public function itAddsTwoValues (int $ value1 , int $ value2 , string $ expected ): void
36
40
{
37
41
self ::assertEqualNumber ($ expected , $ this ->getCalculator ()::add ((string ) $ value1 , (string ) $ value2 ));
42
+
43
+ self ::runLocaleAware (LC_ALL , 'ru_RU.UTF-8 ' , function () use ($ value1 , $ value2 , $ expected ): void {
44
+ self ::assertEqualNumber ($ expected , $ this ->getCalculator ()::add ((string ) $ value1 , (string ) $ value2 ));
45
+ });
38
46
}
39
47
40
48
/**
@@ -48,6 +56,10 @@ public function itAddsTwoValues(int $value1, int $value2, string $expected): voi
48
56
public function itSubtractsAValueFromAnother (int $ value1 , int $ value2 , string $ expected ): void
49
57
{
50
58
self ::assertEqualNumber ($ expected , $ this ->getCalculator ()::subtract ((string ) $ value1 , (string ) $ value2 ));
59
+
60
+ self ::runLocaleAware (LC_ALL , 'ru_RU.UTF-8 ' , function () use ($ value1 , $ value2 , $ expected ): void {
61
+ self ::assertEqualNumber ($ expected , $ this ->getCalculator ()::subtract ((string ) $ value1 , (string ) $ value2 ));
62
+ });
51
63
}
52
64
53
65
/**
@@ -61,6 +73,10 @@ public function itSubtractsAValueFromAnother(int $value1, int $value2, string $e
61
73
public function itMultipliesAValueByAnother (int |string $ value1 , float $ value2 , string $ expected ): void
62
74
{
63
75
self ::assertEqualNumber ($ expected , $ this ->getCalculator ()::multiply ((string ) $ value1 , (string ) $ value2 ));
76
+
77
+ self ::runLocaleAware (LC_ALL , 'ru_RU.UTF-8 ' , function () use ($ value1 , $ value2 , $ expected ): void {
78
+ self ::assertEqualNumber ($ expected , $ this ->getCalculator ()::multiply ((string ) $ value1 , (string ) $ value2 ));
79
+ });
64
80
}
65
81
66
82
/**
@@ -96,6 +112,10 @@ public function itDividesAValueByAnother(int|string $value1, int|float $value2,
96
112
public function itDividesAValueByAnotherExact (int $ value1 , int |float $ value2 , string $ expected ): void
97
113
{
98
114
self ::assertEqualNumber ($ expected , $ this ->getCalculator ()::divide ((string ) $ value1 , (string ) $ value2 ));
115
+
116
+ self ::runLocaleAware (LC_ALL , 'ru_RU.UTF-8 ' , function () use ($ value1 , $ value2 , $ expected ): void {
117
+ self ::assertEqualNumber ($ expected , $ this ->getCalculator ()::divide ((string ) $ value1 , (string ) $ value2 ));
118
+ });
99
119
}
100
120
101
121
/**
@@ -108,6 +128,10 @@ public function itDividesAValueByAnotherExact(int $value1, int|float $value2, st
108
128
public function itCeilsAValue (float $ value , string $ expected ): void
109
129
{
110
130
self ::assertEquals ($ expected , $ this ->getCalculator ()::ceil ((string ) $ value ));
131
+
132
+ self ::runLocaleAware (LC_ALL , 'ru_RU.UTF-8 ' , function () use ($ value , $ expected ): void {
133
+ self ::assertEqualNumber ($ expected , $ this ->getCalculator ()::ceil ((string ) $ value ));
134
+ });
111
135
}
112
136
113
137
/**
@@ -120,6 +144,10 @@ public function itCeilsAValue(float $value, string $expected): void
120
144
public function itFloorsAValue (float $ value , string $ expected ): void
121
145
{
122
146
self ::assertEquals ($ expected , $ this ->getCalculator ()::floor ((string ) $ value ));
147
+
148
+ self ::runLocaleAware (LC_ALL , 'ru_RU.UTF-8 ' , function () use ($ value , $ expected ): void {
149
+ self ::assertEqualNumber ($ expected , $ this ->getCalculator ()::floor ((string ) $ value ));
150
+ });
123
151
}
124
152
125
153
/**
@@ -132,6 +160,10 @@ public function itFloorsAValue(float $value, string $expected): void
132
160
public function itCalculatesTheAbsoluteValue (int $ value , string $ expected ): void
133
161
{
134
162
self ::assertEquals ($ expected , $ this ->getCalculator ()::absolute ((string ) $ value ));
163
+
164
+ self ::runLocaleAware (LC_ALL , 'ru_RU.UTF-8 ' , function () use ($ value , $ expected ): void {
165
+ self ::assertEqualNumber ($ expected , $ this ->getCalculator ()::absolute ((string ) $ value ));
166
+ });
135
167
}
136
168
137
169
/**
@@ -159,6 +191,10 @@ public function itSharesAValue(int $value, int $ratio, int $total, string $expec
159
191
public function itRoundsAValue (int |string $ value , int $ mode , string $ expected ): void
160
192
{
161
193
self ::assertEquals ($ expected , $ this ->getCalculator ()::round ((string ) $ value , $ mode ));
194
+
195
+ self ::runLocaleAware (LC_ALL , 'ru_RU.UTF-8 ' , function () use ($ value , $ mode , $ expected ): void {
196
+ self ::assertEqualNumber ($ expected , $ this ->getCalculator ()::round ((string ) $ value , $ mode ));
197
+ });
162
198
}
163
199
164
200
/**
@@ -201,6 +237,10 @@ public function itComparesValues(int|string $left, int|string $right): void
201
237
public function itCalculatesTheModulusOfAValue (int $ left , int $ right , string $ expected ): void
202
238
{
203
239
self ::assertEquals ($ expected , $ this ->getCalculator ()::mod ((string ) $ left , (string ) $ right ));
240
+
241
+ self ::runLocaleAware (LC_ALL , 'ru_RU.UTF-8 ' , function () use ($ left , $ right , $ expected ): void {
242
+ self ::assertEqualNumber ($ expected , $ this ->getCalculator ()::mod ((string ) $ left , (string ) $ right ));
243
+ });
204
244
}
205
245
206
246
/** @test */
@@ -250,7 +290,7 @@ public function itRefusesToModuloByNegativeZero(): void
250
290
* numeric-string
251
291
* }>
252
292
*/
253
- public function additionExamples (): array
293
+ public static function additionExamples (): array
254
294
{
255
295
return [
256
296
[1 , 1 , '2 ' ],
@@ -265,7 +305,7 @@ public function additionExamples(): array
265
305
* numeric-string
266
306
* }>
267
307
*/
268
- public function subtractionExamples (): array
308
+ public static function subtractionExamples (): array
269
309
{
270
310
return [
271
311
[1 , 1 , '0 ' ],
@@ -280,7 +320,7 @@ public function subtractionExamples(): array
280
320
* numeric-string
281
321
* }>
282
322
*/
283
- public function multiplicationExamples (): array
323
+ public static function multiplicationExamples (): array
284
324
{
285
325
return [
286
326
[1 , 1.5 , '1.5 ' ],
@@ -306,7 +346,7 @@ public function multiplicationExamples(): array
306
346
* numeric-string
307
347
* }>
308
348
*/
309
- public function divisionExamples (): array
349
+ public static function divisionExamples (): array
310
350
{
311
351
return [
312
352
[6 , 3 , '2 ' ],
@@ -333,7 +373,7 @@ public function divisionExamples(): array
333
373
* numeric-string
334
374
* }>
335
375
*/
336
- public function divisionExactExamples (): array
376
+ public static function divisionExactExamples (): array
337
377
{
338
378
return [
339
379
[6 , 3 , '2 ' ],
@@ -352,7 +392,7 @@ public function divisionExactExamples(): array
352
392
* numeric-string
353
393
* }>
354
394
*/
355
- public function ceilExamples (): array
395
+ public static function ceilExamples (): array
356
396
{
357
397
return [
358
398
[1.2 , '2 ' ],
@@ -367,7 +407,7 @@ public function ceilExamples(): array
367
407
* numeric-string
368
408
* }>
369
409
*/
370
- public function floorExamples (): array
410
+ public static function floorExamples (): array
371
411
{
372
412
return [
373
413
[2.7 , '2 ' ],
@@ -382,7 +422,7 @@ public function floorExamples(): array
382
422
* numeric-string
383
423
* }>
384
424
*/
385
- public function absoluteExamples (): array
425
+ public static function absoluteExamples (): array
386
426
{
387
427
return [
388
428
[2 , '2 ' ],
@@ -398,7 +438,7 @@ public function absoluteExamples(): array
398
438
* numeric-string
399
439
* }>
400
440
*/
401
- public function shareExamples (): array
441
+ public static function shareExamples (): array
402
442
{
403
443
return [
404
444
[10 , 2 , 4 , '5 ' ],
@@ -408,7 +448,7 @@ public function shareExamples(): array
408
448
/**
409
449
* @psalm-return array<int,array<int|numeric-string>>
410
450
*/
411
- public function compareLessExamples (): array
451
+ public static function compareLessExamples (): array
412
452
{
413
453
return [
414
454
[0 , 1 ],
@@ -427,7 +467,7 @@ public function compareLessExamples(): array
427
467
* int|numeric-string
428
468
* }>
429
469
*/
430
- public function compareEqualExamples (): array
470
+ public static function compareEqualExamples (): array
431
471
{
432
472
return [
433
473
[1 , 1 ],
@@ -443,7 +483,7 @@ public function compareEqualExamples(): array
443
483
* numeric-string
444
484
* }>
445
485
*/
446
- public function modExamples (): array
486
+ public static function modExamples (): array
447
487
{
448
488
return [
449
489
[11 , 5 , '1 ' ],
0 commit comments