Skip to content

Commit e16c0e4

Browse files
Merge branch '6.1' into 6.2
* 6.1: [DI] fix tests [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 Bugfix: add \UnitEnum as a result of get() method Fix AbstractFormLoginAuthenticator return types (fixes #47571). Run composer with --ignore-platform-req=php+ [FrameworkBundle] Fix a phpdoc in mailer assertions
2 parents ba6d479 + 1f77f32 commit e16c0e4

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
@@ -389,6 +389,7 @@ private function extractMessages(string $locale, array $transPaths, string $pref
389389
{
390390
$extractedCatalogue = new MessageCatalogue($locale);
391391
$this->extractor->setPrefix($prefix);
392+
$transPaths = $this->filterDuplicateTransPaths($transPaths);
392393
foreach ($transPaths as $path) {
393394
if (is_dir($path) || is_file($path)) {
394395
$this->extractor->extract($path, $extractedCatalogue);
@@ -398,6 +399,27 @@ private function extractMessages(string $locale, array $transPaths, string $pref
398399
return $extractedCatalogue;
399400
}
400401

402+
private function filterDuplicateTransPaths(array $transPaths): array
403+
{
404+
$transPaths = array_filter(array_map('realpath', $transPaths));
405+
406+
sort($transPaths);
407+
408+
$filteredPaths = [];
409+
410+
foreach ($transPaths as $path) {
411+
foreach ($filteredPaths as $filteredPath) {
412+
if (str_starts_with($path, $filteredPath.\DIRECTORY_SEPARATOR)) {
413+
continue 2;
414+
}
415+
}
416+
417+
$filteredPaths[] = $path;
418+
}
419+
420+
return $filteredPaths;
421+
}
422+
401423
private function loadCurrentMessages(string $locale, array $transPaths): MessageCatalogue
402424
{
403425
$currentCatalogue = new MessageCatalogue($locale);

Resources/config/serializer.php

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

179179
->set('serializer.encoder.json', JsonEncoder::class)
180+
->args([null, null])
180181
->tag('serializer.encoder')
181182

182183
->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)