From 887c02b60f0694779a81de2d672a70c0787c5306 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 4 Jun 2024 09:21:06 +0200 Subject: [PATCH 1/2] Update friendsofphp/php-cs-fixer requirement from 3.57.2 to 3.58.1 (#65) Updates the requirements on [friendsofphp/php-cs-fixer](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer) to permit the latest version. - [Release notes](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/releases) - [Changelog](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/master/CHANGELOG.md) - [Commits](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/compare/v3.57.2...v3.58.1) --- updated-dependencies: - dependency-name: friendsofphp/php-cs-fixer dependency-type: direct:development ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index ccdea90..5d62f4c 100644 --- a/composer.json +++ b/composer.json @@ -41,7 +41,7 @@ "shopware/storefront": "6.5.*|6.6.*" }, "require-dev": { - "friendsofphp/php-cs-fixer": "3.57.2", + "friendsofphp/php-cs-fixer": "3.58.1", "phpstan/phpstan": "^1.10", "vimeo/psalm": "^5.20" }, From 8bff2e9bbd012c316e008466c36c352498bfae2a Mon Sep 17 00:00:00 2001 From: Jordan Kniest Date: Fri, 14 Jun 2024 08:51:33 +0200 Subject: [PATCH 2/2] Update test trait & harden psalm linting (#63) * Dont run vendor fixtures by default, add flag to run vendor fixtures * Trailing slashes! * Change docs formats * Use first class callable syntax * Refactor FixtureTrait * Enable phpstan rule: checkMissingIterableValueType * Enable rule checkGenericClassInNonGenericObjectType in psalm * Disable error warnings if generics arent provided, since they were added in SW 6.5.something --- CHANGELOG.md | 5 ++ phpstan.neon | 6 ++- psalm.xml | 4 +- src/FixtureLoader.php | 6 +++ src/FixtureOption.php | 3 ++ src/FixtureTrait.php | 81 +++++++++++++------------------ src/Utils/CategoryUtils.php | 4 ++ src/Utils/CmsUtils.php | 4 ++ src/Utils/CustomerUtils.php | 4 ++ src/Utils/MediaUtils.php | 6 +++ src/Utils/PaymentMethodUtils.php | 4 ++ src/Utils/SalesChannelUtils.php | 16 ++++++ src/Utils/ShippingMethodUtils.php | 4 ++ 13 files changed, 96 insertions(+), 51 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a31b7a..fd50aef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Changed argument type on `SalesChannelUtils::getTax()` from `int` to `float` - **Breaking** By default no fixtures in the vendor directory are loaded. Added option `--vendor` to load them +- Refactored `FixtureTrait` to not use command anymore but direct Fixture Loader + - `FixtureTrait::loadFixtures` now takes in a FixtureOption parameter + - `FixtureTrait::runSpecificFixtures` is an alias to run specific fixtures with optionally dependencies + - `FixtureTrait::runSingleFixture` (before `FixtureTrait::runSingleFixtureWithDependencies`) with dependencies can now be configured as the second parameter + - `FixtureTrait::runFixtureGroup` is a new function to execute whole fixture groups with optionally dependencies ### Removed - Dropped support for PHP 8.1 diff --git a/phpstan.neon b/phpstan.neon index 7825684..ba61e1d 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -5,5 +5,7 @@ parameters: # The level 9 is the highest level level: 9 - checkMissingIterableValueType: false - checkGenericClassInNonGenericObjectType: false + ignoreErrors: + # This is ignored until we drop support for Shopware 6.5 + - message: '#Shopware\\Core\\Framework\\DataAbstractionLayer\\EntityRepository is not generic\.#' + reportUnmatched: false diff --git a/psalm.xml b/psalm.xml index 8cf9f21..c2d6ed6 100644 --- a/psalm.xml +++ b/psalm.xml @@ -14,10 +14,12 @@ - + + + diff --git a/src/FixtureLoader.php b/src/FixtureLoader.php index d96b684..1b3cf08 100644 --- a/src/FixtureLoader.php +++ b/src/FixtureLoader.php @@ -8,8 +8,12 @@ class FixtureLoader { + /** @var array */ private readonly array $fixtures; + /** + * @param \Traversable $fixtures + */ public function __construct(\Traversable $fixtures) { $this->fixtures = iterator_to_array($fixtures); @@ -127,6 +131,8 @@ private function checkThatAllDependenciesAreInGroup( /** * Check if dependencies of fixture are also in the same group. If not, show error and stop process. + * + * @param array $references */ private function checkDependenciesAreInSameGroup( Fixture $fixture, diff --git a/src/FixtureOption.php b/src/FixtureOption.php index 72afc09..fc4e1b9 100644 --- a/src/FixtureOption.php +++ b/src/FixtureOption.php @@ -6,6 +6,9 @@ readonly class FixtureOption { + /** + * @param array $fixtureNames + */ public function __construct( public bool $dryMode = false, public ?string $groupName = null, diff --git a/src/FixtureTrait.php b/src/FixtureTrait.php index 72a0d27..26c2649 100644 --- a/src/FixtureTrait.php +++ b/src/FixtureTrait.php @@ -4,69 +4,54 @@ namespace Basecom\FixturePlugin; -use Shopware\Core\Framework\Test\TestCaseBase\KernelLifecycleManager; -use Symfony\Bundle\FrameworkBundle\Console\Application; -use Symfony\Component\Console\Input\ArrayInput; -use Symfony\Component\Console\Output\BufferedOutput; -use Symfony\Component\Console\Output\ConsoleOutput; +use Shopware\Core\Framework\DependencyInjection\DependencyInjectionException; +use Shopware\Core\Framework\Test\TestCaseBase\IntegrationTestBehaviour; trait FixtureTrait { - private function runFixtures(?array $fixtures = []): void - { - if (empty($fixtures)) { - $application = new Application(KernelLifecycleManager::getKernel()); - $fixtureCommand = $application->find('fixture:load'); - - $returnCode = $fixtureCommand->run( - new ArrayInput( - $fixtures, - $fixtureCommand->getDefinition(), - ), - new BufferedOutput(), // use new ConsoleOutput() if you don't want to hide output, new BufferedOutput() - ); + use IntegrationTestBehaviour; - if ($returnCode !== 0) { - throw new \RuntimeException('fixture:load'); - } + private function runFixtures(FixtureOption $options): void + { + $fixtureLoader = $this->getContainer()->get(FixtureLoader::class); - return; + if (!$fixtureLoader instanceof FixtureLoader) { + throw new DependencyInjectionException(404, 'FIXTURE_LOADER_NOT_FOUND', 'Fixture Loader not found in container'); } - foreach ($fixtures as $fixture) { - $application = new Application(KernelLifecycleManager::getKernel()); + $fixtureLoader->run($options); + } - $fixtureCommand = $application->find('fixture:load:single'); + /** + * @param array $fixtures + */ + private function runSpecificFixtures(array $fixtures = [], bool $withDependencies = false): void + { + $options = new FixtureOption( + fixtureNames: $fixtures, + withDependencies: $withDependencies, + ); - $returnCode = $fixtureCommand->run( - new ArrayInput( - ['fixtureName' => $fixture], - $fixtureCommand->getDefinition(), - ), - new BufferedOutput(), // use new ConsoleOutput() if you don't want to hide output, new BufferedOutput() - ); - if ($returnCode !== 0) { - throw new \RuntimeException('fixture:single'); - } - } + $this->runFixtures($options); } - private function runSingleFixtureWithDependencies(string $fixture): void + private function runSingleFixture(string $fixture, bool $withDependencies = false): void { - $application = new Application(KernelLifecycleManager::getKernel()); + $options = new FixtureOption( + fixtureNames: [$fixture], + withDependencies: $withDependencies, + ); - $fixtureCommand = $application->find('fixture:load:single'); + $this->runFixtures($options); + } - $returnCode = $fixtureCommand->run( - new ArrayInput( - ['fixtureName' => $fixture, '--with-dependencies' => true], - $fixtureCommand->getDefinition(), - ), - new BufferedOutput(), + private function runFixtureGroup(string $group, bool $withDependencies = false): void + { + $options = new FixtureOption( + groupName: $group, + withDependencies: $withDependencies, ); - if ($returnCode !== 0) { - throw new \RuntimeException('fixture:single'); - } + $this->runFixtures($options); } } diff --git a/src/Utils/CategoryUtils.php b/src/Utils/CategoryUtils.php index fc0783f..e2968c0 100644 --- a/src/Utils/CategoryUtils.php +++ b/src/Utils/CategoryUtils.php @@ -6,6 +6,7 @@ namespace Basecom\FixturePlugin\Utils; +use Shopware\Core\Content\Category\CategoryCollection; use Shopware\Core\Content\Category\CategoryEntity; use Shopware\Core\Framework\Context; use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository; @@ -14,6 +15,9 @@ readonly class CategoryUtils { + /** + * @param EntityRepository $categoryRepository + */ public function __construct( private EntityRepository $categoryRepository, ) { diff --git a/src/Utils/CmsUtils.php b/src/Utils/CmsUtils.php index 1203ea3..b3aaac0 100644 --- a/src/Utils/CmsUtils.php +++ b/src/Utils/CmsUtils.php @@ -4,6 +4,7 @@ namespace Basecom\FixturePlugin\Utils; +use Shopware\Core\Content\Cms\CmsPageCollection; use Shopware\Core\Content\Cms\CmsPageEntity; use Shopware\Core\Framework\Context; use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository; @@ -13,6 +14,9 @@ readonly class CmsUtils { + /** + * @param EntityRepository $cmsPageRepository + */ public function __construct( private EntityRepository $cmsPageRepository, ) { diff --git a/src/Utils/CustomerUtils.php b/src/Utils/CustomerUtils.php index c065bb9..678283d 100644 --- a/src/Utils/CustomerUtils.php +++ b/src/Utils/CustomerUtils.php @@ -8,10 +8,14 @@ use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository; use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria; use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter; +use Shopware\Core\System\Salutation\SalutationCollection; use Shopware\Core\System\Salutation\SalutationEntity; readonly class CustomerUtils { + /** + * @param EntityRepository $salutationRepository + */ public function __construct( private EntityRepository $salutationRepository, ) { diff --git a/src/Utils/MediaUtils.php b/src/Utils/MediaUtils.php index 03394fe..297c016 100644 --- a/src/Utils/MediaUtils.php +++ b/src/Utils/MediaUtils.php @@ -4,9 +4,11 @@ namespace Basecom\FixturePlugin\Utils; +use Shopware\Core\Content\Media\Aggregate\MediaFolder\MediaFolderCollection; use Shopware\Core\Content\Media\Aggregate\MediaFolder\MediaFolderEntity; use Shopware\Core\Content\Media\File\FileFetcher; use Shopware\Core\Content\Media\File\FileSaver; +use Shopware\Core\Content\Media\MediaCollection; use Shopware\Core\Framework\Context; use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository; use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria; @@ -14,6 +16,10 @@ readonly class MediaUtils { + /** + * @param EntityRepository $mediaRepository + * @param EntityRepository $mediaFolderRepository + */ public function __construct( private EntityRepository $mediaRepository, private EntityRepository $mediaFolderRepository, diff --git a/src/Utils/PaymentMethodUtils.php b/src/Utils/PaymentMethodUtils.php index 668a58c..e980f07 100644 --- a/src/Utils/PaymentMethodUtils.php +++ b/src/Utils/PaymentMethodUtils.php @@ -5,6 +5,7 @@ namespace Basecom\FixturePlugin\Utils; use Shopware\Core\Checkout\Payment\Cart\PaymentHandler\InvoicePayment; +use Shopware\Core\Checkout\Payment\PaymentMethodCollection; use Shopware\Core\Checkout\Payment\PaymentMethodEntity; use Shopware\Core\Framework\Context; use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository; @@ -13,6 +14,9 @@ readonly class PaymentMethodUtils { + /** + * @param EntityRepository $paymentMethodRepository + */ public function __construct( private EntityRepository $paymentMethodRepository, ) { diff --git a/src/Utils/SalesChannelUtils.php b/src/Utils/SalesChannelUtils.php index cb8286e..89f6086 100644 --- a/src/Utils/SalesChannelUtils.php +++ b/src/Utils/SalesChannelUtils.php @@ -9,16 +9,32 @@ use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository; use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria; use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter; +use Shopware\Core\System\Country\CountryCollection; use Shopware\Core\System\Country\CountryEntity; +use Shopware\Core\System\Currency\CurrencyCollection; use Shopware\Core\System\Currency\CurrencyEntity; +use Shopware\Core\System\Language\LanguageCollection; use Shopware\Core\System\Language\LanguageEntity; +use Shopware\Core\System\Locale\LocaleCollection; use Shopware\Core\System\Locale\LocaleEntity; +use Shopware\Core\System\SalesChannel\SalesChannelCollection; use Shopware\Core\System\SalesChannel\SalesChannelEntity; +use Shopware\Core\System\Snippet\Aggregate\SnippetSet\SnippetSetCollection; use Shopware\Core\System\Snippet\Aggregate\SnippetSet\SnippetSetEntity; +use Shopware\Core\System\Tax\TaxCollection; use Shopware\Core\System\Tax\TaxEntity; readonly class SalesChannelUtils { + /** + * @param EntityRepository $salesChannelRepository + * @param EntityRepository $snippetSetRepository + * @param EntityRepository $taxRepository + * @param EntityRepository $countryRepository + * @param EntityRepository $languageRepository + * @param EntityRepository $currencyRepository + * @param EntityRepository $localeRepository + */ public function __construct( private EntityRepository $salesChannelRepository, private EntityRepository $snippetSetRepository, diff --git a/src/Utils/ShippingMethodUtils.php b/src/Utils/ShippingMethodUtils.php index b8e625c..0ee6b19 100644 --- a/src/Utils/ShippingMethodUtils.php +++ b/src/Utils/ShippingMethodUtils.php @@ -4,6 +4,7 @@ namespace Basecom\FixturePlugin\Utils; +use Shopware\Core\Checkout\Shipping\ShippingMethodCollection; use Shopware\Core\Checkout\Shipping\ShippingMethodEntity; use Shopware\Core\Framework\Context; use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository; @@ -12,6 +13,9 @@ readonly class ShippingMethodUtils { + /** + * @param EntityRepository $shippingMethodRepository + */ public function __construct( private EntityRepository $shippingMethodRepository, ) {