Skip to content

Commit

Permalink
Enable intlformat sprintf function for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SenseException committed Apr 30, 2024
1 parent 2039e3e commit e888c50
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"autoload-dev": {
"psr-4": {
"Budgegeria\\IntlFormat\\Tests\\": "tests/"
}
},
"files": ["src/intl-format.php"]
},
"prefer-stable": true,
"config": {
Expand Down
24 changes: 24 additions & 0 deletions tests/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
use DateTime;
use DateTimeZone;
use Exception;
use Locale;
use PHPUnit\Framework\TestCase;

use function Budgegeria\IntlFormat\sprintf;

class FactoryTest extends TestCase
{
public function testCreateIntlFormat(): void
Expand Down Expand Up @@ -40,4 +43,25 @@ public function testCreateIntlFormatIntegration(): void
self::assertSame('Error: "test"', $intlFormat->format('Error: "%emessage"', new Exception('test')));
self::assertSame('User Foo has 10 points', $intlFormat->format('User %s has %d points', 'Foo', 10));
}

public function testSprintF(): void
{
Locale::setDefault('en_US');
$date = new DateTime();
$date->setDate(2016, 3, 1);
$date->setTime(5, 30);
$date->setTimezone(new DateTimeZone('US/Arizona'));

self::assertSame('Today is 3/1/16', sprintf('Today is %date_short', $date));
self::assertSame('I got 1,002.25 as average value', sprintf('I got %number as average value', 1002.25));
self::assertSame('I got 1,002.2500 as average value', sprintf('I got %.4number as average value', 1002.25));
self::assertSame('I got 01,002.2500 as average value', sprintf('I got %011.4number as average value', 1002.25));
self::assertSame('I got 1,002.3 as average value', sprintf('I got %.1number_halfway_up as average value', 1002.25));
self::assertSame('I is 5:30 AM on my clock.', sprintf('I is %time_short on my clock.', $date));
self::assertSame('The timezone id is US/Arizona.', sprintf('The timezone id is %timezone_id.', $date));
self::assertSame('I am from Italy.', sprintf('I am from %region.', 'it_IT'));
self::assertSame('You have 10$.', sprintf('You have 10%currency_symbol.', ''));
self::assertSame('Error: "test"', sprintf('Error: "%emessage"', new Exception('test')));
self::assertSame('User Foo has 10 points', sprintf('User %s has %d points', 'Foo', 10));
}
}

0 comments on commit e888c50

Please sign in to comment.