Skip to content

Commit 4dd5c5b

Browse files
Merge branch '5.4' into 6.0
* 5.4: [FrameworkBundle] fix merge [FrameworkBundle] Filter out trans paths that are covered by a parent folder path [Form] fix tests [Serializer] Fixed framework.serializer.default_context is not working for JsonEncoder [Ldap] Do not run ldap_set_option on failed connection Correct compare float data Fix AbstractFormLoginAuthenticator return types (fixes #47571). Run composer with --ignore-platform-req=php+ [FrameworkBundle] Fix a phpdoc in mailer assertions
2 parents 3763f0d + b41f68c commit 4dd5c5b

File tree

4 files changed

+64
-1
lines changed

4 files changed

+64
-1
lines changed

Command/TranslationUpdateCommand.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ private function extractMessages(string $locale, array $transPaths, string $pref
395395
{
396396
$extractedCatalogue = new MessageCatalogue($locale);
397397
$this->extractor->setPrefix($prefix);
398+
$transPaths = $this->filterDuplicateTransPaths($transPaths);
398399
foreach ($transPaths as $path) {
399400
if (is_dir($path) || is_file($path)) {
400401
$this->extractor->extract($path, $extractedCatalogue);
@@ -404,6 +405,27 @@ private function extractMessages(string $locale, array $transPaths, string $pref
404405
return $extractedCatalogue;
405406
}
406407

408+
private function filterDuplicateTransPaths(array $transPaths): array
409+
{
410+
$transPaths = array_filter(array_map('realpath', $transPaths));
411+
412+
sort($transPaths);
413+
414+
$filteredPaths = [];
415+
416+
foreach ($transPaths as $path) {
417+
foreach ($filteredPaths as $filteredPath) {
418+
if (str_starts_with($path, $filteredPath.\DIRECTORY_SEPARATOR)) {
419+
continue 2;
420+
}
421+
}
422+
423+
$filteredPaths[] = $path;
424+
}
425+
426+
return $filteredPaths;
427+
}
428+
407429
private function loadCurrentMessages(string $locale, array $transPaths): MessageCatalogue
408430
{
409431
$currentCatalogue = new MessageCatalogue($locale);

Resources/config/serializer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@
174174
->tag('serializer.encoder')
175175

176176
->set('serializer.encoder.json', JsonEncoder::class)
177+
->args([null, null])
177178
->tag('serializer.encoder')
178179

179180
->set('serializer.encoder.yaml', YamlEncoder::class)

Test/MailerAssertionsTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public static function assertEmailAddressContains(RawMessage $email, string $hea
9191
}
9292

9393
/**
94-
* @return MessageEvents[]
94+
* @return MessageEvent[]
9595
*/
9696
public static function getMailerEvents(string $transport = null): array
9797
{

Tests/Command/TranslationUpdateCommandTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,46 @@ public function testWriteMessagesForSpecificDomain()
140140
$this->assertMatchesRegularExpression('/Translation files were successfully updated./', $tester->getDisplay());
141141
}
142142

143+
public function testFilterDuplicateTransPaths()
144+
{
145+
$transPaths = [
146+
$this->translationDir.'/a/test/folder/with/a/subfolder',
147+
$this->translationDir.'/a/test/folder/',
148+
$this->translationDir.'/a/test/folder/with/a/subfolder/and/a/file.txt',
149+
$this->translationDir.'/a/different/test/folder',
150+
];
151+
152+
$expectedPaths = [
153+
$this->translationDir.'/a/different/test/folder',
154+
$this->translationDir.'/a/test/folder',
155+
];
156+
157+
foreach ($transPaths as $transPath) {
158+
if (realpath($transPath)) {
159+
continue;
160+
}
161+
162+
if (preg_match('/\.[a-z]+$/', $transPath)) {
163+
if (!realpath(\dirname($transPath))) {
164+
mkdir(\dirname($transPath), 0777, true);
165+
}
166+
167+
touch($transPath);
168+
} else {
169+
mkdir($transPath, 0777, true);
170+
}
171+
}
172+
173+
$command = $this->createMock(TranslationUpdateCommand::class);
174+
175+
$method = new \ReflectionMethod(TranslationUpdateCommand::class, 'filterDuplicateTransPaths');
176+
$method->setAccessible(true);
177+
178+
$filteredTransPaths = $method->invoke($command, $transPaths);
179+
180+
$this->assertEquals($expectedPaths, $filteredTransPaths);
181+
}
182+
143183
protected function setUp(): void
144184
{
145185
$this->fs = new Filesystem();

0 commit comments

Comments
 (0)