From b34c2301f42c4896b3b08dbd24f0f040149d0915 Mon Sep 17 00:00:00 2001 From: Frederik Bosch Date: Tue, 6 Feb 2024 10:07:27 +0100 Subject: [PATCH] move locale aware tests abstract calculator --- tests/Calculator/CalculatorTestCase.php | 40 +++++++++++++++++++ .../LocaleAwareBcMathCalculatorTest.php | 20 ---------- .../LocaleAwareGmpCalculatorTest.php | 20 ---------- 3 files changed, 40 insertions(+), 40 deletions(-) delete mode 100644 tests/Calculator/LocaleAwareBcMathCalculatorTest.php delete mode 100644 tests/Calculator/LocaleAwareGmpCalculatorTest.php diff --git a/tests/Calculator/CalculatorTestCase.php b/tests/Calculator/CalculatorTestCase.php index 80ca1c54..640cde2a 100644 --- a/tests/Calculator/CalculatorTestCase.php +++ b/tests/Calculator/CalculatorTestCase.php @@ -8,15 +8,19 @@ use Money\Exception\InvalidArgumentException; use Money\Money; use PHPUnit\Framework\TestCase; +use Tests\Money\Locale; use Tests\Money\RoundExamples; use function preg_replace; use function rtrim; use function substr; +use const LC_ALL; + abstract class CalculatorTestCase extends TestCase { use RoundExamples; + use Locale; /** * @return Calculator @@ -35,6 +39,10 @@ abstract protected function getCalculator(): string; public function itAddsTwoValues(int $value1, int $value2, string $expected): void { self::assertEqualNumber($expected, $this->getCalculator()::add((string) $value1, (string) $value2)); + + self::runLocaleAware(LC_ALL, 'ru_RU.UTF-8', function () use ($value1, $value2, $expected): void { + self::assertEqualNumber($expected, $this->getCalculator()::add((string) $value1, (string) $value2)); + }); } /** @@ -48,6 +56,10 @@ public function itAddsTwoValues(int $value1, int $value2, string $expected): voi public function itSubtractsAValueFromAnother(int $value1, int $value2, string $expected): void { self::assertEqualNumber($expected, $this->getCalculator()::subtract((string) $value1, (string) $value2)); + + self::runLocaleAware(LC_ALL, 'ru_RU.UTF-8', function () use ($value1, $value2, $expected): void { + self::assertEqualNumber($expected, $this->getCalculator()::subtract((string) $value1, (string) $value2)); + }); } /** @@ -61,6 +73,10 @@ public function itSubtractsAValueFromAnother(int $value1, int $value2, string $e public function itMultipliesAValueByAnother(int|string $value1, float $value2, string $expected): void { self::assertEqualNumber($expected, $this->getCalculator()::multiply((string) $value1, (string) $value2)); + + self::runLocaleAware(LC_ALL, 'ru_RU.UTF-8', function () use ($value1, $value2, $expected): void { + self::assertEqualNumber($expected, $this->getCalculator()::multiply((string) $value1, (string) $value2)); + }); } /** @@ -96,6 +112,10 @@ public function itDividesAValueByAnother(int|string $value1, int|float $value2, public function itDividesAValueByAnotherExact(int $value1, int|float $value2, string $expected): void { self::assertEqualNumber($expected, $this->getCalculator()::divide((string) $value1, (string) $value2)); + + self::runLocaleAware(LC_ALL, 'ru_RU.UTF-8', function () use ($value1, $value2, $expected): void { + self::assertEqualNumber($expected, $this->getCalculator()::divide((string) $value1, (string) $value2)); + }); } /** @@ -108,6 +128,10 @@ public function itDividesAValueByAnotherExact(int $value1, int|float $value2, st public function itCeilsAValue(float $value, string $expected): void { self::assertEquals($expected, $this->getCalculator()::ceil((string) $value)); + + self::runLocaleAware(LC_ALL, 'ru_RU.UTF-8', function () use ($value, $expected): void { + self::assertEqualNumber($expected, $this->getCalculator()::ceil((string) $value)); + }); } /** @@ -120,6 +144,10 @@ public function itCeilsAValue(float $value, string $expected): void public function itFloorsAValue(float $value, string $expected): void { self::assertEquals($expected, $this->getCalculator()::floor((string) $value)); + + self::runLocaleAware(LC_ALL, 'ru_RU.UTF-8', function () use ($value, $expected): void { + self::assertEqualNumber($expected, $this->getCalculator()::floor((string) $value)); + }); } /** @@ -132,6 +160,10 @@ public function itFloorsAValue(float $value, string $expected): void public function itCalculatesTheAbsoluteValue(int $value, string $expected): void { self::assertEquals($expected, $this->getCalculator()::absolute((string) $value)); + + self::runLocaleAware(LC_ALL, 'ru_RU.UTF-8', function () use ($value, $expected): void { + self::assertEqualNumber($expected, $this->getCalculator()::absolute((string) $value)); + }); } /** @@ -159,6 +191,10 @@ public function itSharesAValue(int $value, int $ratio, int $total, string $expec public function itRoundsAValue(int|string $value, int $mode, string $expected): void { self::assertEquals($expected, $this->getCalculator()::round((string) $value, $mode)); + + self::runLocaleAware(LC_ALL, 'ru_RU.UTF-8', function () use ($value, $mode, $expected): void { + self::assertEqualNumber($expected, $this->getCalculator()::round((string) $value, $mode)); + }); } /** @@ -201,6 +237,10 @@ public function itComparesValues(int|string $left, int|string $right): void public function itCalculatesTheModulusOfAValue(int $left, int $right, string $expected): void { self::assertEquals($expected, $this->getCalculator()::mod((string) $left, (string) $right)); + + self::runLocaleAware(LC_ALL, 'ru_RU.UTF-8', function () use ($left, $right, $expected): void { + self::assertEqualNumber($expected, $this->getCalculator()::mod((string) $left, (string) $right)); + }); } /** @test */ diff --git a/tests/Calculator/LocaleAwareBcMathCalculatorTest.php b/tests/Calculator/LocaleAwareBcMathCalculatorTest.php deleted file mode 100644 index d0a57090..00000000 --- a/tests/Calculator/LocaleAwareBcMathCalculatorTest.php +++ /dev/null @@ -1,20 +0,0 @@ -