From 68cfaa340e8eb921379d8618919b32a11aee655f Mon Sep 17 00:00:00 2001 From: Alexander Hofbauer Date: Tue, 19 Oct 2021 16:39:33 +0200 Subject: [PATCH 01/15] Apply changes from #101 by @aleho --- .github/workflows/build.yml | 14 +- composer.json | 22 +-- easy-coding-standard.yml | 9 - ecs.php | 14 ++ src/AttributeOptions/Importer.php | 2 +- src/Command/EnqueueCommand.php | 11 +- src/Command/ReconcileCommand.php | 3 +- src/Converter/ValueConverter.php | 2 +- src/Product/Importer.php | 18 +- src/Product/ProductOptionsResolver.php | 10 +- src/ProductAssociations/Importer.php | 6 +- src/ValueHandler/AttributeValueHandler.php | 2 +- src/ValueHandler/ImageValueHandler.php | 2 +- .../ImmutableSlugValueHandler.php | 6 +- .../ProductOptionValueHandler.php | 4 +- .../TranslatablePropertyValueHandler.php | 2 +- tests/Application/Kernel.php | 33 ++-- tests/Application/config/bundles.php | 3 - .../Application/config/packages/_sylius.yaml | 1 - .../config/packages/twig_extensions.yaml | 11 -- .../config/sylius/1.10/bundles.php | 6 + .../1.10/packages/dev/jms_serializer.yaml | 12 ++ .../sylius/1.10/packages/jms_serializer.yaml | 4 + .../1.10/packages/prod/jms_serializer.yaml | 10 ++ .../config/sylius/1.10/packages/security.yaml | 148 ++++++++++++++++ .../Application/config/sylius/1.8/bundles.php | 2 + .../config/sylius/1.8/packages/_sylius.yaml | 2 + .../{ => sylius/1.8}/packages/security.yaml | 13 +- .../1.8}/routes/sylius_admin_api.yaml | 0 .../Application/config/sylius/1.9/bundles.php | 2 + .../config/sylius/1.9/packages/_sylius.yaml | 2 + .../config/sylius/1.9/packages/security.yaml | 159 ++++++++++++++++++ .../sylius/1.9/routes/sylius_admin_api.yaml | 3 + .../4.4}/packages/framework.yaml | 0 34 files changed, 441 insertions(+), 97 deletions(-) delete mode 100644 easy-coding-standard.yml create mode 100644 ecs.php delete mode 100644 tests/Application/config/packages/twig_extensions.yaml create mode 100644 tests/Application/config/sylius/1.10/bundles.php create mode 100644 tests/Application/config/sylius/1.10/packages/dev/jms_serializer.yaml create mode 100644 tests/Application/config/sylius/1.10/packages/jms_serializer.yaml create mode 100644 tests/Application/config/sylius/1.10/packages/prod/jms_serializer.yaml create mode 100644 tests/Application/config/sylius/1.10/packages/security.yaml create mode 100644 tests/Application/config/sylius/1.8/packages/_sylius.yaml rename tests/Application/config/{ => sylius/1.8}/packages/security.yaml (90%) rename tests/Application/config/{ => sylius/1.8}/routes/sylius_admin_api.yaml (100%) create mode 100644 tests/Application/config/sylius/1.9/packages/_sylius.yaml create mode 100644 tests/Application/config/sylius/1.9/packages/security.yaml create mode 100644 tests/Application/config/sylius/1.9/routes/sylius_admin_api.yaml rename tests/Application/config/{sylius/1.8 => symfony/4.4}/packages/framework.yaml (100%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1440c0f5..833579fb 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -21,16 +21,16 @@ jobs: strategy: fail-fast: false matrix: - php: [7.4, 7.3] - symfony: [^4.4, ^5.2] - sylius: [~1.8.0, ~1.9.0] - node: [10.x] - mysql: [5.7] + php: ["8.0", "7.4"] + symfony: ["^4.4", "^5.2"] + sylius: ["~1.9.0", "~1.10.0"] + node: ["10.x"] + mysql: ["8.0"] exclude: - - sylius: ~1.8.0 - symfony: ^5.2 + php: "8.0" + sylius: "~1.9.0" env: APP_ENV: test diff --git a/composer.json b/composer.json index bef5cdd4..f28b007d 100644 --- a/composer.json +++ b/composer.json @@ -8,16 +8,13 @@ "description": "Plugin allowing to import products data from Akeneo PIM to your Sylius store.", "license": "MIT", "require": { - "php": "^7.3", + "php": "^7.4 || ^8.0", "cocur/slugify": "^4.0", "guzzlehttp/guzzle": "^6.5", - "sylius/sylius": "~1.8.0 || ~1.9.0", + "sylius/sylius": "~1.9.0 || ~1.10.0@beta", "symfony/deprecation-contracts": "^2.2", "symfony/lock": "^4.4|^5.0" }, - "conflict": { - "api-platform/core": "^2.6" - }, "require-dev": { "ext-json": "*", "behat/behat": "^3.6.1", @@ -26,37 +23,36 @@ "dmore/chrome-mink-driver": "^2.7", "friends-of-behat/mink": "^1.8", "friends-of-behat/mink-browserkit-driver": "^1.4", + "friends-of-behat/mink-debug-extension": "^2.0.0", "friends-of-behat/mink-extension": "^2.4", "friends-of-behat/page-object-extension": "^0.3", "friends-of-behat/suite-settings-extension": "^1.0", "friends-of-behat/symfony-extension": "^2.1", "friends-of-behat/variadic-extension": "^1.3", "friendsofsymfony/oauth-server-bundle": "^1.6 || >2.0.0-alpha.0 ^2.0@dev", - "lakion/mink-debug-extension": "^2.0.0", - "matthiasnoback/symfony-dependency-injection-test": "^4.2", - "mikey179/vfsstream": "^1.6", "phpspec/phpspec": "^7.0", "phpstan/extension-installer": "^1.0", - "phpstan/phpstan": "0.12.74", - "phpstan/phpstan-doctrine": "0.12.31", + "phpstan/phpstan": "0.12.85", + "phpstan/phpstan-doctrine": "0.12.33", + "phpstan/phpstan-strict-rules": "^0.12.0", "phpstan/phpstan-webmozart-assert": "0.12.12", "phpunit/phpunit": "^9.5", "sensiolabs/security-checker": "^6.0", - "sylius-labs/coding-standard": "^3.1", + "sylius-labs/coding-standard": "^4.0", "symfony/browser-kit": "^4.4 || ^5.2", "symfony/debug-bundle": "^4.4 || ^5.2", "symfony/dotenv": "^4.4 || ^5.2", "symfony/intl": "^4.4 || ^5.2", "symfony/web-profiler-bundle": "^4.4 || ^5.2", "theofidry/alice-data-fixtures": "^1.1", - "vimeo/psalm": "4.4.1" + "vimeo/psalm": "4.7.1" }, "config": { "sort-packages": true }, "extra": { "branch-alias": { - "dev-master": "1.9-dev" + "dev-master": "1.10-dev" } }, "autoload": { diff --git a/easy-coding-standard.yml b/easy-coding-standard.yml deleted file mode 100644 index 5feee0c4..00000000 --- a/easy-coding-standard.yml +++ /dev/null @@ -1,9 +0,0 @@ -imports: - - { resource: 'vendor/sylius-labs/coding-standard/easy-coding-standard.yml' } - -parameters: - exclude_files: - - 'tests/Application/*' - skip: - SlevomatCodingStandard\Sniffs\Commenting\InlineDocCommentDeclarationSniff.NoAssignment: ~ # This checker seems bugged - SlevomatCodingStandard\Sniffs\Commenting\InlineDocCommentDeclarationSniff.MissingVariable: ~ # This checker seems bugged diff --git a/ecs.php b/ecs.php new file mode 100644 index 00000000..bf40cc9f --- /dev/null +++ b/ecs.php @@ -0,0 +1,14 @@ +import('vendor/sylius-labs/coding-standard/ecs.php'); + + $containerConfigurator->parameters()->set(Option::SKIP, [ + VisibilityRequiredFixer::class => ['*Spec.php'], + ]); +}; diff --git a/src/AttributeOptions/Importer.php b/src/AttributeOptions/Importer.php index 16b75d5e..9d6f987d 100644 --- a/src/AttributeOptions/Importer.php +++ b/src/AttributeOptions/Importer.php @@ -72,7 +72,7 @@ public function getIdentifiersModifiedSince(\DateTime $sinceDate): array $syliusSelectAttributes = $this->attributeRepository->findBy(['type' => SelectAttributeType::TYPE]); $syliusSelectAttributes = array_filter( array_map( - function (ProductAttributeInterface $attribute) { + static function (ProductAttributeInterface $attribute): ?string { return $attribute->getCode(); }, $syliusSelectAttributes diff --git a/src/Command/EnqueueCommand.php b/src/Command/EnqueueCommand.php index d8f47fcf..b46bce02 100644 --- a/src/Command/EnqueueCommand.php +++ b/src/Command/EnqueueCommand.php @@ -90,7 +90,7 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { $sinceFilePath = null; - if ($sinceOptionValue = (string)$input->getOption(self::SINCE_OPTION_NAME)) { + if ('' !== $sinceOptionValue = (string)$input->getOption(self::SINCE_OPTION_NAME)) { try { $sinceDate = new \DateTime($sinceOptionValue); } catch (\Throwable $t) { @@ -98,7 +98,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int sprintf('The "%s" argument must be a valid date', self::SINCE_OPTION_NAME) ); } - } elseif ($sinceFilePath = (string)$input->getOption(self::SINCE_FILE_OPTION_NAME)) { + } elseif ('' !== $sinceFilePath = (string)$input->getOption(self::SINCE_FILE_OPTION_NAME)) { $sinceDate = $this->getSinceDateByFile($sinceFilePath); } elseif ($input->getOption(self::ALL_OPTION_NAME) === true) { $sinceDate = (new \DateTime())->setTimestamp(0); @@ -154,7 +154,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int } } - if ($sinceFilePath) { + if ($sinceFilePath !== null) { $this->writeSinceDateFile($sinceFilePath, $runDate); } @@ -201,7 +201,7 @@ private function writeSinceDateFile(string $filepath, \DateTime $runDate): void private function isEntityAlreadyQueuedToImport(string $akeneoEntity, string $akeneoIdentifier): bool { $queueItem = $this->queueItemRepository->findOneToImport($akeneoEntity, $akeneoIdentifier); - if ($queueItem) { + if ($queueItem !== null) { return true; } @@ -218,7 +218,7 @@ private function getImporters(InputInterface $input): array throw new \RuntimeException('There are no importers in registry.'); } $importersCodes = array_map( - static function (ImporterInterface $importer) { + static function (ImporterInterface $importer): string { return $importer->getAkeneoEntity(); }, $allImporters @@ -233,7 +233,6 @@ static function (ImporterInterface $importer) { } $allImporters = array_combine($importersCodes, $allImporters); - Assert::isArray($allImporters); $importers = []; foreach ($importersToUse as $importerToUse) { diff --git a/src/Command/ReconcileCommand.php b/src/Command/ReconcileCommand.php index 72b05785..cba5e4c0 100644 --- a/src/Command/ReconcileCommand.php +++ b/src/Command/ReconcileCommand.php @@ -86,7 +86,7 @@ private function getReconcilers(InputInterface $input): array return []; } $reconcilersCodes = array_map( - static function (ReconcilerInterface $reconciler) { + static function (ReconcilerInterface $reconciler): string { return $reconciler->getAkeneoEntity(); }, $allReconcilers @@ -101,7 +101,6 @@ static function (ReconcilerInterface $reconciler) { } $allReconcilers = array_combine($reconcilersCodes, $allReconcilers); - Assert::isArray($allReconcilers); $reconcilers = []; foreach ($reconcilersToUse as $reconcilerToUse) { diff --git a/src/Converter/ValueConverter.php b/src/Converter/ValueConverter.php index 9f63f992..8c589d11 100644 --- a/src/Converter/ValueConverter.php +++ b/src/Converter/ValueConverter.php @@ -65,7 +65,7 @@ public function convert(AttributeInterface $attribute, $value, string $localeCod $possibleOptionsCodes = array_map('strval', array_keys($choices)); $invalid = array_diff($value, $possibleOptionsCodes); - if (!empty($invalid)) { + if (count($invalid) > 0) { throw new \InvalidArgumentException( sprintf( 'This select attribute can only save existing attribute options. ' . diff --git a/src/Product/Importer.php b/src/Product/Importer.php index 7682f4be..13f04e0a 100644 --- a/src/Product/Importer.php +++ b/src/Product/Importer.php @@ -118,7 +118,7 @@ public function getAkeneoEntity(): string public function import(string $identifier): void { $productVariantResponse = $this->apiClient->findProduct($identifier); - if (!$productVariantResponse) { + if ($productVariantResponse === null) { throw new \RuntimeException(sprintf('Cannot find product "%s" on Akeneo.', $identifier)); } @@ -195,7 +195,7 @@ private function getOrCreateProductFromVariantResponse(array $productVariantResp $parentCode = $productVariantResponse['parent']; if ($parentCode !== null) { $product = $this->productRepository->findOneByCode($parentCode); - if (!$product) { + if ($product === null) { $product = $this->createNewProductFromAkeneoProduct($productVariantResponse); } @@ -203,7 +203,7 @@ private function getOrCreateProductFromVariantResponse(array $productVariantResp } $product = $this->productRepository->findOneByCode($identifier); - if (!$product) { + if ($product === null) { $product = $this->productFactory->createNew(); } Assert::isInstanceOf($product, ProductInterface::class); @@ -249,10 +249,10 @@ private function handleTaxons(ProductInterface $product, array $akeneoProduct): { $akeneoTaxons = new ArrayCollection($this->taxonsResolver->resolve($akeneoProduct)); $syliusTaxons = $product->getTaxons(); - $akeneoTaxonsCodes = $akeneoTaxons->map(function (TaxonInterface $taxon) {return $taxon->getCode(); })->toArray(); - $syliusTaxonsCodes = $syliusTaxons->map(function (TaxonInterface $taxon) {return $taxon->getCode(); })->toArray(); + $akeneoTaxonsCodes = $akeneoTaxons->map(function (TaxonInterface $taxon): ?string {return $taxon->getCode(); })->toArray(); + $syliusTaxonsCodes = $syliusTaxons->map(function (TaxonInterface $taxon): ?string {return $taxon->getCode(); })->toArray(); $toAddTaxons = $akeneoTaxons->filter( - function (TaxonInterface $taxon) use ($syliusTaxonsCodes) { + function (TaxonInterface $taxon) use ($syliusTaxonsCodes): bool { return !in_array($taxon->getCode(), $syliusTaxonsCodes, true); } ); @@ -325,7 +325,7 @@ public function reconcile(array $identifiersToReconcileWith): void /** @var ProductVariantInterface[] $productVariantsToReconcile */ $productVariantsToReconcile = $this->productVariantRepository->findAll(); /** @var string[] $identifiersToReconcile */ - $identifiersToReconcile = array_map(function ($productVariant) { + $identifiersToReconcile = array_map(static function ($productVariant): ?string { return $productVariant->getCode(); }, $productVariantsToReconcile); @@ -334,7 +334,7 @@ public function reconcile(array $identifiersToReconcileWith): void foreach ($identifiersToDisable as $productVariantIdentifierToDisable) { /** @var ?ProductVariantInterface $productVariantToDisable */ $productVariantToDisable = $this->productVariantRepository->findOneBy(['code' => $productVariantIdentifierToDisable]); - if (!$productVariantToDisable || !$productVariantToDisable->isEnabled()) { + if ($productVariantToDisable === null || !$productVariantToDisable->isEnabled()) { continue; } $productVariantToDisable->setEnabled(false); @@ -343,7 +343,7 @@ public function reconcile(array $identifiersToReconcileWith): void /** @var ?ProductInterface $product */ $product = $productVariantToDisable->getProduct(); - if (!$product || !$product->isEnabled() || count($product->getEnabledVariants()) > 0) { + if ($product === null || !$product->isEnabled() || count($product->getEnabledVariants()) > 0) { continue; } diff --git a/src/Product/ProductOptionsResolver.php b/src/Product/ProductOptionsResolver.php index 0f35762e..72000383 100644 --- a/src/Product/ProductOptionsResolver.php +++ b/src/Product/ProductOptionsResolver.php @@ -44,7 +44,7 @@ public function resolve(array $akeneoProduct): array { /** @var string|null $parentCode */ $parentCode = $akeneoProduct['parent'] ?? null; - if (!$parentCode) { + if ($parentCode === null) { throw new \RuntimeException( sprintf( 'Cannot resolve product options for Akeneo product "%s" because it does not belong to any ' . @@ -54,13 +54,13 @@ public function resolve(array $akeneoProduct): array ); } $productResponse = $this->apiClient->findProductModel($parentCode); - if (!$productResponse) { + if ($productResponse === null) { throw new \RuntimeException(sprintf('Cannot find product model "%s" on Akeneo.', $parentCode)); } $familyCode = $productResponse['family']; $familyVariantCode = $productResponse['family_variant']; $familyVariantResponse = $this->apiClient->findFamilyVariant($familyCode, $familyVariantCode); - if (!$familyVariantResponse) { + if ($familyVariantResponse === null) { throw new \RuntimeException( sprintf( 'Cannot find family variant "%s" within family "%s" on Akeneo.', @@ -73,7 +73,7 @@ public function resolve(array $akeneoProduct): array foreach ($familyVariantResponse['variant_attribute_sets'][0]['axes'] as $position => $attributeCode) { /** @var ProductOptionInterface|null $productOption */ $productOption = $this->productOptionRepository->findOneBy(['code' => $attributeCode]); - if ($productOption) { + if ($productOption !== null) { $productOptions[] = $productOption; continue; @@ -83,7 +83,7 @@ public function resolve(array $akeneoProduct): array $productOption->setCode($attributeCode); $productOption->setPosition($position); $attributeResponse = $this->apiClient->findAttribute($attributeCode); - if (!$attributeResponse) { + if ($attributeResponse === null) { throw new \RuntimeException( sprintf( 'Cannot resolve product options for product "%s" because one of its variant attributes, ' . diff --git a/src/ProductAssociations/Importer.php b/src/ProductAssociations/Importer.php index 2ef0b283..e4875b25 100644 --- a/src/ProductAssociations/Importer.php +++ b/src/ProductAssociations/Importer.php @@ -65,7 +65,7 @@ public function getAkeneoEntity(): string public function import(string $identifier): void { $productVariantResponse = $this->apiClient->findProduct($identifier); - if (!$productVariantResponse) { + if ($productVariantResponse === null) { throw new \RuntimeException(sprintf('Cannot find product "%s" on Akeneo.', $identifier)); } @@ -159,7 +159,7 @@ public function getIdentifiersModifiedSince(\DateTime $sinceDate): array private function getProductsToAdd(Collection $syliusAssociations, Collection $akeneoAssociations): Collection { return $akeneoAssociations->filter( - static function (BaseProductInterface $productToAssociate) use ($syliusAssociations) { + static function (BaseProductInterface $productToAssociate) use ($syliusAssociations): bool { return !$syliusAssociations->contains($productToAssociate); } ); @@ -173,7 +173,7 @@ static function (BaseProductInterface $productToAssociate) use ($syliusAssociati private function getProductsToRemove(Collection $syliusAssociations, Collection $akeneoAssociations): Collection { return $syliusAssociations->filter( - static function (BaseProductInterface $productToAssociate) use ($akeneoAssociations) { + static function (BaseProductInterface $productToAssociate) use ($akeneoAssociations): bool { return !$akeneoAssociations->contains($productToAssociate); } ); diff --git a/src/ValueHandler/AttributeValueHandler.php b/src/ValueHandler/AttributeValueHandler.php index d2ff12e1..bed3a67b 100644 --- a/src/ValueHandler/AttributeValueHandler.php +++ b/src/ValueHandler/AttributeValueHandler.php @@ -74,7 +74,7 @@ public function supports($subject, string $attributeCode, array $value): bool /** @var AttributeInterface|null $attribute */ $attribute = $this->attributeRepository->findOneBy(['code' => $attributeCode]); - return $attribute && $this->hasSupportedType($attribute); + return $attribute !== null && $this->hasSupportedType($attribute); } /** diff --git a/src/ValueHandler/ImageValueHandler.php b/src/ValueHandler/ImageValueHandler.php index 3da37917..e404b2f1 100644 --- a/src/ValueHandler/ImageValueHandler.php +++ b/src/ValueHandler/ImageValueHandler.php @@ -84,7 +84,7 @@ public function handle($subject, string $attribute, array $value): void $imageFile = $this->apiClient->downloadFile($mediaCode); $productImage = $this->getExistentProductVariantImage($subject, $product); - if (!$productImage) { + if ($productImage === null) { $productImage = $this->productImageFactory->createNew(); Assert::isInstanceOf($productImage, ProductImageInterface::class); /** @var ProductImageInterface $productImage */ diff --git a/src/ValueHandler/ImmutableSlugValueHandler.php b/src/ValueHandler/ImmutableSlugValueHandler.php index 01456ca7..306215fd 100644 --- a/src/ValueHandler/ImmutableSlugValueHandler.php +++ b/src/ValueHandler/ImmutableSlugValueHandler.php @@ -89,7 +89,7 @@ public function handle($subject, string $attribute, array $value): void } $productTranslation = $this->getOrCreateNewProductTranslation($product, $localeCode); - if ($productTranslation->getSlug()) { + if ($productTranslation->getSlug() !== null) { continue; } $slug = $this->slugify->slugify($valueToSlugify); @@ -118,7 +118,7 @@ private function setSlugOnAllTranslations(ProductInterface $product, string $val { foreach ($this->translationLocaleProvider->getDefinedLocalesCodes() as $localeCode) { $productTranslation = $this->getOrCreateNewProductTranslation($product, $localeCode); - if ($productTranslation->getSlug()) { + if ($productTranslation->getSlug() !== null) { continue; } $slug = $this->slugify->slugify($valueToSlugify); @@ -145,7 +145,7 @@ private function getDeduplicatedSlug( $anotherProductTranslation = $this->productTranslationRepository->findOneBy( ['slug' => $deduplicatedSlug, 'locale' => $localeCode] ); - if ($anotherProductTranslation && + if ($anotherProductTranslation !== null && $anotherProductTranslation->getTranslatable() instanceof ProductInterface && $anotherProductTranslation->getTranslatable()->getId() !== $product->getId()) { return $this->getDeduplicatedSlug($slug, $localeCode, $product, ++$increment); diff --git a/src/ValueHandler/ProductOptionValueHandler.php b/src/ValueHandler/ProductOptionValueHandler.php index e14107ab..2ee8b877 100644 --- a/src/ValueHandler/ProductOptionValueHandler.php +++ b/src/ValueHandler/ProductOptionValueHandler.php @@ -102,7 +102,7 @@ public function handle($productVariant, string $optionCode, array $akeneoValue): $partialValueCode = $akeneoValue[0]['data']; $fullValueCode = $optionCode . '_' . $partialValueCode; $akeneoAttributeOption = $this->apiClient->findAttributeOption($optionCode, $partialValueCode); - if (!$akeneoAttributeOption) { + if ($akeneoAttributeOption === null) { throw new \RuntimeException( sprintf( 'Cannot handle option value on Akeneo product "%s", the option of the parent product "%s" is ' . @@ -122,7 +122,7 @@ public function handle($productVariant, string $optionCode, array $akeneoValue): // return $productOption->getCode() === $optionCode; // } // )->first(); - if (!$productOption) { + if ($productOption === null) { throw new \RuntimeException( sprintf( 'Cannot import Akeneo product "%s", the option "%s" is not set on the parent product "%s".', diff --git a/src/ValueHandler/TranslatablePropertyValueHandler.php b/src/ValueHandler/TranslatablePropertyValueHandler.php index 1baf1774..1a900350 100644 --- a/src/ValueHandler/TranslatablePropertyValueHandler.php +++ b/src/ValueHandler/TranslatablePropertyValueHandler.php @@ -80,7 +80,7 @@ public function handle($subject, string $attribute, array $value): void continue; } - if (!in_array($localeCode, $this->localeProvider->getDefinedLocalesCodes())) { + if (!in_array($localeCode, $this->localeProvider->getDefinedLocalesCodes(), true)) { continue; } diff --git a/tests/Application/Kernel.php b/tests/Application/Kernel.php index d3bf1a5e..fd2a4aa3 100644 --- a/tests/Application/Kernel.php +++ b/tests/Application/Kernel.php @@ -7,24 +7,12 @@ use PSS\SymfonyMockerContainer\DependencyInjection\MockerContainer; use Sylius\Bundle\CoreBundle\Application\Kernel as SyliusKernel; use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; -use Symfony\Component\Config\Loader\DelegatingLoader; use Symfony\Component\Config\Loader\LoaderInterface; -use Symfony\Component\Config\Loader\LoaderResolver; use Symfony\Component\Config\Resource\FileResource; use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\DependencyInjection\Loader\ClosureLoader; -use Symfony\Component\DependencyInjection\Loader\DirectoryLoader; -use Symfony\Component\DependencyInjection\Loader\GlobFileLoader; -use Symfony\Component\DependencyInjection\Loader\IniFileLoader; -use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; -use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; -use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; use Symfony\Component\HttpKernel\Bundle\BundleInterface; -use Symfony\Component\HttpKernel\Config\FileLocator; use Symfony\Component\HttpKernel\Kernel as BaseKernel; use Symfony\Component\Routing\RouteCollectionBuilder; -use Webmozart\Assert\Assert; final class Kernel extends BaseKernel { @@ -45,14 +33,22 @@ public function getLogDir(): string public function registerBundles(): iterable { foreach ($this->getConfigurationDirectories() as $confDir) { - yield from $this->registerBundlesFromFile($confDir . '/bundles.php'); + $bundlesFile = $confDir . '/bundles.php'; + if (false === is_file($bundlesFile)) { + continue; + } + yield from $this->registerBundlesFromFile($bundlesFile); } } protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void { foreach ($this->getConfigurationDirectories() as $confDir) { - $container->addResource(new FileResource($confDir . '/bundles.php')); + $bundlesFile = $confDir . '/bundles.php'; + if (false === is_file($bundlesFile)) { + continue; + } + $container->addResource(new FileResource($bundlesFile)); } $container->setParameter('container.dumper.inline_class_loader', true); @@ -117,6 +113,13 @@ private function registerBundlesFromFile(string $bundlesFile): iterable private function getConfigurationDirectories(): iterable { yield $this->getProjectDir() . '/config'; - yield $this->getProjectDir() . '/config/sylius/' . SyliusKernel::MAJOR_VERSION . '.' . SyliusKernel::MINOR_VERSION; + $syliusConfigDir = $this->getProjectDir() . '/config/sylius/' . SyliusKernel::MAJOR_VERSION . '.' . SyliusKernel::MINOR_VERSION; + if (is_dir($syliusConfigDir)) { + yield $syliusConfigDir; + } + $symfonyConfigDir = $this->getProjectDir() . '/config/symfony/' . BaseKernel::MAJOR_VERSION . '.' . BaseKernel::MINOR_VERSION; + if (is_dir($symfonyConfigDir)) { + yield $symfonyConfigDir; + } } } diff --git a/tests/Application/config/bundles.php b/tests/Application/config/bundles.php index 6541535e..8a0949eb 100644 --- a/tests/Application/config/bundles.php +++ b/tests/Application/config/bundles.php @@ -45,8 +45,6 @@ Sylius\Bundle\ThemeBundle\SyliusThemeBundle::class => ['all' => true], Sylius\Bundle\AdminBundle\SyliusAdminBundle::class => ['all' => true], Sylius\Bundle\ShopBundle\SyliusShopBundle::class => ['all' => true], - FOS\OAuthServerBundle\FOSOAuthServerBundle::class => ['all' => true], - Sylius\Bundle\AdminApiBundle\SyliusAdminApiBundle::class => ['all' => true], Webgriffe\SyliusAkeneoPlugin\WebgriffeSyliusAkeneoPlugin::class => ['all' => true], Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true, 'test' => true, 'test_cached' => true], Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true, 'test_cached' => true], @@ -58,5 +56,4 @@ Lexik\Bundle\JWTAuthenticationBundle\LexikJWTAuthenticationBundle::class => ['all' => true], Sylius\Bundle\ApiBundle\SyliusApiBundle::class => ['all' => true], SyliusLabs\DoctrineMigrationsExtraBundle\SyliusLabsDoctrineMigrationsExtraBundle::class => ['all' => true], - Symplify\ConsoleColorDiff\ConsoleColorDiffBundle::class => ['dev' => true, 'test' => true], ]; diff --git a/tests/Application/config/packages/_sylius.yaml b/tests/Application/config/packages/_sylius.yaml index 79f5ce6c..7532b01a 100644 --- a/tests/Application/config/packages/_sylius.yaml +++ b/tests/Application/config/packages/_sylius.yaml @@ -2,7 +2,6 @@ imports: - { resource: "@SyliusCoreBundle/Resources/config/app/config.yml" } - { resource: "@SyliusAdminBundle/Resources/config/app/config.yml" } - - { resource: "@SyliusAdminApiBundle/Resources/config/app/config.yml" } - { resource: "@SyliusShopBundle/Resources/config/app/config.yml" } diff --git a/tests/Application/config/packages/twig_extensions.yaml b/tests/Application/config/packages/twig_extensions.yaml deleted file mode 100644 index 0881cc95..00000000 --- a/tests/Application/config/packages/twig_extensions.yaml +++ /dev/null @@ -1,11 +0,0 @@ -services: - _defaults: - public: false - autowire: true - autoconfigure: true - - # Uncomment any lines below to activate that Twig extension - #Twig\Extensions\ArrayExtension: ~ - #Twig\Extensions\DateExtension: ~ - #Twig\Extensions\IntlExtension: ~ - #Twig\Extensions\TextExtension: ~ diff --git a/tests/Application/config/sylius/1.10/bundles.php b/tests/Application/config/sylius/1.10/bundles.php new file mode 100644 index 00000000..bd33f4ae --- /dev/null +++ b/tests/Application/config/sylius/1.10/bundles.php @@ -0,0 +1,6 @@ + ['all' => true], + SyliusLabs\Polyfill\Symfony\Security\Bundle\SyliusLabsPolyfillSymfonySecurityBundle::class => ['all' => true], +]; diff --git a/tests/Application/config/sylius/1.10/packages/dev/jms_serializer.yaml b/tests/Application/config/sylius/1.10/packages/dev/jms_serializer.yaml new file mode 100644 index 00000000..2f32a9b1 --- /dev/null +++ b/tests/Application/config/sylius/1.10/packages/dev/jms_serializer.yaml @@ -0,0 +1,12 @@ +jms_serializer: + visitors: + json_serialization: + options: + - JSON_PRETTY_PRINT + - JSON_UNESCAPED_SLASHES + - JSON_PRESERVE_ZERO_FRACTION + json_deserialization: + options: + - JSON_PRETTY_PRINT + - JSON_UNESCAPED_SLASHES + - JSON_PRESERVE_ZERO_FRACTION diff --git a/tests/Application/config/sylius/1.10/packages/jms_serializer.yaml b/tests/Application/config/sylius/1.10/packages/jms_serializer.yaml new file mode 100644 index 00000000..ed7bc613 --- /dev/null +++ b/tests/Application/config/sylius/1.10/packages/jms_serializer.yaml @@ -0,0 +1,4 @@ +jms_serializer: + visitors: + xml_serialization: + format_output: '%kernel.debug%' diff --git a/tests/Application/config/sylius/1.10/packages/prod/jms_serializer.yaml b/tests/Application/config/sylius/1.10/packages/prod/jms_serializer.yaml new file mode 100644 index 00000000..c2881820 --- /dev/null +++ b/tests/Application/config/sylius/1.10/packages/prod/jms_serializer.yaml @@ -0,0 +1,10 @@ +jms_serializer: + visitors: + json_serialization: + options: + - JSON_UNESCAPED_SLASHES + - JSON_PRESERVE_ZERO_FRACTION + json_deserialization: + options: + - JSON_UNESCAPED_SLASHES + - JSON_PRESERVE_ZERO_FRACTION diff --git a/tests/Application/config/sylius/1.10/packages/security.yaml b/tests/Application/config/sylius/1.10/packages/security.yaml new file mode 100644 index 00000000..10628102 --- /dev/null +++ b/tests/Application/config/sylius/1.10/packages/security.yaml @@ -0,0 +1,148 @@ +parameters: + sylius.security.admin_regex: "^/%sylius_admin.path_name%" + sylius.security.api_regex: "^/api" + sylius.security.shop_regex: "^/(?!%sylius_admin.path_name%|new-api|api/.*|api$|media/.*)[^/]++" + sylius.security.new_api_route: "/new-api" + sylius.security.new_api_regex: "^%sylius.security.new_api_route%" + sylius.security.new_api_admin_route: "%sylius.security.new_api_route%/admin" + sylius.security.new_api_admin_regex: "^%sylius.security.new_api_admin_route%" + sylius.security.new_api_shop_route: "%sylius.security.new_api_route%/shop" + sylius.security.new_api_shop_regex: "^%sylius.security.new_api_shop_route%" + +security: + always_authenticate_before_granting: true + providers: + sylius_admin_user_provider: + id: sylius.admin_user_provider.email_or_name_based + sylius_api_admin_user_provider: + id: sylius.admin_user_provider.email_or_name_based + sylius_shop_user_provider: + id: sylius.shop_user_provider.email_or_name_based + sylius_api_shop_user_provider: + id: sylius.shop_user_provider.email_or_name_based + sylius_api_chain_provider: + chain: + providers: [sylius_api_shop_user_provider, sylius_api_admin_user_provider] + + encoders: + Sylius\Component\User\Model\UserInterface: argon2i + firewalls: + admin: + switch_user: true + context: admin + pattern: "%sylius.security.admin_regex%" + provider: sylius_admin_user_provider + form_login: + provider: sylius_admin_user_provider + login_path: sylius_admin_login + check_path: sylius_admin_login_check + failure_path: sylius_admin_login + default_target_path: sylius_admin_dashboard + use_forward: false + use_referer: true + csrf_token_generator: security.csrf.token_manager + csrf_parameter: _csrf_admin_security_token + csrf_token_id: admin_authenticate + remember_me: + secret: "%env(APP_SECRET)%" + path: "/%sylius_admin.path_name%" + name: APP_ADMIN_REMEMBER_ME + lifetime: 31536000 + remember_me_parameter: _remember_me + logout: + path: sylius_admin_logout + target: sylius_admin_login + anonymous: true + + new_api_admin_user: + pattern: "%sylius.security.new_api_route%/admin-user-authentication-token" + provider: sylius_admin_user_provider + stateless: true + anonymous: true + json_login: + check_path: "%sylius.security.new_api_route%/admin-user-authentication-token" + username_path: email + password_path: password + success_handler: lexik_jwt_authentication.handler.authentication_success + failure_handler: lexik_jwt_authentication.handler.authentication_failure + guard: + authenticators: + - lexik_jwt_authentication.jwt_token_authenticator + + new_api_shop_user: + pattern: "%sylius.security.new_api_route%/shop-user-authentication-token" + provider: sylius_shop_user_provider + stateless: true + anonymous: true + json_login: + check_path: "%sylius.security.new_api_route%/shop-user-authentication-token" + username_path: email + password_path: password + success_handler: lexik_jwt_authentication.handler.authentication_success + failure_handler: lexik_jwt_authentication.handler.authentication_failure + guard: + authenticators: + - lexik_jwt_authentication.jwt_token_authenticator + + new_api: + pattern: "%sylius.security.new_api_regex%/*" + provider: sylius_api_chain_provider + stateless: true + anonymous: lazy + guard: + authenticators: + - lexik_jwt_authentication.jwt_token_authenticator + + shop: + switch_user: { role: ROLE_ALLOWED_TO_SWITCH } + context: shop + pattern: "%sylius.security.shop_regex%" + provider: sylius_shop_user_provider + form_login: + success_handler: sylius.authentication.success_handler + failure_handler: sylius.authentication.failure_handler + provider: sylius_shop_user_provider + login_path: sylius_shop_login + check_path: sylius_shop_login_check + failure_path: sylius_shop_login + default_target_path: sylius_shop_homepage + use_forward: false + use_referer: true + csrf_token_generator: security.csrf.token_manager + csrf_parameter: _csrf_shop_security_token + csrf_token_id: shop_authenticate + remember_me: + secret: "%env(APP_SECRET)%" + name: APP_SHOP_REMEMBER_ME + lifetime: 31536000 + remember_me_parameter: _remember_me + logout: + path: sylius_shop_logout + target: sylius_shop_login + invalidate_session: false + success_handler: sylius.handler.shop_user_logout + anonymous: true + + dev: + pattern: ^/(_(profiler|wdt)|css|images|js)/ + security: false + + access_control: + - { path: "%sylius.security.admin_regex%/_partial", role: IS_AUTHENTICATED_ANONYMOUSLY, ips: [127.0.0.1, ::1] } + - { path: "%sylius.security.admin_regex%/_partial", role: ROLE_NO_ACCESS } + - { path: "%sylius.security.shop_regex%/_partial", role: IS_AUTHENTICATED_ANONYMOUSLY, ips: [127.0.0.1, ::1] } + - { path: "%sylius.security.shop_regex%/_partial", role: ROLE_NO_ACCESS } + + - { path: "%sylius.security.admin_regex%/login", role: IS_AUTHENTICATED_ANONYMOUSLY } + - { path: "%sylius.security.api_regex%/login", role: IS_AUTHENTICATED_ANONYMOUSLY } + - { path: "%sylius.security.shop_regex%/login", role: IS_AUTHENTICATED_ANONYMOUSLY } + + - { path: "%sylius.security.shop_regex%/register", role: IS_AUTHENTICATED_ANONYMOUSLY } + - { path: "%sylius.security.shop_regex%/verify", role: IS_AUTHENTICATED_ANONYMOUSLY } + + - { path: "%sylius.security.admin_regex%", role: ROLE_ADMINISTRATION_ACCESS } + - { path: "%sylius.security.api_regex%/.*", role: ROLE_API_ACCESS } + - { path: "%sylius.security.shop_regex%/account", role: ROLE_USER } + + - { path: "%sylius.security.new_api_admin_regex%/.*", role: ROLE_API_ACCESS } + - { path: "%sylius.security.new_api_shop_regex%/.*", role: IS_AUTHENTICATED_ANONYMOUSLY } diff --git a/tests/Application/config/sylius/1.8/bundles.php b/tests/Application/config/sylius/1.8/bundles.php index 74ee2bc0..c3c8ea46 100644 --- a/tests/Application/config/sylius/1.8/bundles.php +++ b/tests/Application/config/sylius/1.8/bundles.php @@ -3,4 +3,6 @@ return [ Doctrine\Bundle\DoctrineCacheBundle\DoctrineCacheBundle::class => ['all' => true], WhiteOctober\PagerfantaBundle\WhiteOctoberPagerfantaBundle::class => ['all' => true], + FOS\OAuthServerBundle\FOSOAuthServerBundle::class => ['all' => true], + Sylius\Bundle\AdminApiBundle\SyliusAdminApiBundle::class => ['all' => true], ]; diff --git a/tests/Application/config/sylius/1.8/packages/_sylius.yaml b/tests/Application/config/sylius/1.8/packages/_sylius.yaml new file mode 100644 index 00000000..1674a972 --- /dev/null +++ b/tests/Application/config/sylius/1.8/packages/_sylius.yaml @@ -0,0 +1,2 @@ +imports: + - { resource: "@SyliusAdminApiBundle/Resources/config/app/config.yml" } diff --git a/tests/Application/config/packages/security.yaml b/tests/Application/config/sylius/1.8/packages/security.yaml similarity index 90% rename from tests/Application/config/packages/security.yaml rename to tests/Application/config/sylius/1.8/packages/security.yaml index 12e842b8..8161bdab 100644 --- a/tests/Application/config/packages/security.yaml +++ b/tests/Application/config/sylius/1.8/packages/security.yaml @@ -1,9 +1,13 @@ parameters: - sylius.security.admin_regex: "^/admin" + sylius.security.admin_regex: "^/%sylius_admin.path_name%" sylius.security.api_regex: "^/api" - sylius.security.shop_regex: "^/(?!admin|new-api|api/.*|api$|media/.*)[^/]++" + sylius.security.shop_regex: "^/(?!%sylius_admin.path_name%|new-api|api/.*|api$|media/.*)[^/]++" sylius.security.new_api_route: "/new-api" sylius.security.new_api_regex: "^%sylius.security.new_api_route%" + sylius.security.new_api_admin_route: "%sylius.security.new_api_route%/admin" + sylius.security.new_api_admin_regex: "^%sylius.security.new_api_admin_route%" + sylius.security.new_api_shop_route: "%sylius.security.new_api_route%/shop" + sylius.security.new_api_shop_regex: "^%sylius.security.new_api_shop_route%" security: always_authenticate_before_granting: true @@ -41,7 +45,7 @@ security: csrf_token_id: admin_authenticate remember_me: secret: "%env(APP_SECRET)%" - path: /admin + path: "/%sylius_admin.path_name%" name: APP_ADMIN_REMEMBER_ME lifetime: 31536000 remember_me_parameter: _remember_me @@ -150,3 +154,6 @@ security: - { path: "%sylius.security.admin_regex%", role: ROLE_ADMINISTRATION_ACCESS } - { path: "%sylius.security.api_regex%/.*", role: ROLE_API_ACCESS } - { path: "%sylius.security.shop_regex%/account", role: ROLE_USER } + + - { path: "%sylius.security.new_api_admin_regex%/.*", role: ROLE_API_ACCESS } + - { path: "%sylius.security.new_api_shop_regex%/.*", role: IS_AUTHENTICATED_ANONYMOUSLY } diff --git a/tests/Application/config/routes/sylius_admin_api.yaml b/tests/Application/config/sylius/1.8/routes/sylius_admin_api.yaml similarity index 100% rename from tests/Application/config/routes/sylius_admin_api.yaml rename to tests/Application/config/sylius/1.8/routes/sylius_admin_api.yaml diff --git a/tests/Application/config/sylius/1.9/bundles.php b/tests/Application/config/sylius/1.9/bundles.php index bd33f4ae..66f523db 100644 --- a/tests/Application/config/sylius/1.9/bundles.php +++ b/tests/Application/config/sylius/1.9/bundles.php @@ -3,4 +3,6 @@ return [ BabDev\PagerfantaBundle\BabDevPagerfantaBundle::class => ['all' => true], SyliusLabs\Polyfill\Symfony\Security\Bundle\SyliusLabsPolyfillSymfonySecurityBundle::class => ['all' => true], + FOS\OAuthServerBundle\FOSOAuthServerBundle::class => ['all' => true], + Sylius\Bundle\AdminApiBundle\SyliusAdminApiBundle::class => ['all' => true], ]; diff --git a/tests/Application/config/sylius/1.9/packages/_sylius.yaml b/tests/Application/config/sylius/1.9/packages/_sylius.yaml new file mode 100644 index 00000000..1674a972 --- /dev/null +++ b/tests/Application/config/sylius/1.9/packages/_sylius.yaml @@ -0,0 +1,2 @@ +imports: + - { resource: "@SyliusAdminApiBundle/Resources/config/app/config.yml" } diff --git a/tests/Application/config/sylius/1.9/packages/security.yaml b/tests/Application/config/sylius/1.9/packages/security.yaml new file mode 100644 index 00000000..8161bdab --- /dev/null +++ b/tests/Application/config/sylius/1.9/packages/security.yaml @@ -0,0 +1,159 @@ +parameters: + sylius.security.admin_regex: "^/%sylius_admin.path_name%" + sylius.security.api_regex: "^/api" + sylius.security.shop_regex: "^/(?!%sylius_admin.path_name%|new-api|api/.*|api$|media/.*)[^/]++" + sylius.security.new_api_route: "/new-api" + sylius.security.new_api_regex: "^%sylius.security.new_api_route%" + sylius.security.new_api_admin_route: "%sylius.security.new_api_route%/admin" + sylius.security.new_api_admin_regex: "^%sylius.security.new_api_admin_route%" + sylius.security.new_api_shop_route: "%sylius.security.new_api_route%/shop" + sylius.security.new_api_shop_regex: "^%sylius.security.new_api_shop_route%" + +security: + always_authenticate_before_granting: true + providers: + sylius_admin_user_provider: + id: sylius.admin_user_provider.email_or_name_based + sylius_api_admin_user_provider: + id: sylius.admin_user_provider.email_or_name_based + sylius_shop_user_provider: + id: sylius.shop_user_provider.email_or_name_based + sylius_api_shop_user_provider: + id: sylius.shop_user_provider.email_or_name_based + sylius_api_chain_provider: + chain: + providers: [sylius_api_shop_user_provider, sylius_api_admin_user_provider] + + encoders: + Sylius\Component\User\Model\UserInterface: argon2i + firewalls: + admin: + switch_user: true + context: admin + pattern: "%sylius.security.admin_regex%" + provider: sylius_admin_user_provider + form_login: + provider: sylius_admin_user_provider + login_path: sylius_admin_login + check_path: sylius_admin_login_check + failure_path: sylius_admin_login + default_target_path: sylius_admin_dashboard + use_forward: false + use_referer: true + csrf_token_generator: security.csrf.token_manager + csrf_parameter: _csrf_admin_security_token + csrf_token_id: admin_authenticate + remember_me: + secret: "%env(APP_SECRET)%" + path: "/%sylius_admin.path_name%" + name: APP_ADMIN_REMEMBER_ME + lifetime: 31536000 + remember_me_parameter: _remember_me + logout: + path: sylius_admin_logout + target: sylius_admin_login + anonymous: true + + oauth_token: + pattern: "%sylius.security.api_regex%/oauth/v2/token" + security: false + + new_api_admin_user: + pattern: "%sylius.security.new_api_route%/admin-user-authentication-token" + provider: sylius_admin_user_provider + stateless: true + anonymous: true + json_login: + check_path: "%sylius.security.new_api_route%/admin-user-authentication-token" + username_path: email + password_path: password + success_handler: lexik_jwt_authentication.handler.authentication_success + failure_handler: lexik_jwt_authentication.handler.authentication_failure + guard: + authenticators: + - lexik_jwt_authentication.jwt_token_authenticator + + new_api_shop_user: + pattern: "%sylius.security.new_api_route%/shop-user-authentication-token" + provider: sylius_shop_user_provider + stateless: true + anonymous: true + json_login: + check_path: "%sylius.security.new_api_route%/shop-user-authentication-token" + username_path: email + password_path: password + success_handler: lexik_jwt_authentication.handler.authentication_success + failure_handler: lexik_jwt_authentication.handler.authentication_failure + guard: + authenticators: + - lexik_jwt_authentication.jwt_token_authenticator + + new_api: + pattern: "%sylius.security.new_api_regex%/*" + provider: sylius_api_chain_provider + stateless: true + anonymous: lazy + guard: + authenticators: + - lexik_jwt_authentication.jwt_token_authenticator + + api: + pattern: "%sylius.security.api_regex%/.*" + provider: sylius_admin_user_provider + fos_oauth: true + stateless: true + anonymous: true + + shop: + switch_user: { role: ROLE_ALLOWED_TO_SWITCH } + context: shop + pattern: "%sylius.security.shop_regex%" + provider: sylius_shop_user_provider + form_login: + success_handler: sylius.authentication.success_handler + failure_handler: sylius.authentication.failure_handler + provider: sylius_shop_user_provider + login_path: sylius_shop_login + check_path: sylius_shop_login_check + failure_path: sylius_shop_login + default_target_path: sylius_shop_homepage + use_forward: false + use_referer: true + csrf_token_generator: security.csrf.token_manager + csrf_parameter: _csrf_shop_security_token + csrf_token_id: shop_authenticate + remember_me: + secret: "%env(APP_SECRET)%" + name: APP_SHOP_REMEMBER_ME + lifetime: 31536000 + remember_me_parameter: _remember_me + logout: + path: sylius_shop_logout + target: sylius_shop_login + invalidate_session: false + success_handler: sylius.handler.shop_user_logout + anonymous: true + + dev: + pattern: ^/(_(profiler|wdt)|css|images|js)/ + security: false + + access_control: + - { path: "%sylius.security.admin_regex%/_partial", role: IS_AUTHENTICATED_ANONYMOUSLY, ips: [127.0.0.1, ::1] } + - { path: "%sylius.security.admin_regex%/_partial", role: ROLE_NO_ACCESS } + - { path: "%sylius.security.shop_regex%/_partial", role: IS_AUTHENTICATED_ANONYMOUSLY, ips: [127.0.0.1, ::1] } + - { path: "%sylius.security.shop_regex%/_partial", role: ROLE_NO_ACCESS } + + - { path: "%sylius.security.admin_regex%/login", role: IS_AUTHENTICATED_ANONYMOUSLY } + - { path: "%sylius.security.api_regex%/login", role: IS_AUTHENTICATED_ANONYMOUSLY } + - { path: "%sylius.security.shop_regex%/login", role: IS_AUTHENTICATED_ANONYMOUSLY } + + - { path: "%sylius.security.shop_regex%/register", role: IS_AUTHENTICATED_ANONYMOUSLY } + - { path: "%sylius.security.shop_regex%/verify", role: IS_AUTHENTICATED_ANONYMOUSLY } + + - { path: "%sylius.security.admin_regex%", role: ROLE_ADMINISTRATION_ACCESS } + - { path: "%sylius.security.api_regex%/.*", role: ROLE_API_ACCESS } + - { path: "%sylius.security.shop_regex%/account", role: ROLE_USER } + + - { path: "%sylius.security.new_api_admin_regex%/.*", role: ROLE_API_ACCESS } + - { path: "%sylius.security.new_api_shop_regex%/.*", role: IS_AUTHENTICATED_ANONYMOUSLY } diff --git a/tests/Application/config/sylius/1.9/routes/sylius_admin_api.yaml b/tests/Application/config/sylius/1.9/routes/sylius_admin_api.yaml new file mode 100644 index 00000000..80aed457 --- /dev/null +++ b/tests/Application/config/sylius/1.9/routes/sylius_admin_api.yaml @@ -0,0 +1,3 @@ +sylius_admin_api: + resource: "@SyliusAdminApiBundle/Resources/config/routing.yml" + prefix: /api diff --git a/tests/Application/config/sylius/1.8/packages/framework.yaml b/tests/Application/config/symfony/4.4/packages/framework.yaml similarity index 100% rename from tests/Application/config/sylius/1.8/packages/framework.yaml rename to tests/Application/config/symfony/4.4/packages/framework.yaml From 0b1f3a3d322a8295b14f932f6dc18c3d916a8d13 Mon Sep 17 00:00:00 2001 From: Lorenzo Ruozzi Date: Tue, 19 Oct 2021 16:53:41 +0200 Subject: [PATCH 02/15] Add conflict with Doctrine DBAL 3 https://github.com/Sylius/Sylius/issues/13211 --- composer.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/composer.json b/composer.json index f28b007d..bf36bfaf 100644 --- a/composer.json +++ b/composer.json @@ -76,5 +76,8 @@ "post-create-project-cmd": [ "php bin/create_node_symlink.php" ] + }, + "conflict": { + "doctrine/dbal": "^3.0" } } From 1b5cd814ec0061b920992062c25f06b9187ed14b Mon Sep 17 00:00:00 2001 From: Lorenzo Ruozzi Date: Tue, 19 Oct 2021 17:08:00 +0200 Subject: [PATCH 03/15] Try to fix Psalm --- src/ApiClient.php | 2 +- src/Command/EnqueueCommand.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ApiClient.php b/src/ApiClient.php index a2de45ad..4bad2d24 100644 --- a/src/ApiClient.php +++ b/src/ApiClient.php @@ -90,7 +90,7 @@ public function authenticatedRequest(string $uri, string $method, array $headers $headers, [ 'Content-Type' => 'application/json', - 'Authorization' => sprintf('Bearer %s', $this->accessToken), + 'Authorization' => sprintf('Bearer %s', (string) $this->accessToken), ] ); $request = new Request($method, $uri, $headers); diff --git a/src/Command/EnqueueCommand.php b/src/Command/EnqueueCommand.php index b46bce02..542fbb89 100644 --- a/src/Command/EnqueueCommand.php +++ b/src/Command/EnqueueCommand.php @@ -137,9 +137,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int if ($this->isEntityAlreadyQueuedToImport($importer->getAkeneoEntity(), $identifier)) { continue; } + /** @var QueueItemInterface|object $queueItem */ $queueItem = $this->queueItemFactory->createNew(); Assert::isInstanceOf($queueItem, QueueItemInterface::class); - /** @var QueueItemInterface $queueItem */ $queueItem->setAkeneoEntity($importer->getAkeneoEntity()); $queueItem->setAkeneoIdentifier($identifier); $queueItem->setCreatedAt(new \DateTime()); From 8a3482a57c21cd6aaa98e289c2405587a0aa8263 Mon Sep 17 00:00:00 2001 From: Lorenzo Ruozzi Date: Tue, 19 Oct 2021 17:31:51 +0200 Subject: [PATCH 04/15] Try to fix Psalm --- src/Command/EnqueueCommand.php | 4 ++-- src/Command/ReconcileCommand.php | 2 ++ src/Controller/ProductEnqueueController.php | 2 -- src/Converter/UnitMeasurementValueConverter.php | 2 -- .../WebgriffeSyliusAkeneoExtension.php | 4 ++-- src/Product/Importer.php | 2 -- src/ProductAssociations/Importer.php | 2 -- src/ValueHandler/ImageValueHandler.php | 2 -- src/ValueHandler/ImmutableSlugValueHandler.php | 13 +++++-------- src/ValueHandler/ProductOptionValueHandler.php | 1 - .../TranslatablePropertyValueHandler.php | 2 -- 11 files changed, 11 insertions(+), 25 deletions(-) diff --git a/src/Command/EnqueueCommand.php b/src/Command/EnqueueCommand.php index 542fbb89..e2afd48a 100644 --- a/src/Command/EnqueueCommand.php +++ b/src/Command/EnqueueCommand.php @@ -137,7 +137,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int if ($this->isEntityAlreadyQueuedToImport($importer->getAkeneoEntity(), $identifier)) { continue; } - /** @var QueueItemInterface|object $queueItem */ $queueItem = $this->queueItemFactory->createNew(); Assert::isInstanceOf($queueItem, QueueItemInterface::class); $queueItem->setAkeneoEntity($importer->getAkeneoEntity()); @@ -184,7 +183,6 @@ private function getSinceDateByFile(string $filepath): \DateTime try { $content = file_get_contents($filepath); Assert::string($content); - /** @var string $content */ $sinceDate = new \DateTime(trim($content)); } catch (\Throwable $t) { throw new \RuntimeException(sprintf('The file "%s" must contain a valid datetime', $filepath), 0, $t); @@ -234,11 +232,13 @@ static function (ImporterInterface $importer): string { $allImporters = array_combine($importersCodes, $allImporters); + /** @var ImporterInterface[] $importers */ $importers = []; foreach ($importersToUse as $importerToUse) { if (!array_key_exists($importerToUse, $allImporters)) { throw new \InvalidArgumentException(sprintf('Importer "%s" does not exists.', $importerToUse)); } + Assert::isInstanceOf($allImporters[$importerToUse], ImporterInterface::class); $importers[] = $allImporters[$importerToUse]; } diff --git a/src/Command/ReconcileCommand.php b/src/Command/ReconcileCommand.php index cba5e4c0..ff6a117e 100644 --- a/src/Command/ReconcileCommand.php +++ b/src/Command/ReconcileCommand.php @@ -102,11 +102,13 @@ static function (ReconcilerInterface $reconciler): string { $allReconcilers = array_combine($reconcilersCodes, $allReconcilers); + /** @var ReconcilerInterface[] $reconcilers */ $reconcilers = []; foreach ($reconcilersToUse as $reconcilerToUse) { if (!array_key_exists($reconcilerToUse, $allReconcilers)) { throw new \InvalidArgumentException(sprintf('Reconciler "%s" does not exists.', $reconcilerToUse)); } + Assert::isInstanceOf($allReconcilers[$reconcilerToUse], ReconcilerInterface::class); $reconcilers[] = $allReconcilers[$reconcilerToUse]; } diff --git a/src/Controller/ProductEnqueueController.php b/src/Controller/ProductEnqueueController.php index c89db7eb..89f32089 100644 --- a/src/Controller/ProductEnqueueController.php +++ b/src/Controller/ProductEnqueueController.php @@ -49,11 +49,9 @@ public function enqueueAction(int $productId): Response $alreadyEnqueued = []; $enqueued = []; foreach ($product->getVariants() as $productVariant) { - /** @var ?string $productVariantCode */ $productVariantCode = $productVariant->getCode(); Assert::notNull($productVariantCode); - /** @var array $productEnqueued */ $productEnqueued = $this->queueItemRepository->findBy([ 'akeneoIdentifier' => $productVariantCode, 'akeneoEntity' => 'Product', diff --git a/src/Converter/UnitMeasurementValueConverter.php b/src/Converter/UnitMeasurementValueConverter.php index b4091732..892da0a2 100644 --- a/src/Converter/UnitMeasurementValueConverter.php +++ b/src/Converter/UnitMeasurementValueConverter.php @@ -57,7 +57,6 @@ public function convert(string $amount, string $sourceUnitMeasurementCode, ?stri private function getUnitMeasurementFamilyByUnitMeasurementCode(string $unitMeasurementCode): array { $unitMeasurementFamilies = $this->apiClient->getMeasurementFamilies(); - /** @var array{code: string, labels: array{localeCode: string}, standard_unit_code: string, units: array{unitCode: array{code: string, labels: array, convert_from_standard: array{operator: string, value: string}, symbol: string}}} $unitMeasurementFamily */ foreach ($unitMeasurementFamilies as $unitMeasurementFamily) { if (array_key_exists($unitMeasurementCode, $unitMeasurementFamily['units'])) { return $unitMeasurementFamily; @@ -144,7 +143,6 @@ private function doReverseOperations($operationsToDefaultUnitMeasurement, float private function getOperationsForDefaultFromUnitMeasurement(array $units, string $unitMeasurementCode): array { $operationsToDefaultUnitMeasurement = []; - /** @var array{code: string, labels: array, convert_from_standard: array{operator: string, value: string}, symbol: string} $unitMeasurement */ foreach ($units as $unitMeasurement) { if ($unitMeasurement['code'] === $unitMeasurementCode) { $operationsToDefaultUnitMeasurement = $unitMeasurement['convert_from_standard']; diff --git a/src/DependencyInjection/WebgriffeSyliusAkeneoExtension.php b/src/DependencyInjection/WebgriffeSyliusAkeneoExtension.php index 6a0b4c68..51ab7d30 100644 --- a/src/DependencyInjection/WebgriffeSyliusAkeneoExtension.php +++ b/src/DependencyInjection/WebgriffeSyliusAkeneoExtension.php @@ -285,7 +285,7 @@ private function addTaggedImportersToRegistry(ContainerBuilder $container): void $importerRegistryDefinition = $container->findDefinition('webgriffe_sylius_akeneo.importer_registry'); $taggedImporters = $container->findTaggedServiceIds(self::IMPORTER_TAG); - foreach ($taggedImporters as $id => $tags) { + foreach ($taggedImporters as $id => $_tags) { $importerRegistryDefinition->addMethodCall('add', [new Reference($id)]); } } @@ -300,7 +300,7 @@ private function addTaggedReconcilersToRegistry(ContainerBuilder $container): vo /** @var array $taggedReconcilers */ $taggedReconcilers = $container->findTaggedServiceIds(self::RECONCILER_TAG); - foreach ($taggedReconcilers as $id => $tags) { + foreach ($taggedReconcilers as $id => $_tags) { $importerRegistryDefinition->addMethodCall('add', [new Reference($id)]); } } diff --git a/src/Product/Importer.php b/src/Product/Importer.php index 13f04e0a..ea7e22e8 100644 --- a/src/Product/Importer.php +++ b/src/Product/Importer.php @@ -207,7 +207,6 @@ private function getOrCreateProductFromVariantResponse(array $productVariantResp $product = $this->productFactory->createNew(); } Assert::isInstanceOf($product, ProductInterface::class); - /** @var ProductInterface $product */ $product->setCode($identifier); return $product; @@ -280,7 +279,6 @@ private function createNewProductFromAkeneoProduct(array $productVariantResponse $parentCode = $productVariantResponse['parent']; $product = $this->productFactory->createNew(); Assert::isInstanceOf($product, ProductInterface::class); - /** @var ProductInterface $product */ $product->setCode($parentCode); foreach ($this->productOptionsResolver->resolve($productVariantResponse) as $productOption) { $product->addOption($productOption); diff --git a/src/ProductAssociations/Importer.php b/src/ProductAssociations/Importer.php index e4875b25..57977538 100644 --- a/src/ProductAssociations/Importer.php +++ b/src/ProductAssociations/Importer.php @@ -80,7 +80,6 @@ public function import(string $identifier): void if ($product === null) { throw new \RuntimeException(sprintf('Cannot find product "%s" on Sylius.', $productCode)); } - /** @var ProductInterface $product */ $associations = $productVariantResponse['associations']; foreach ($associations as $associationTypeCode => $associationInfo) { /** @var ProductAssociationTypeInterface|null $productAssociationType */ @@ -115,7 +114,6 @@ public function import(string $identifier): void ['owner' => $product, 'type' => $productAssociationType] ); if ($productAssociation === null) { - /** @var ProductAssociationInterface|object $productAssociation */ $productAssociation = $this->productAssociationFactory->createNew(); Assert::isInstanceOf($productAssociation, ProductAssociationInterface::class); $productAssociation->setOwner($product); diff --git a/src/ValueHandler/ImageValueHandler.php b/src/ValueHandler/ImageValueHandler.php index e404b2f1..084a4ddc 100644 --- a/src/ValueHandler/ImageValueHandler.php +++ b/src/ValueHandler/ImageValueHandler.php @@ -72,7 +72,6 @@ public function handle($subject, string $attribute, array $value): void $product = $subject->getProduct(); Assert::isInstanceOf($product, ProductInterface::class); - /** @var ProductInterface $product */ if ($value[0]['data'] === null) { $this->removeAlreadyExistentVariantImages($subject, $product); @@ -87,7 +86,6 @@ public function handle($subject, string $attribute, array $value): void if ($productImage === null) { $productImage = $this->productImageFactory->createNew(); Assert::isInstanceOf($productImage, ProductImageInterface::class); - /** @var ProductImageInterface $productImage */ $productImage->setType($this->syliusImageType); $subject->addImage($productImage); $product->addImage($productImage); diff --git a/src/ValueHandler/ImmutableSlugValueHandler.php b/src/ValueHandler/ImmutableSlugValueHandler.php index 306215fd..fac22b7a 100644 --- a/src/ValueHandler/ImmutableSlugValueHandler.php +++ b/src/ValueHandler/ImmutableSlugValueHandler.php @@ -73,11 +73,9 @@ public function handle($subject, string $attribute, array $value): void $product = $subject->getProduct(); Assert::isInstanceOf($product, ProductInterface::class); foreach ($value as $item) { - /** @var ProductInterface $product */ $localeCode = $item['locale']; $valueToSlugify = $item['data']; Assert::string($valueToSlugify); - /** @var string $valueToSlugify */ if (!$localeCode) { $this->setSlugOnAllTranslations($product, $valueToSlugify); @@ -106,7 +104,6 @@ private function getOrCreateNewProductTranslation( if ($translation->getLocale() !== $localeCode) { $translation = $this->productTranslationFactory->createNew(); Assert::isInstanceOf($translation, ProductTranslationInterface::class); - /** @var ProductTranslationInterface $translation */ $translation->setLocale($localeCode); $product->addTranslation($translation); } @@ -131,14 +128,14 @@ private function getDeduplicatedSlug( string $slug, string $localeCode, ProductInterface $product, - int $increment = 0 + int $_increment = 0 ): string { - if ($increment > self::MAX_DEDUPLICATION_INCREMENT) { + if ($_increment > self::MAX_DEDUPLICATION_INCREMENT) { throw new \RuntimeException('Maximum slug deduplication increment reached.'); } $deduplicatedSlug = $slug; - if ($increment > 0) { - $deduplicatedSlug .= '-' . $increment; + if ($_increment > 0) { + $deduplicatedSlug .= '-' . $_increment; } /** @var ProductTranslationInterface|null $anotherProductTranslation */ @@ -148,7 +145,7 @@ private function getDeduplicatedSlug( if ($anotherProductTranslation !== null && $anotherProductTranslation->getTranslatable() instanceof ProductInterface && $anotherProductTranslation->getTranslatable()->getId() !== $product->getId()) { - return $this->getDeduplicatedSlug($slug, $localeCode, $product, ++$increment); + return $this->getDeduplicatedSlug($slug, $localeCode, $product, ++$_increment); } return $deduplicatedSlug; diff --git a/src/ValueHandler/ProductOptionValueHandler.php b/src/ValueHandler/ProductOptionValueHandler.php index 2ee8b877..72cb9073 100644 --- a/src/ValueHandler/ProductOptionValueHandler.php +++ b/src/ValueHandler/ProductOptionValueHandler.php @@ -86,7 +86,6 @@ public function handle($productVariant, string $optionCode, array $akeneoValue): } $product = $productVariant->getProduct(); Assert::isInstanceOf($product, ProductInterface::class); - /** @var ProductInterface $product */ if (count($akeneoValue) > 1) { throw new \RuntimeException( sprintf( diff --git a/src/ValueHandler/TranslatablePropertyValueHandler.php b/src/ValueHandler/TranslatablePropertyValueHandler.php index 1a900350..453ec4c7 100644 --- a/src/ValueHandler/TranslatablePropertyValueHandler.php +++ b/src/ValueHandler/TranslatablePropertyValueHandler.php @@ -151,7 +151,6 @@ private function getOrCreateNewProductTranslation( if ($translation->getLocale() !== $localeCode) { $translation = $this->productTranslationFactory->createNew(); Assert::isInstanceOf($translation, ProductTranslationInterface::class); - /** @var ProductTranslationInterface $translation */ $translation->setLocale($localeCode); $subject->addTranslation($translation); } @@ -167,7 +166,6 @@ private function getOrCreateNewProductVariantTranslation( if ($translation->getLocale() !== $localeCode) { $translation = $this->productVariantTranslationFactory->createNew(); Assert::isInstanceOf($translation, ProductVariantTranslationInterface::class); - /** @var ProductVariantTranslationInterface $translation */ $translation->setLocale($localeCode); $subject->addTranslation($translation); } From b016c80894315c3159b7cf8ed27b90f7a2152033 Mon Sep 17 00:00:00 2001 From: Lorenzo Ruozzi Date: Tue, 19 Oct 2021 17:38:25 +0200 Subject: [PATCH 05/15] Try to fix Psalm --- src/ApiClient.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ApiClient.php b/src/ApiClient.php index 4bad2d24..5012e52a 100644 --- a/src/ApiClient.php +++ b/src/ApiClient.php @@ -255,7 +255,7 @@ private function getResourceOrNull(string $endpoint): ?array { try { $response = $this->authenticatedRequest($endpoint, 'GET', []); - } catch (\HttpException $exception) { + } catch (\Throwable $exception) { if ($exception->getCode() !== 404) { throw $exception; } From 2933426bcea4fa15d2c3fd7df641087b3c91abd9 Mon Sep 17 00:00:00 2001 From: Lorenzo Ruozzi Date: Tue, 19 Oct 2021 17:58:04 +0200 Subject: [PATCH 06/15] Try to fix phpunit --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index bf36bfaf..6dd6bab4 100644 --- a/composer.json +++ b/composer.json @@ -30,6 +30,7 @@ "friends-of-behat/symfony-extension": "^2.1", "friends-of-behat/variadic-extension": "^1.3", "friendsofsymfony/oauth-server-bundle": "^1.6 || >2.0.0-alpha.0 ^2.0@dev", + "matthiasnoback/symfony-dependency-injection-test": "^4.3", "phpspec/phpspec": "^7.0", "phpstan/extension-installer": "^1.0", "phpstan/phpstan": "0.12.85", From 6662e3b56e32943c611553f87f0f7144c1804427 Mon Sep 17 00:00:00 2001 From: Lorenzo Ruozzi Date: Tue, 19 Oct 2021 18:02:31 +0200 Subject: [PATCH 07/15] Try to fix phpunit --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 6dd6bab4..a8d7868d 100644 --- a/composer.json +++ b/composer.json @@ -79,6 +79,7 @@ ] }, "conflict": { - "doctrine/dbal": "^3.0" + "doctrine/dbal": "^3.0", + "doctrine/orm": "^2.10.0" } } From 151c1c9c785302880bad7a57ab0cd63b82f6043c Mon Sep 17 00:00:00 2001 From: Lorenzo Ruozzi Date: Wed, 20 Oct 2021 09:33:20 +0200 Subject: [PATCH 08/15] Try to fix phpunit --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index a8d7868d..f2c5f6c0 100644 --- a/composer.json +++ b/composer.json @@ -31,6 +31,7 @@ "friends-of-behat/variadic-extension": "^1.3", "friendsofsymfony/oauth-server-bundle": "^1.6 || >2.0.0-alpha.0 ^2.0@dev", "matthiasnoback/symfony-dependency-injection-test": "^4.3", + "mikey179/vfsstream": "^1.6", "phpspec/phpspec": "^7.0", "phpstan/extension-installer": "^1.0", "phpstan/phpstan": "0.12.85", From 435145c7ffd58bdb30986a0d5d911774f00aac07 Mon Sep 17 00:00:00 2001 From: Lorenzo Ruozzi Date: Wed, 20 Oct 2021 09:51:43 +0200 Subject: [PATCH 09/15] Try to fix behat --- src/Command/EnqueueCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Command/EnqueueCommand.php b/src/Command/EnqueueCommand.php index e2afd48a..d58a1df5 100644 --- a/src/Command/EnqueueCommand.php +++ b/src/Command/EnqueueCommand.php @@ -153,7 +153,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int } } - if ($sinceFilePath !== null) { + if (!empty($sinceFilePath)) { $this->writeSinceDateFile($sinceFilePath, $runDate); } From 162f124f79e2e839863b8b01d1b6ad27fc4ba408 Mon Sep 17 00:00:00 2001 From: Lorenzo Ruozzi Date: Wed, 20 Oct 2021 09:55:43 +0200 Subject: [PATCH 10/15] Try to fix behat --- src/Command/EnqueueCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Command/EnqueueCommand.php b/src/Command/EnqueueCommand.php index d58a1df5..53abde8d 100644 --- a/src/Command/EnqueueCommand.php +++ b/src/Command/EnqueueCommand.php @@ -153,7 +153,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int } } - if (!empty($sinceFilePath)) { + if ($sinceFilePath !== null && $sinceFilePath !== '') { $this->writeSinceDateFile($sinceFilePath, $runDate); } From 888db3025a05bf3bf21eb08dcd3039ae173f300c Mon Sep 17 00:00:00 2001 From: Lorenzo Ruozzi Date: Wed, 20 Oct 2021 09:57:04 +0200 Subject: [PATCH 11/15] Try to fix phpunit --- src/Command/EnqueueCommand.php | 1 + src/Command/ReconcileCommand.php | 1 + 2 files changed, 2 insertions(+) diff --git a/src/Command/EnqueueCommand.php b/src/Command/EnqueueCommand.php index 53abde8d..d3ae9428 100644 --- a/src/Command/EnqueueCommand.php +++ b/src/Command/EnqueueCommand.php @@ -231,6 +231,7 @@ static function (ImporterInterface $importer): string { } $allImporters = array_combine($importersCodes, $allImporters); + Assert::isArray($allImporters); /** @var ImporterInterface[] $importers */ $importers = []; diff --git a/src/Command/ReconcileCommand.php b/src/Command/ReconcileCommand.php index ff6a117e..d7174ce4 100644 --- a/src/Command/ReconcileCommand.php +++ b/src/Command/ReconcileCommand.php @@ -101,6 +101,7 @@ static function (ReconcilerInterface $reconciler): string { } $allReconcilers = array_combine($reconcilersCodes, $allReconcilers); + Assert::isArray($allReconcilers); /** @var ReconcilerInterface[] $reconcilers */ $reconcilers = []; From 362affa7a557ece68942b2cd110e84f5d98f5a82 Mon Sep 17 00:00:00 2001 From: Lorenzo Ruozzi Date: Wed, 20 Oct 2021 10:06:51 +0200 Subject: [PATCH 12/15] Try to fix phpstan --- src/Command/EnqueueCommand.php | 2 +- src/Command/ReconcileCommand.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Command/EnqueueCommand.php b/src/Command/EnqueueCommand.php index d3ae9428..704363ed 100644 --- a/src/Command/EnqueueCommand.php +++ b/src/Command/EnqueueCommand.php @@ -230,6 +230,7 @@ static function (ImporterInterface $importer): string { return $allImporters; } + /** @var ImporterInterface[]|array|false $allImporters */ $allImporters = array_combine($importersCodes, $allImporters); Assert::isArray($allImporters); @@ -239,7 +240,6 @@ static function (ImporterInterface $importer): string { if (!array_key_exists($importerToUse, $allImporters)) { throw new \InvalidArgumentException(sprintf('Importer "%s" does not exists.', $importerToUse)); } - Assert::isInstanceOf($allImporters[$importerToUse], ImporterInterface::class); $importers[] = $allImporters[$importerToUse]; } diff --git a/src/Command/ReconcileCommand.php b/src/Command/ReconcileCommand.php index d7174ce4..011b76e5 100644 --- a/src/Command/ReconcileCommand.php +++ b/src/Command/ReconcileCommand.php @@ -100,8 +100,9 @@ static function (ReconcilerInterface $reconciler): string { return $allReconcilers; } + /** @var ReconcilerInterface[]|array|false $allReconcilers */ $allReconcilers = array_combine($reconcilersCodes, $allReconcilers); - Assert::isArray($allReconcilers); + Assert::notFalse($allReconcilers); /** @var ReconcilerInterface[] $reconcilers */ $reconcilers = []; @@ -109,7 +110,6 @@ static function (ReconcilerInterface $reconciler): string { if (!array_key_exists($reconcilerToUse, $allReconcilers)) { throw new \InvalidArgumentException(sprintf('Reconciler "%s" does not exists.', $reconcilerToUse)); } - Assert::isInstanceOf($allReconcilers[$reconcilerToUse], ReconcilerInterface::class); $reconcilers[] = $allReconcilers[$reconcilerToUse]; } From c31125f7456b34447d589a0f56e55a095b9bf9f0 Mon Sep 17 00:00:00 2001 From: Lorenzo Ruozzi Date: Wed, 20 Oct 2021 10:17:31 +0200 Subject: [PATCH 13/15] Update composer.json --- composer.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index f2c5f6c0..6dcaec16 100644 --- a/composer.json +++ b/composer.json @@ -11,10 +11,14 @@ "php": "^7.4 || ^8.0", "cocur/slugify": "^4.0", "guzzlehttp/guzzle": "^6.5", - "sylius/sylius": "~1.9.0 || ~1.10.0@beta", + "sylius/sylius": "~1.9.0 || ~1.10.0", "symfony/deprecation-contracts": "^2.2", "symfony/lock": "^4.4|^5.0" }, + "conflict": { + "doctrine/dbal": "^3.0", + "doctrine/orm": "^2.10.0" + }, "require-dev": { "ext-json": "*", "behat/behat": "^3.6.1", @@ -78,9 +82,5 @@ "post-create-project-cmd": [ "php bin/create_node_symlink.php" ] - }, - "conflict": { - "doctrine/dbal": "^3.0", - "doctrine/orm": "^2.10.0" } } From 51a201774b2a09e5c5f62e6cd030f6631b2546db Mon Sep 17 00:00:00 2001 From: Lorenzo Ruozzi Date: Wed, 20 Oct 2021 10:51:59 +0200 Subject: [PATCH 14/15] Align with sylius skeleton --- .github/workflows/build.yml | 2 +- composer.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 833579fb..bb090723 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -23,7 +23,7 @@ jobs: matrix: php: ["8.0", "7.4"] symfony: ["^4.4", "^5.2"] - sylius: ["~1.9.0", "~1.10.0"] + sylius: ["~1.9.0", "~1.10.0@alpha"] node: ["10.x"] mysql: ["8.0"] diff --git a/composer.json b/composer.json index 6dcaec16..a285e844 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ "php": "^7.4 || ^8.0", "cocur/slugify": "^4.0", "guzzlehttp/guzzle": "^6.5", - "sylius/sylius": "~1.9.0 || ~1.10.0", + "sylius/sylius": "~1.9.0 || ~1.10.0@alpha", "symfony/deprecation-contracts": "^2.2", "symfony/lock": "^4.4|^5.0" }, From 7f40f3fb0d1aac152359e3fa7216caee153f269e Mon Sep 17 00:00:00 2001 From: Lorenzo Ruozzi Date: Thu, 21 Oct 2021 15:04:27 +0200 Subject: [PATCH 15/15] Chatch more explicitly client exception on retrieving product call --- src/ApiClient.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ApiClient.php b/src/ApiClient.php index 5012e52a..2db5c7ef 100644 --- a/src/ApiClient.php +++ b/src/ApiClient.php @@ -5,6 +5,7 @@ namespace Webgriffe\SyliusAkeneoPlugin; use GuzzleHttp\ClientInterface; +use GuzzleHttp\Exception\ClientException; use GuzzleHttp\Exception\GuzzleException; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\Request; @@ -255,7 +256,7 @@ private function getResourceOrNull(string $endpoint): ?array { try { $response = $this->authenticatedRequest($endpoint, 'GET', []); - } catch (\Throwable $exception) { + } catch (ClientException $exception) { if ($exception->getCode() !== 404) { throw $exception; }