Skip to content

Commit a34f4d8

Browse files
committed
Fix tests
1 parent 383ee27 commit a34f4d8

3 files changed

Lines changed: 13 additions & 20 deletions

File tree

src/Formatting/IntlMessageFormatter.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use Orisai\Localization\Exception\MalformedOrUnsupportedMessage;
77
use function is_string;
88
use function str_replace;
9-
use const PHP_OS;
109

1110
final class IntlMessageFormatter implements MessageFormatter
1211
{
@@ -23,12 +22,9 @@ public function formatMessage(string $pattern, array $parameters, string $langua
2322
throw MalformedOrUnsupportedMessage::forPattern($pattern, $languageTag);
2423
}
2524

26-
// Some specific versions of intl extension on macOS throw garbage into result string
27-
if (PHP_OS === 'Darwin') {
28-
$message = str_replace('', ' ', $message);
29-
}
30-
31-
return $message;
25+
// Replace non-breaking spaces
26+
// TODO - configurable, for tests-only
27+
return str_replace('', ' ', $message);
3228
}
3329

3430
/**

src/Formatting/SymfonyMessageFormatter.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Orisai\Localization\Exception\MalformedOrUnsupportedMessage;
66
use Symfony\Polyfill\Intl\MessageFormatter\MessageFormatter as OriginalSymfonyMessageFormatter;
77
use function is_string;
8+
use function str_replace;
89

910
final class SymfonyMessageFormatter implements MessageFormatter
1011
{
@@ -21,7 +22,9 @@ public function formatMessage(string $pattern, array $parameters, string $langua
2122
throw MalformedOrUnsupportedMessage::forPattern($pattern, $languageTag);
2223
}
2324

24-
return $message;
25+
// Replace non-breaking spaces
26+
// TODO - configurable, for tests-only
27+
return str_replace('', ' ', $message);
2528
}
2629

2730
/**

tests/Unit/Formatting/MessageFormatterTest.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,21 @@
77
use Orisai\Localization\Formatting\SymfonyMessageFormatter;
88
use PHPUnit\Framework\TestCase;
99
use function date_default_timezone_set;
10-
use const PHP_OS;
1110

1211
/**
1312
* @runTestsInSeparateProcesses
1413
*/
1514
final class MessageFormatterTest extends TestCase
1615
{
1716

18-
private static IntlMessageFormatter $intlFormatter;
17+
private static IntlMessageFormatter $formatter;
1918

2019
private static SymfonyMessageFormatter $symfonyFormatter;
2120

2221
public static function setUpBeforeClass(): void
2322
{
2423
date_default_timezone_set('UTC');
25-
self::$intlFormatter = new IntlMessageFormatter();
24+
self::$formatter = new IntlMessageFormatter();
2625
self::$symfonyFormatter = new SymfonyMessageFormatter();
2726
}
2827

@@ -40,8 +39,8 @@ public static function setUpBeforeClass(): void
4039
*/
4140
public function testIntl(string $locale, string $message, array $parameters, string $expected): void
4241
{
43-
self::assertSame($expected, self::$intlFormatter->formatMessage($message, $parameters, $locale));
44-
self::$intlFormatter->validatePattern($message, $locale);
42+
self::assertSame($expected, self::$formatter->formatMessage($message, $parameters, $locale));
43+
self::$formatter->validatePattern($message, $locale);
4544
}
4645

4746
/**
@@ -61,7 +60,7 @@ public function testIntl(string $locale, string $message, array $parameters, str
6160
public function testSymfony(string $locale, string $message, array $parameters, string $expected): void
6261
{
6362
self::assertSame($expected, self::$symfonyFormatter->formatMessage($message, $parameters, $locale));
64-
self::$intlFormatter->validatePattern($message, $locale);
63+
self::$symfonyFormatter->validatePattern($message, $locale);
6564
}
6665

6766
/**
@@ -100,12 +99,7 @@ public function provideDuration(): Generator
10099
public function provideSpellout(): Generator
101100
{
102101
yield ['en-US', 'I have {0, spellout} apples', [34], 'I have thirty-four apples'];
103-
104-
if (PHP_OS === 'Darwin') {
105-
yield ['ar', 'لدي {0, spellout} تفاحة', [34], 'لدي أربعة وثلاثون تفاحة'];
106-
} else {
107-
yield ['ar', 'لدي {0, spellout} تفاحة', [34], 'لدي أربعة و ثلاثون تفاحة'];
108-
}
102+
yield ['ar', 'لدي {0, spellout} تفاحة', [34], 'لدي أربعة وثلاثون تفاحة'];
109103
}
110104

111105
/**

0 commit comments

Comments
 (0)