Skip to content

Commit dfdb760

Browse files
Merge pull request #784 from moneyphp/phpunit_10
Phpunit 10
2 parents 4c1a502 + b34c230 commit dfdb760

24 files changed

+151
-119
lines changed

composer.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"php-http/message": "^1.16.0",
4343
"php-http/mock-client": "^1.6.0",
4444
"phpbench/phpbench": "^1.2.5",
45-
"phpunit/phpunit": "^9.5.4",
45+
"phpunit/phpunit": "^10.5.9",
4646
"psalm/plugin-phpunit": "^0.18.4",
4747
"psr/cache": "^1.0.1 || ^2.0 || ^3.0",
4848
"vimeo/psalm": "~5.20.0"
@@ -88,13 +88,13 @@
8888
],
8989
"clean": "rm -rf build/ vendor/",
9090
"test": [
91-
"vendor/bin/phpunit -v",
9291
"vendor/bin/phpbench run",
92+
"vendor/bin/phpunit",
9393
"vendor/bin/psalm",
9494
"vendor/bin/phpcs"
9595
],
9696
"test-coverage": [
97-
"vendor/bin/phpunit -v --coverage-text --coverage-clover=build/unit_coverage.xml"
97+
"vendor/bin/phpunit --coverage-text --coverage-clover=build/unit_coverage.xml"
9898
],
9999
"update-currencies": [
100100
"cp vendor/moneyphp/iso-currencies/resources/current.php resources/currency.php",

phpunit.xml.dist

+11-13
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,19 @@
44
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
55
bootstrap="./vendor/autoload.php"
66
colors="true"
7-
verbose="true"
87
columns="max"
9-
beStrictAboutTestsThatDoNotTestAnything="true"
10-
beStrictAboutResourceUsageDuringSmallTests="true"
118
beStrictAboutChangesToGlobalState="true"
129
>
13-
<testsuites>
14-
<testsuite name="Money Test Suite">
15-
<directory>tests/</directory>
16-
</testsuite>
17-
</testsuites>
1810

19-
<coverage>
20-
<include>
21-
<directory suffix=".php">src</directory>
22-
</include>
23-
</coverage>
11+
<testsuites>
12+
<testsuite name="Money Test Suite">
13+
<directory>tests/</directory>
14+
</testsuite>
15+
</testsuites>
16+
17+
<source>
18+
<include>
19+
<directory>src</directory>
20+
</include>
21+
</source>
2422
</phpunit>

src/PHPUnit/Comparator.php

+11-7
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ final class Comparator extends \SebastianBergmann\Comparator\Comparator
3131

3232
public function __construct()
3333
{
34-
parent::__construct();
35-
3634
$currencies = new AggregateCurrencies([
3735
new ISOCurrencies(),
3836
new BitcoinCurrencies(),
@@ -43,15 +41,21 @@ public function __construct()
4341
}
4442

4543
/** {@inheritDoc} */
46-
public function accepts($expected, $actual)
44+
public function accepts(mixed $expected, mixed $actual): bool
4745
{
4846
return $expected instanceof Money && $actual instanceof Money;
4947
}
5048

51-
/** {@inheritDoc} */
49+
/**
50+
* {@inheritDoc}
51+
*
52+
* @param float $delta
53+
* @param bool $canonicalize
54+
* @param bool $ignoreCase
55+
*/
5256
public function assertEquals(
53-
$expected,
54-
$actual,
57+
mixed $expected,
58+
mixed $actual,
5559
$delta = 0.0,
5660
$canonicalize = false,
5761
$ignoreCase = false
@@ -60,7 +64,7 @@ public function assertEquals(
6064
assert($actual instanceof Money);
6165

6266
if (! $expected->equals($actual)) {
63-
throw new ComparisonFailure($expected, $actual, $this->formatter->format($expected), $this->formatter->format($actual), false, 'Failed asserting that two Money objects are equal.');
67+
throw new ComparisonFailure($expected, $actual, $this->formatter->format($expected), $this->formatter->format($actual), 'Failed asserting that two Money objects are equal.');
6468
}
6569
}
6670
}

tests/AggregateExamples.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
trait AggregateExamples
1010
{
1111
/** @psalm-return non-empty-list<array{non-empty-list<Money>, Money}> */
12-
public function sumExamples(): array
12+
public static function sumExamples(): array
1313
{
1414
return [
1515
[[Money::EUR(5), Money::EUR(10), Money::EUR(15)], Money::EUR(30)],
@@ -19,7 +19,7 @@ public function sumExamples(): array
1919
}
2020

2121
/** @psalm-return non-empty-list<array{non-empty-list<Money>, Money}> */
22-
public function minExamples(): array
22+
public static function minExamples(): array
2323
{
2424
return [
2525
[[Money::EUR(5), Money::EUR(10), Money::EUR(15)], Money::EUR(5)],
@@ -29,7 +29,7 @@ public function minExamples(): array
2929
}
3030

3131
/** @psalm-return non-empty-list<array{non-empty-list<Money>, Money}> */
32-
public function maxExamples(): array
32+
public static function maxExamples(): array
3333
{
3434
return [
3535
[[Money::EUR(5), Money::EUR(10), Money::EUR(15)], Money::EUR(15)],
@@ -39,7 +39,7 @@ public function maxExamples(): array
3939
}
4040

4141
/** @psalm-return non-empty-list<array{non-empty-list<Money>, Money}> */
42-
public function avgExamples(): array
42+
public static function avgExamples(): array
4343
{
4444
return [
4545
[[Money::EUR(5), Money::EUR(10), Money::EUR(15)], Money::EUR(10)],

tests/Calculator/BcMathCalculatorTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public function itRefusesToModuloByZeroWhenDivisorIsTooSmallToCompare(): void
116116
/**
117117
* @psalm-return array<int,array<int|numeric-string>>
118118
*/
119-
public function compareLessExamples(): array
119+
public static function compareLessExamples(): array
120120
{
121121
return array_merge(
122122
parent::compareLessExamples(),

tests/Calculator/CalculatorTestCase.php

+52-12
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,19 @@
88
use Money\Exception\InvalidArgumentException;
99
use Money\Money;
1010
use PHPUnit\Framework\TestCase;
11+
use Tests\Money\Locale;
1112
use Tests\Money\RoundExamples;
1213

1314
use function preg_replace;
1415
use function rtrim;
1516
use function substr;
1617

18+
use const LC_ALL;
19+
1720
abstract class CalculatorTestCase extends TestCase
1821
{
1922
use RoundExamples;
23+
use Locale;
2024

2125
/**
2226
* @return Calculator
@@ -35,6 +39,10 @@ abstract protected function getCalculator(): string;
3539
public function itAddsTwoValues(int $value1, int $value2, string $expected): void
3640
{
3741
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+
});
3846
}
3947

4048
/**
@@ -48,6 +56,10 @@ public function itAddsTwoValues(int $value1, int $value2, string $expected): voi
4856
public function itSubtractsAValueFromAnother(int $value1, int $value2, string $expected): void
4957
{
5058
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+
});
5163
}
5264

5365
/**
@@ -61,6 +73,10 @@ public function itSubtractsAValueFromAnother(int $value1, int $value2, string $e
6173
public function itMultipliesAValueByAnother(int|string $value1, float $value2, string $expected): void
6274
{
6375
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+
});
6480
}
6581

6682
/**
@@ -96,6 +112,10 @@ public function itDividesAValueByAnother(int|string $value1, int|float $value2,
96112
public function itDividesAValueByAnotherExact(int $value1, int|float $value2, string $expected): void
97113
{
98114
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+
});
99119
}
100120

101121
/**
@@ -108,6 +128,10 @@ public function itDividesAValueByAnotherExact(int $value1, int|float $value2, st
108128
public function itCeilsAValue(float $value, string $expected): void
109129
{
110130
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+
});
111135
}
112136

113137
/**
@@ -120,6 +144,10 @@ public function itCeilsAValue(float $value, string $expected): void
120144
public function itFloorsAValue(float $value, string $expected): void
121145
{
122146
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+
});
123151
}
124152

125153
/**
@@ -132,6 +160,10 @@ public function itFloorsAValue(float $value, string $expected): void
132160
public function itCalculatesTheAbsoluteValue(int $value, string $expected): void
133161
{
134162
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+
});
135167
}
136168

137169
/**
@@ -159,6 +191,10 @@ public function itSharesAValue(int $value, int $ratio, int $total, string $expec
159191
public function itRoundsAValue(int|string $value, int $mode, string $expected): void
160192
{
161193
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+
});
162198
}
163199

164200
/**
@@ -201,6 +237,10 @@ public function itComparesValues(int|string $left, int|string $right): void
201237
public function itCalculatesTheModulusOfAValue(int $left, int $right, string $expected): void
202238
{
203239
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+
});
204244
}
205245

206246
/** @test */
@@ -250,7 +290,7 @@ public function itRefusesToModuloByNegativeZero(): void
250290
* numeric-string
251291
* }>
252292
*/
253-
public function additionExamples(): array
293+
public static function additionExamples(): array
254294
{
255295
return [
256296
[1, 1, '2'],
@@ -265,7 +305,7 @@ public function additionExamples(): array
265305
* numeric-string
266306
* }>
267307
*/
268-
public function subtractionExamples(): array
308+
public static function subtractionExamples(): array
269309
{
270310
return [
271311
[1, 1, '0'],
@@ -280,7 +320,7 @@ public function subtractionExamples(): array
280320
* numeric-string
281321
* }>
282322
*/
283-
public function multiplicationExamples(): array
323+
public static function multiplicationExamples(): array
284324
{
285325
return [
286326
[1, 1.5, '1.5'],
@@ -306,7 +346,7 @@ public function multiplicationExamples(): array
306346
* numeric-string
307347
* }>
308348
*/
309-
public function divisionExamples(): array
349+
public static function divisionExamples(): array
310350
{
311351
return [
312352
[6, 3, '2'],
@@ -333,7 +373,7 @@ public function divisionExamples(): array
333373
* numeric-string
334374
* }>
335375
*/
336-
public function divisionExactExamples(): array
376+
public static function divisionExactExamples(): array
337377
{
338378
return [
339379
[6, 3, '2'],
@@ -352,7 +392,7 @@ public function divisionExactExamples(): array
352392
* numeric-string
353393
* }>
354394
*/
355-
public function ceilExamples(): array
395+
public static function ceilExamples(): array
356396
{
357397
return [
358398
[1.2, '2'],
@@ -367,7 +407,7 @@ public function ceilExamples(): array
367407
* numeric-string
368408
* }>
369409
*/
370-
public function floorExamples(): array
410+
public static function floorExamples(): array
371411
{
372412
return [
373413
[2.7, '2'],
@@ -382,7 +422,7 @@ public function floorExamples(): array
382422
* numeric-string
383423
* }>
384424
*/
385-
public function absoluteExamples(): array
425+
public static function absoluteExamples(): array
386426
{
387427
return [
388428
[2, '2'],
@@ -398,7 +438,7 @@ public function absoluteExamples(): array
398438
* numeric-string
399439
* }>
400440
*/
401-
public function shareExamples(): array
441+
public static function shareExamples(): array
402442
{
403443
return [
404444
[10, 2, 4, '5'],
@@ -408,7 +448,7 @@ public function shareExamples(): array
408448
/**
409449
* @psalm-return array<int,array<int|numeric-string>>
410450
*/
411-
public function compareLessExamples(): array
451+
public static function compareLessExamples(): array
412452
{
413453
return [
414454
[0, 1],
@@ -427,7 +467,7 @@ public function compareLessExamples(): array
427467
* int|numeric-string
428468
* }>
429469
*/
430-
public function compareEqualExamples(): array
470+
public static function compareEqualExamples(): array
431471
{
432472
return [
433473
[1, 1],
@@ -443,7 +483,7 @@ public function compareEqualExamples(): array
443483
* numeric-string
444484
* }>
445485
*/
446-
public function modExamples(): array
486+
public static function modExamples(): array
447487
{
448488
return [
449489
[11, 5, '1'],

tests/Calculator/GmpCalculatorTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function it_divides_bug538(): void
5858
/**
5959
* @psalm-return array<int,array<int|numeric-string>>
6060
*/
61-
public function compareLessExamples(): array
61+
public static function compareLessExamples(): array
6262
{
6363
return array_merge(
6464
parent::compareLessExamples(),

0 commit comments

Comments
 (0)