Skip to content

Commit

Permalink
chore: upgrade PHPUnit 9 => 10
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris8934 committed Feb 2, 2024
1 parent b19212c commit e58c49b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 19 deletions.
25 changes: 13 additions & 12 deletions tests/ConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
use Money\Money;
use PHPUnit\Framework\TestCase;

use function setlocale;
use function sprintf;

use const LC_ALL;

/** @covers \Money\Converter */
final class ConverterTest extends TestCase
{
use Locale;

/**
* @psalm-param non-empty-string $baseCurrencyCode
* @psalm-param non-empty-string $counterCurrencyCode
Expand Down Expand Up @@ -193,17 +194,17 @@ public function itConvertsToADifferentCurrencyWhenDecimalSeparatorIsComma(
$amount,
$expectedAmount
): void {
setlocale(LC_ALL, 'ru_RU.UTF-8');

$this->itConvertsToADifferentCurrency(
$baseCurrencyCode,
$counterCurrencyCode,
$subunitBase,
$subunitCounter,
$ratio,
$amount,
$expectedAmount
);
self::runLocaleAware(LC_ALL, 'ru_RU.UTF-8', function () use ($expectedAmount, $amount, $ratio, $subunitCounter, $subunitBase, $counterCurrencyCode, $baseCurrencyCode): void {
$this->itConvertsToADifferentCurrency(
$baseCurrencyCode,
$counterCurrencyCode,
$subunitBase,
$subunitCounter,
$ratio,
$amount,
$expectedAmount
);
});
}

/**
Expand Down
23 changes: 23 additions & 0 deletions tests/Locale.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace Tests\Money;

use Closure;

use function setlocale;

trait Locale
{
public static function runLocaleAware(int $category, string $locale, Closure $callback): void
{
$currentLocale = setlocale($category, 0);
try {
setlocale($category, $locale);
$callback();
} finally {
setlocale($category, $currentLocale);
}
}
}
14 changes: 7 additions & 7 deletions tests/MoneyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use PHPUnit\Framework\TestCase;

use function json_encode;
use function setlocale;

use const LC_ALL;
use const PHP_INT_MAX;
Expand All @@ -20,6 +19,7 @@ final class MoneyTest extends TestCase
{
use AggregateExamples;
use RoundExamples;
use Locale;

public const AMOUNT = 10;

Expand Down Expand Up @@ -100,13 +100,13 @@ public function itMultipliesTheAmount(int|string $multiplier, int $roundingMode,
*/
public function itMultipliesTheAmountWithLocaleThatUsesCommaSeparator(): void
{
setlocale(LC_ALL, 'es_ES.utf8');
self::runLocaleAware(LC_ALL, 'es_ES.utf8', static function (): void {
$money = new Money(100, new Currency(self::CURRENCY));
$money = $money->multiply('0.1');

$money = new Money(100, new Currency(self::CURRENCY));
$money = $money->multiply('0.1');

self::assertInstanceOf(Money::class, $money);
self::assertEquals('10', $money->getAmount());
self::assertInstanceOf(Money::class, $money);
self::assertEquals('10', $money->getAmount());
});
}

/**
Expand Down

0 comments on commit e58c49b

Please sign in to comment.