Skip to content

Commit

Permalink
test(IntlNumberFormatterTest): add currency example
Browse files Browse the repository at this point in the history
  • Loading branch information
h4kuna committed Mar 24, 2024
1 parent 8d180bb commit d39e579
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions tests/src/Number/Formatters/IntlNumberFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use h4kuna\Format\Number\NativePhp\NumberFormatterFactory;
use h4kuna\Format\Tests\TestCase;
use h4kuna\Format\Utils\Space;
use NumberFormatter;
use Tester\Assert;

require_once __DIR__ . '/../../../bootstrap.php';
Expand All @@ -24,28 +23,42 @@ final class IntlNumberFormatterTest extends TestCase
*/
public function testFormat(array $parameters, string $expected, $number): void
{
$numberFormatter = self::createNumberFormatter();
$numberFormatter = self::createNumberFormatter()->create();

Check failure on line 26 in tests/src/Number/Formatters/IntlNumberFormatterTest.php

View workflow job for this annotation

GitHub Actions / PHPStan

Unable to resolve the template type T in call to method h4kuna\Format\Number\NativePhp\NumberFormatterFactory::create()
$numberFormat = new IntlNumberFormatter($numberFormatter, ...$parameters);
Assert::same(Space::nbsp($expected), $numberFormat->format($number));
}


public function testCurrency(): void
{
$numberFormatterFactory = self::createNumberFormatter();

$numberFormatter = $numberFormatterFactory->currency();
$numberFormat = new IntlNumberFormatter($numberFormatter);
Assert::same(Space::nbsp('1 000,46 Kč'), $numberFormat->format(1000.456));

$numberFormatter = $numberFormatterFactory->currency('en_GB');
$numberFormat = new IntlNumberFormatter($numberFormatter);
Assert::same(Space::nbsp('£1,000.46'), $numberFormat->format(1000.456));
}


/**
* @dataProvider provideFormat
* @param array{emptyValue: string, zeroIsEmpty: bool} $parameters
* @param string|int|float|null $number
*/
public function testModify(array $parameters, string $expected, $number): void
{
$numberFormatter = self::createNumberFormatter();
$numberFormatter = self::createNumberFormatter()->create();

Check failure on line 53 in tests/src/Number/Formatters/IntlNumberFormatterTest.php

View workflow job for this annotation

GitHub Actions / PHPStan

Unable to resolve the template type T in call to method h4kuna\Format\Number\NativePhp\NumberFormatterFactory::create()
$numberFormat = (new IntlNumberFormatter($numberFormatter))->modify(...$parameters);
Assert::same(Space::nbsp($expected), $numberFormat->format($number));
}


private static function createNumberFormatter(): NumberFormatter
private static function createNumberFormatter(): NumberFormatterFactory
{
return (new NumberFormatterFactory('cs_CZ'))->create();
return new NumberFormatterFactory('cs_CZ');
}


Expand Down

0 comments on commit d39e579

Please sign in to comment.