Skip to content

Commit

Permalink
move locale aware tests abstract calculator
Browse files Browse the repository at this point in the history
  • Loading branch information
frederikbosch committed Feb 6, 2024
1 parent e58c49b commit b34c230
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 40 deletions.
40 changes: 40 additions & 0 deletions tests/Calculator/CalculatorTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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));
});
}

/**
Expand All @@ -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));
});
}

/**
Expand All @@ -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));
});
}

/**
Expand Down Expand Up @@ -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));
});
}

/**
Expand All @@ -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));
});
}

/**
Expand All @@ -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));
});
}

/**
Expand All @@ -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));
});
}

/**
Expand Down Expand Up @@ -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));
});
}

/**
Expand Down Expand Up @@ -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 */
Expand Down
20 changes: 0 additions & 20 deletions tests/Calculator/LocaleAwareBcMathCalculatorTest.php

This file was deleted.

20 changes: 0 additions & 20 deletions tests/Calculator/LocaleAwareGmpCalculatorTest.php

This file was deleted.

0 comments on commit b34c230

Please sign in to comment.