From 79b610c9b02efdd4ba438d7cb94521c022e8e39e Mon Sep 17 00:00:00 2001 From: PantherX99 <121259031+PantherX99@users.noreply.github.com> Date: Wed, 3 Jun 2026 22:29:31 +0200 Subject: [PATCH 1/4] Remove null caching for invalid language lookup Stop caching null values for languages because they might get created afterwards in the converters. --- src/Migration/Mapping/Lookup/LanguageLookup.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Migration/Mapping/Lookup/LanguageLookup.php b/src/Migration/Mapping/Lookup/LanguageLookup.php index 4204c422a..2704726cb 100644 --- a/src/Migration/Mapping/Lookup/LanguageLookup.php +++ b/src/Migration/Mapping/Lookup/LanguageLookup.php @@ -57,8 +57,6 @@ public function get(string $localeCode, Context $context): ?string $language = $this->getLanguage($localeUuid, $context); if (!$language instanceof LanguageEntity) { - $this->cache[$localeCode] = null; - return null; } From df6d7d2792c52ae0e0d9cda6d07232e4117408dc Mon Sep 17 00:00:00 2001 From: PantherX99 <121259031+PantherX99@users.noreply.github.com> Date: Thu, 4 Jun 2026 18:04:52 +0200 Subject: [PATCH 2/4] Add test for missing language caching in LanguageLookup --- .../Mapping/Lookup/LanguageLookupTest.php | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/tests/Migration/Mapping/Lookup/LanguageLookupTest.php b/tests/Migration/Mapping/Lookup/LanguageLookupTest.php index d77c692c8..6535cccce 100644 --- a/tests/Migration/Mapping/Lookup/LanguageLookupTest.php +++ b/tests/Migration/Mapping/Lookup/LanguageLookupTest.php @@ -7,6 +7,7 @@ namespace SwagMigrationAssistant\Test\Migration\Mapping\Lookup; +use Doctrine\DBAL\Connection; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Shopware\Core\Framework\Context; @@ -58,6 +59,63 @@ public function testGetShouldGetDataFromCache(string $localeCode, ?string $expec static::assertSame($expectedResult, $documentTypeLookup->get($localeCode, Context::createDefaultContext())); } + public function testGetDoesNotCacheMissingLanguage(): void + { + $context = Context::createDefaultContext(); + + $connection = static::getContainer()->get(Connection::class); + $languageRepository = static::getContainer()->get('language.repository'); + $localeRepository = static::getContainer()->get('locale.repository'); + + $locale = $connection->fetchAssociative(' + SELECT LOWER(HEX(locale.id)) AS id, locale.code + FROM locale + LEFT JOIN language ON language.locale_id = locale.id + WHERE language.id IS NULL + LIMIT 1 + '); + + if ($locale === false) { + static::markTestSkipped('No locale without language found.'); + } + + static::assertArrayHasKey('id', $locale); + static::assertArrayHasKey('code', $locale); + static::assertIsString($locale['id']); + static::assertIsString($locale['code']); + + $languageLookup = new LanguageLookup( + $languageRepository, + new LocaleLookup($localeRepository) + ); + + static::assertNull($languageLookup->get($locale['code'], $context)); + + $languageId = Uuid::randomHex(); + $languageCreated = false; + + try { + $languageRepository->create([ + [ + 'id' => $languageId, + 'name' => 'Test language ' . $locale['code'], + 'localeId' => $locale['id'], + 'translationCodeId' => $locale['id'], + ], + ], $context); + + $languageCreated = true; + + static::assertSame($languageId, $languageLookup->get($locale['code'], $context)); + } finally { + if ($languageCreated) { + $languageRepository->delete([ + ['id' => $languageId], + ], $context); + } + } + } + #[DataProvider('getLanguageIdData')] public function testGetDefaultLanguageEntity(string $languageId, ?string $expectedResult): void { From 93816a656cc372456745301a6564ac67ffd221de Mon Sep 17 00:00:00 2001 From: PantherX99 <121259031+PantherX99@users.noreply.github.com> Date: Thu, 4 Jun 2026 18:10:09 +0200 Subject: [PATCH 3/4] no whitespace in blank line --- .../Mapping/Lookup/LanguageLookupTest.php | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/Migration/Mapping/Lookup/LanguageLookupTest.php b/tests/Migration/Mapping/Lookup/LanguageLookupTest.php index 6535cccce..366bbe55c 100644 --- a/tests/Migration/Mapping/Lookup/LanguageLookupTest.php +++ b/tests/Migration/Mapping/Lookup/LanguageLookupTest.php @@ -62,11 +62,11 @@ public function testGetShouldGetDataFromCache(string $localeCode, ?string $expec public function testGetDoesNotCacheMissingLanguage(): void { $context = Context::createDefaultContext(); - + $connection = static::getContainer()->get(Connection::class); $languageRepository = static::getContainer()->get('language.repository'); $localeRepository = static::getContainer()->get('locale.repository'); - + $locale = $connection->fetchAssociative(' SELECT LOWER(HEX(locale.id)) AS id, locale.code FROM locale @@ -74,26 +74,26 @@ public function testGetDoesNotCacheMissingLanguage(): void WHERE language.id IS NULL LIMIT 1 '); - + if ($locale === false) { static::markTestSkipped('No locale without language found.'); } - + static::assertArrayHasKey('id', $locale); static::assertArrayHasKey('code', $locale); static::assertIsString($locale['id']); static::assertIsString($locale['code']); - + $languageLookup = new LanguageLookup( $languageRepository, new LocaleLookup($localeRepository) ); - + static::assertNull($languageLookup->get($locale['code'], $context)); - + $languageId = Uuid::randomHex(); $languageCreated = false; - + try { $languageRepository->create([ [ @@ -103,9 +103,9 @@ public function testGetDoesNotCacheMissingLanguage(): void 'translationCodeId' => $locale['id'], ], ], $context); - + $languageCreated = true; - + static::assertSame($languageId, $languageLookup->get($locale['code'], $context)); } finally { if ($languageCreated) { From f7bb89f59d49ca22853698cf1fc489c8e1a4e2c0 Mon Sep 17 00:00:00 2001 From: PantherX99 <121259031+PantherX99@users.noreply.github.com> Date: Fri, 5 Jun 2026 10:56:25 +0200 Subject: [PATCH 4/4] use random testLocale instead od db data --- .../Mapping/Lookup/LanguageLookupTest.php | 65 ++++++++----------- 1 file changed, 28 insertions(+), 37 deletions(-) diff --git a/tests/Migration/Mapping/Lookup/LanguageLookupTest.php b/tests/Migration/Mapping/Lookup/LanguageLookupTest.php index 366bbe55c..35ab34c59 100644 --- a/tests/Migration/Mapping/Lookup/LanguageLookupTest.php +++ b/tests/Migration/Mapping/Lookup/LanguageLookupTest.php @@ -7,7 +7,6 @@ namespace SwagMigrationAssistant\Test\Migration\Mapping\Lookup; -use Doctrine\DBAL\Connection; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Shopware\Core\Framework\Context; @@ -63,56 +62,48 @@ public function testGetDoesNotCacheMissingLanguage(): void { $context = Context::createDefaultContext(); - $connection = static::getContainer()->get(Connection::class); $languageRepository = static::getContainer()->get('language.repository'); $localeRepository = static::getContainer()->get('locale.repository'); - $locale = $connection->fetchAssociative(' - SELECT LOWER(HEX(locale.id)) AS id, locale.code - FROM locale - LEFT JOIN language ON language.locale_id = locale.id - WHERE language.id IS NULL - LIMIT 1 - '); - - if ($locale === false) { - static::markTestSkipped('No locale without language found.'); - } - - static::assertArrayHasKey('id', $locale); - static::assertArrayHasKey('code', $locale); - static::assertIsString($locale['id']); - static::assertIsString($locale['code']); + $localeId = Uuid::randomHex(); + $localeCode = 'zz-ZZ'; + $languageId = Uuid::randomHex(); - $languageLookup = new LanguageLookup( - $languageRepository, - new LocaleLookup($localeRepository) - ); + try { + $localeRepository->create([ + [ + 'id' => $localeId, + 'code' => $localeCode, + 'name' => 'Test Locale', + 'territory' => 'Test Territory', + ], + ], $context); - static::assertNull($languageLookup->get($locale['code'], $context)); + $languageLookup = new LanguageLookup( + $languageRepository, + new LocaleLookup($localeRepository) + ); - $languageId = Uuid::randomHex(); - $languageCreated = false; + static::assertNull($languageLookup->get($localeCode, $context)); - try { $languageRepository->create([ [ 'id' => $languageId, - 'name' => 'Test language ' . $locale['code'], - 'localeId' => $locale['id'], - 'translationCodeId' => $locale['id'], + 'name' => 'Test language', + 'localeId' => $localeId, + 'translationCodeId' => $localeId, ], ], $context); - $languageCreated = true; - - static::assertSame($languageId, $languageLookup->get($locale['code'], $context)); + static::assertSame($languageId, $languageLookup->get($localeCode, $context)); } finally { - if ($languageCreated) { - $languageRepository->delete([ - ['id' => $languageId], - ], $context); - } + $languageRepository->delete([ + ['id' => $languageId], + ], $context); + + $localeRepository->delete([ + ['id' => $localeId], + ], $context); } }