Skip to content

Commit 83b5c67

Browse files
committed
minor symfony#52968 [VarDumper] Test intl formatter broken since dumper does not replace the nnbsp character by standard space (CDR)
This PR was squashed before being merged into the 6.3 branch. Discussion ---------- [VarDumper] Test intl formatter broken since dumper does not replace the nnbsp character by standard space | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | I don't know, saw the problem on my machine | License | MIT Fix the \Symfony\Component\VarDumper\Tests\Caster\IntlCasterTest::testCastDateFormatter failure on machines that have Intl >= 72.1 : Failed asserting that two strings are identical. --- Expected +++ Actual @@ @@ 'IntlDateFormatter { locale: "en" - pattern: "EEEE, MMMM d, y 'at' h:mm:ss a zzzz" <--- Notice that between 'ss' and 'a', it look's like a space, but it is an invisible \u{202F} character + pattern: "EEEE, MMMM d, y 'at' h:mm:ss\u{202F}a zzzz" Commit 6936845 says 'display invisible characters'. Since Intl 72.1 version, the getPattern method of IntlDateFormatter returns a string containing an invisible character \u{202F} (alia NNBSP). I replaced it by \\u{202F} in the expected output, but I guess maybe we could go further and do this replacement in the assertDumpEquals method For example, here is a piece of code I wrote when debugging the problem : ``` // Check what happens with Unicode caracters $u202F = "\u{202F}"; $escapedU202F = "\\u{202F}"; // Obviously those two strings are not equals $this->assertNotEquals($u202F, $escapedU202F); // this test fails : // $this->assertDumpEquals('"' . $u202F . '"', $u202F); // Output : /// Failed asserting that two strings are identical. // -'" "' // +'"\u{202F}"' // the dump of the first one \u{202F} is equal to the second one \\u{202F} // this test passes : $this->assertDumpEquals('"' . $escapedU202F . '"', $u202F); // since Intl 72, $var->getPatterns returns EEEE, MMMM d, y 'at' h:mm:ss\u{202F}a zzzz // The test fails as : // - it expects "EEEE, MMMM d, y 'at' h:mm:ss\u{202F}a zzzz" (\u{202F} is invisible, so in the console output it look's like "EEEE, MMMM d, y 'at' h:mm:ss a zzzz" // - but gets "EEEE, MMMM d, y 'at' h:mm:ss\\u{202F}a zzzz" (escaped version produced by dump since commit 6936845) // $expectedPattern = str_replace("\u{202F}", "\\u{202F}", $var->getPattern()); $expectedPattern = $this->normalizeU202F($var->getPattern()); ``` Commits ------- 46b1edb [VarDumper] Test intl formatter broken since dumper does not replace the nnbsp character by standard space
2 parents c481dba + 46b1edb commit 83b5c67

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/Symfony/Component/VarDumper/Tests/Caster/IntlCasterTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ public function testCastDateFormatter()
234234
$var = new \IntlDateFormatter('en', \IntlDateFormatter::TRADITIONAL, \IntlDateFormatter::TRADITIONAL);
235235

236236
$expectedLocale = $var->getLocale();
237-
$expectedPattern = $var->getPattern();
237+
$expectedPattern = $this->normalizeNarrowNoBreakSpaceCharacter($var->getPattern());
238238
$expectedCalendar = $var->getCalendar();
239239
$expectedTimeZoneId = $var->getTimeZoneId();
240240
$expectedTimeType = $var->getTimeType();
@@ -294,4 +294,9 @@ public function testCastDateFormatter()
294294
EOTXT;
295295
$this->assertDumpEquals($expected, $var);
296296
}
297+
298+
private function normalizeNarrowNoBreakSpaceCharacter(string $input): string
299+
{
300+
return str_replace("\u{202F}", '\\u{202F}', $input);
301+
}
297302
}

0 commit comments

Comments
 (0)