diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 3a0f7cf1..2ede9aee 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -16,3 +16,7 @@ parameters: paths: - src - tests + + ignoreErrors: + - # Shopware trunk classifies plugin test namespaces as non-Unit; unit tests here may still carry CoversClass + identifier: shopware.unexpectedTestCovers diff --git a/tests/Core/Framework/DataAbstractionLayer/Write/Validation/SalesChannelDomainValidatorTest.php b/tests/Core/Framework/DataAbstractionLayer/Write/Validation/SalesChannelDomainValidatorTest.php index e04be06e..f2dc739d 100644 --- a/tests/Core/Framework/DataAbstractionLayer/Write/Validation/SalesChannelDomainValidatorTest.php +++ b/tests/Core/Framework/DataAbstractionLayer/Write/Validation/SalesChannelDomainValidatorTest.php @@ -14,11 +14,15 @@ use Shopware\Core\Framework\Context; use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository; use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria; +use Shopware\Core\Framework\DataAbstractionLayer\Write\WriteException; use Shopware\Core\Framework\Uuid\Uuid; +use Shopware\Core\Framework\Validation\WriteConstraintViolationException; use Shopware\Core\System\SalesChannel\Aggregate\SalesChannelDomain\SalesChannelDomainDefinition; use Shopware\Core\System\SalesChannel\SalesChannelCollection; use Shopware\Core\Test\TestDefaults; use Swag\LanguagePack\Test\Helper\ServicesTrait; +use Symfony\Component\Validator\ConstraintViolation; +use Symfony\Component\Validator\ConstraintViolationList; class SalesChannelDomainValidatorTest extends TestCase { @@ -43,8 +47,20 @@ public function testCreatingASalesChannelDomainWithADeactivatedLanguageFails(): $context = Context::createDefaultContext(); $languageId = $this->prepareSalesChannelActiveForLanguageByName('Dansk', false, $context); - $this->expectExceptionMessage(\sprintf('The language with the id "%s" is disabled for all Sales Channels.', $languageId)); - $this->createSalesChannelDomain(Uuid::randomHex(), $languageId, $context); + $this->expectExceptionObject(new WriteConstraintViolationException( + new ConstraintViolationList([ + new ConstraintViolation(\sprintf('The language with the id "%s" is disabled for all Sales Channels.', $languageId), null, [], '', null, null), + ]), + )); + + try { + $this->createSalesChannelDomain(Uuid::randomHex(), $languageId, $context); + } catch (WriteException $e) { + foreach ($e->getExceptions() as $inner) { + throw $inner; + } + throw $e; + } } public function testUpdatingASalesChannelDomainToADisabledLanguageFails(): void @@ -61,13 +77,25 @@ public function testUpdatingASalesChannelDomainToADisabledLanguageFails(): void $domain = $this->salesChannelDomainRepository->search($criteria, $context)->first(); static::assertNotNull($domain); - $this->expectExceptionMessage(\sprintf('The language with the id "%s" is disabled for all Sales Channels.', $disabledLanguageId)); - $this->salesChannelDomainRepository->update([ - [ - 'id' => $domainId, - 'languageId' => $disabledLanguageId, - ], - ], $context); + $this->expectExceptionObject(new WriteConstraintViolationException( + new ConstraintViolationList([ + new ConstraintViolation(\sprintf('The language with the id "%s" is disabled for all Sales Channels.', $disabledLanguageId), null, [], '', null, null), + ]), + )); + + try { + $this->salesChannelDomainRepository->update([ + [ + 'id' => $domainId, + 'languageId' => $disabledLanguageId, + ], + ], $context); + } catch (WriteException $e) { + foreach ($e->getExceptions() as $inner) { + throw $inner; + } + throw $e; + } } private function createSalesChannelDomain(string $domainId, string $languageId, Context $context): void diff --git a/tests/Core/Framework/DataAbstractionLayer/Write/Validation/SalesChannelLanguageValidatorTest.php b/tests/Core/Framework/DataAbstractionLayer/Write/Validation/SalesChannelLanguageValidatorTest.php index 49eb39d9..0ae07f5b 100644 --- a/tests/Core/Framework/DataAbstractionLayer/Write/Validation/SalesChannelLanguageValidatorTest.php +++ b/tests/Core/Framework/DataAbstractionLayer/Write/Validation/SalesChannelLanguageValidatorTest.php @@ -12,10 +12,14 @@ use PHPUnit\Framework\TestCase; use Shopware\Core\Framework\Context; use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository; +use Shopware\Core\Framework\DataAbstractionLayer\Write\WriteException; +use Shopware\Core\Framework\Validation\WriteConstraintViolationException; use Shopware\Core\System\SalesChannel\Aggregate\SalesChannelLanguage\SalesChannelLanguageDefinition; use Shopware\Core\System\SalesChannel\SalesChannelCollection; use Shopware\Core\Test\TestDefaults; use Swag\LanguagePack\Test\Helper\ServicesTrait; +use Symfony\Component\Validator\ConstraintViolation; +use Symfony\Component\Validator\ConstraintViolationList; class SalesChannelLanguageValidatorTest extends TestCase { @@ -40,8 +44,20 @@ public function testCreatingASalesChannelLanguageWithADeactivatedLanguageFails() $context = Context::createDefaultContext(); $languageId = $this->prepareSalesChannelActiveForLanguageByName('Dansk', false, $context); - $this->expectExceptionMessage(\sprintf('The language with the id "%s" is disabled for all Sales Channels.', $languageId)); - $this->createSalesChannelLanguage($languageId, $context); + $this->expectExceptionObject(new WriteConstraintViolationException( + new ConstraintViolationList([ + new ConstraintViolation(\sprintf('The language with the id "%s" is disabled for all Sales Channels.', $languageId), null, [], '', null, null), + ]), + )); + + try { + $this->createSalesChannelLanguage($languageId, $context); + } catch (WriteException $e) { + foreach ($e->getExceptions() as $inner) { + throw $inner; + } + throw $e; + } } private function createSalesChannelLanguage(string $languageId, Context $context): void diff --git a/tests/Core/Framework/DataAbstractionLayer/Write/Validation/SalesChannelValidatorTest.php b/tests/Core/Framework/DataAbstractionLayer/Write/Validation/SalesChannelValidatorTest.php index cdc892be..3c3f4b02 100644 --- a/tests/Core/Framework/DataAbstractionLayer/Write/Validation/SalesChannelValidatorTest.php +++ b/tests/Core/Framework/DataAbstractionLayer/Write/Validation/SalesChannelValidatorTest.php @@ -14,11 +14,15 @@ use Shopware\Core\Framework\Context; use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository; use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria; +use Shopware\Core\Framework\DataAbstractionLayer\Write\WriteException; use Shopware\Core\Framework\Uuid\Uuid; +use Shopware\Core\Framework\Validation\WriteConstraintViolationException; use Shopware\Core\System\SalesChannel\SalesChannelCollection; use Shopware\Core\System\SalesChannel\SalesChannelDefinition; use Shopware\Core\Test\TestDefaults; use Swag\LanguagePack\Test\Helper\ServicesTrait; +use Symfony\Component\Validator\ConstraintViolation; +use Symfony\Component\Validator\ConstraintViolationList; class SalesChannelValidatorTest extends TestCase { @@ -43,8 +47,20 @@ public function testCreatingASalesChannelWithADeactivatedDefaultLanguageFails(): $context = Context::createDefaultContext(); $languageId = $this->prepareSalesChannelActiveForLanguageByName('Dansk', false, $context); - $this->expectExceptionMessage(\sprintf('The language with the id "%s" is disabled for all Sales Channels.', $languageId)); - $this->createSalesChannelWithLanguage(Uuid::randomHex(), $languageId, $context); + $this->expectExceptionObject(new WriteConstraintViolationException( + new ConstraintViolationList([ + new ConstraintViolation(\sprintf('The language with the id "%s" is disabled for all Sales Channels.', $languageId), null, [], '', null, null), + ]), + )); + + try { + $this->createSalesChannelWithLanguage(Uuid::randomHex(), $languageId, $context); + } catch (WriteException $e) { + foreach ($e->getExceptions() as $inner) { + throw $inner; + } + throw $e; + } } public function testThatUpdatingASalesChannelToADisabledSalesChannelFails(): void @@ -61,12 +77,24 @@ public function testThatUpdatingASalesChannelToADisabledSalesChannelFails(): voi $salesChannel = $this->salesChannelRepository->search($criteria, $context)->first(); static::assertNotNull($salesChannel); - $this->expectExceptionMessage(\sprintf('The language with the id "%s" is disabled for all Sales Channels.', $disabledLanguageId)); - $this->salesChannelRepository->update([[ - 'id' => $salesChannelId, - 'languageId' => $disabledLanguageId, - 'languages' => [['id' => $disabledLanguageId]], - ]], $context); + $this->expectExceptionObject(new WriteConstraintViolationException( + new ConstraintViolationList([ + new ConstraintViolation(\sprintf('The language with the id "%s" is disabled for all Sales Channels.', $disabledLanguageId), null, [], '', null, null), + ]), + )); + + try { + $this->salesChannelRepository->update([[ + 'id' => $salesChannelId, + 'languageId' => $disabledLanguageId, + 'languages' => [['id' => $disabledLanguageId]], + ]], $context); + } catch (WriteException $e) { + foreach ($e->getExceptions() as $inner) { + throw $inner; + } + throw $e; + } } private function createSalesChannelWithLanguage(string $salesChannelId, string $languageId, Context $context): void diff --git a/tests/Core/Framework/DataAbstractionLayer/Write/Validation/UserValidatorTest.php b/tests/Core/Framework/DataAbstractionLayer/Write/Validation/UserValidatorTest.php index 5a8389ee..8e658a1b 100644 --- a/tests/Core/Framework/DataAbstractionLayer/Write/Validation/UserValidatorTest.php +++ b/tests/Core/Framework/DataAbstractionLayer/Write/Validation/UserValidatorTest.php @@ -13,10 +13,14 @@ use Shopware\Core\Framework\Context; use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository; use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria; +use Shopware\Core\Framework\DataAbstractionLayer\Write\WriteException; use Shopware\Core\Framework\Uuid\Uuid; +use Shopware\Core\Framework\Validation\WriteConstraintViolationException; use Shopware\Core\System\User\UserCollection; use Shopware\Core\System\User\UserDefinition; use Swag\LanguagePack\Test\Helper\ServicesTrait; +use Symfony\Component\Validator\ConstraintViolation; +use Symfony\Component\Validator\ConstraintViolationList; class UserValidatorTest extends TestCase { @@ -41,8 +45,20 @@ public function testCreateUserWithADeactivatedLanguageFails(): void $context = Context::createDefaultContext(); $localeId = $this->prepareAdministrationActiveForLanguageByLocale('da-DK', false, $context); - $this->expectExceptionMessage(\sprintf('The language bound to the locale with the id "%s" is disabled for the Administration.', $localeId)); - $this->createUser(Uuid::randomHex(), $localeId, $context); + $this->expectExceptionObject(new WriteConstraintViolationException( + new ConstraintViolationList([ + new ConstraintViolation(\sprintf('The language bound to the locale with the id "%s" is disabled for the Administration.', $localeId), null, [], '', null, null), + ]), + )); + + try { + $this->createUser(Uuid::randomHex(), $localeId, $context); + } catch (WriteException $e) { + foreach ($e->getExceptions() as $inner) { + throw $inner; + } + throw $e; + } } public function testUpdateUserToDisabledLanguageFails(): void @@ -59,11 +75,23 @@ public function testUpdateUserToDisabledLanguageFails(): void $user = $this->userRepository->search($criteria, $context)->first(); static::assertNotNull($user); - $this->expectExceptionMessage(\sprintf('The language bound to the locale with the id "%s" is disabled for the Administration.', $disabledLocaleId)); - $this->userRepository->update([[ - 'id' => $userId, - 'localeId' => $disabledLocaleId, - ]], $context); + $this->expectExceptionObject(new WriteConstraintViolationException( + new ConstraintViolationList([ + new ConstraintViolation(\sprintf('The language bound to the locale with the id "%s" is disabled for the Administration.', $disabledLocaleId), null, [], '', null, null), + ]), + )); + + try { + $this->userRepository->update([[ + 'id' => $userId, + 'localeId' => $disabledLocaleId, + ]], $context); + } catch (WriteException $e) { + foreach ($e->getExceptions() as $inner) { + throw $inner; + } + throw $e; + } } private function createUser(string $userId, string $localeId, Context $context): void diff --git a/tests/Util/Migration/MigrationHelperTest.php b/tests/Util/Migration/MigrationHelperTest.php index 005eeca4..2e3cd749 100644 --- a/tests/Util/Migration/MigrationHelperTest.php +++ b/tests/Util/Migration/MigrationHelperTest.php @@ -25,6 +25,7 @@ use Shopware\Core\System\Language\LanguageDefinition; use Swag\LanguagePack\PackLanguage\PackLanguageDefinition; use Swag\LanguagePack\SwagLanguagePack; +use Swag\LanguagePack\Util\Exception\LanguagePackException; use Swag\LanguagePack\Util\Lifecycle\Lifecycle; use Swag\LanguagePack\Util\Migration\MigrationHelper; @@ -135,7 +136,12 @@ public function testMissingLocaleWhileCreating(): void $this->migrationHelper->createPackLanguageTable(); $this->migrationHelper->alterLanguageAddPackLanguageColumn(); - $this->expectExceptionMessage('No LocaleEntities associated to the following locale codes: bg-BG, bs-BA, cs-CZ, da-DK, el-GR, en-US, es-ES, fi-FI, fr-FR, hi-IN, hr-HR, hu-HU, id-ID, it-IT, ko-KR, lv-LV, nl-NL, nn-NO, pl-PL, pt-PT, ro-RO, ru-RU, sk-SK, sl-SI, sr-RS, sv-SE, tr-TR, uk-UA, vi-VN'); + $this->expectExceptionObject(LanguagePackException::installWithoutLocales([ + 'bg-BG', 'bs-BA', 'cs-CZ', 'da-DK', 'el-GR', 'en-US', 'es-ES', 'fi-FI', 'fr-FR', + 'hi-IN', 'hr-HR', 'hu-HU', 'id-ID', 'it-IT', 'ko-KR', 'lv-LV', 'nl-NL', 'nn-NO', + 'pl-PL', 'pt-PT', 'ro-RO', 'ru-RU', 'sk-SK', 'sl-SI', 'sr-RS', 'sv-SE', 'tr-TR', + 'uk-UA', 'vi-VN', + ])); $mockedMigrationHelper = new MigrationHelper($connectionMock); $mockedMigrationHelper->createPackLanguages();