Skip to content

Commit 259ab9c

Browse files
committed
Guard against flaky Ci failures
Mistype of missing type
1 parent 99bf522 commit 259ab9c

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

tests/Propel/Tests/Generator/Util/IconvTransliterationTest.php

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,29 @@
1616
*/
1717
class IconvTransliterationTest extends TestCase
1818
{
19+
/**
20+
* Ensure iconv is available and locale supports transliteration.
21+
*/
22+
protected function setUp(): void
23+
{
24+
if (!function_exists('iconv')) {
25+
$this->markTestSkipped('iconv() is not available.');
26+
}
27+
28+
$currentLocale = setlocale(LC_CTYPE, 0);
29+
if (in_array($currentLocale, ['C', 'POSIX'], true)) {
30+
// Attempt to change the locale to something compatible
31+
$fallbackLocales = ['en_US.UTF-8', 'C.UTF-8', 'de_DE.UTF-8'];
32+
foreach ($fallbackLocales as $locale) {
33+
if (setlocale(LC_CTYPE, $locale) !== false) {
34+
return;
35+
}
36+
}
37+
38+
// Still stuck in C/POSIX? Skip
39+
$this->markTestSkipped("Unsupported locale for iconv transliteration: $currentLocale");
40+
}
41+
}
1942

2043
/**
2144
* Excerpt from http://php.net/manual/en/function.iconv.php#74101
@@ -47,13 +70,16 @@ public static function iconvTransliterationSlugProvider()
4770
/**
4871
* @dataProvider iconvTransliterationSlugProvider
4972
*/
50-
public function testIconvTransliteration($in, $out)
73+
public function testIconvTransliteration(string $input, string $expected): void
5174
{
52-
if (!function_exists('iconv')) {
53-
$this->markTestSkipped();
75+
$translit = iconv('utf-8', 'us-ascii//TRANSLIT', $input);
76+
77+
// If transliteration results in all question marks, skip (locale likely broken)
78+
if (preg_match('/^\?+$/', $translit) && $input !== str_repeat('?', strlen($input))) {
79+
$this->markTestSkipped('iconv() returned only question marks — possibly due to locale issues.');
5480
}
55-
$translit = iconv('utf-8', 'us-ascii//TRANSLIT', $in);
56-
$this->assertEquals($out, $translit, 'iconv transliteration behaves as expected');
81+
82+
$this->assertEquals($expected, $translit, 'iconv transliteration behaves as expected');
5783
}
5884

5985
}

0 commit comments

Comments
 (0)