From 757b698ac19f2d82ceed440ff9444f9a26b17c23 Mon Sep 17 00:00:00 2001 From: Jan Goralski Date: Fri, 1 Mar 2024 12:59:40 +0100 Subject: [PATCH] [Maintenance] Slight fixes of 1.13 support --- .github/workflows/build.yml | 1 - README.md | 7 --- UPGRADE-1.5.md | 7 +++ .../SyliusRefundExtension.php | 13 +++++ .../{app => integrations}/workflow.yaml | 0 tests/Application/Kernel.php | 55 ++----------------- tests/Application/config/bundles.php | 11 +--- .../config/sylius/1.12/_sylius.yaml | 3 - .../config/sylius/1.13/_sylius.yaml | 1 - .../config/sylius/1.13/workflow.yaml | 21 ------- .../Application/public/media/image/.gitignore | 0 11 files changed, 27 insertions(+), 92 deletions(-) rename src/Resources/config/{app => integrations}/workflow.yaml (100%) delete mode 100644 tests/Application/config/sylius/1.12/_sylius.yaml delete mode 100644 tests/Application/config/sylius/1.13/workflow.yaml delete mode 100644 tests/Application/public/media/image/.gitignore diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 054a26ca..43324aad 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -31,7 +31,6 @@ jobs: wkhtmltopdf: ["0.12.6-1"] state_machine_adapter: [ "winzou_state_machine", "symfony_workflow" ] - include: - php: "8.1" diff --git a/README.md b/README.md index 818f70d7..06bafe5d 100644 --- a/README.md +++ b/README.md @@ -64,13 +64,6 @@ From Administrator's point of view, every Refund request results in creating two WKHTMLTOPDF_PATH=/usr/local/bin/wkhtmltopdf # Change this! :) ``` -1. If you are using the symfony workflows instead winzou_state_machine please import configuration: - - ```yaml - imports: - - { resource: "@SyliusRefundPlugin/Resources/config/app/workflow.yaml" } - ``` - #### Beware! This installation instruction assumes that you're using Symfony Flex. If you don't, take a look at the diff --git a/UPGRADE-1.5.md b/UPGRADE-1.5.md index 5411f987..9c3413d6 100644 --- a/UPGRADE-1.5.md +++ b/UPGRADE-1.5.md @@ -16,3 +16,10 @@ constructors of `Sylius\RefundPlugin\Converter\LineItem\OrderItemUnitLineItemsConverter` and `Sylius\RefundPlugin\Converter\LineItem\ShipmentLineItemsConverter` has been deprecated and will be prohibited in 2.0. + +5. Support for Sylius 1.13 has been added, it is now the recommended Sylius version to use with RefundPlugin. + +6. Support for Sylius 1.11 has been dropped, upgrade your application to [Sylius 1.12](https://github.com/Sylius/Sylius/blob/1.12/UPGRADE-1.12.md). + or to [Sylius 1.13](https://github.com/Sylius/Sylius/blob/1.13/UPGRADE-1.13.md). + +7. Support for PHP 8.0 has been dropped. diff --git a/src/DependencyInjection/SyliusRefundExtension.php b/src/DependencyInjection/SyliusRefundExtension.php index c774fe3b..9b6f6bd6 100644 --- a/src/DependencyInjection/SyliusRefundExtension.php +++ b/src/DependencyInjection/SyliusRefundExtension.php @@ -25,6 +25,7 @@ use Symfony\Component\DependencyInjection\Extension\Extension; use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; +use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; final class SyliusRefundExtension extends Extension implements PrependExtensionInterface { @@ -58,6 +59,7 @@ public function prepend(ContainerBuilder $container): void $container->setParameter('sylius_refund.pdf_generator.enabled', $configs['pdf_generator']['enabled']); $this->prependDoctrineMigrations($container); + $this->prependSymfonyWorkflow($container); } protected function getMigrationsNamespace(): string @@ -94,4 +96,15 @@ private function tagsAutoconfiguration(ContainerBuilder $container, array $tagge $container->registerForAutoconfiguration($interface)->addTag($tag); } } + + private function prependSymfonyWorkflow(ContainerBuilder $container): void + { + if (!class_exists('\Symfony\Component\Workflow\Workflow')) { + return; + } + + $loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); + + $loader->load('integrations/workflow.yaml'); + } } diff --git a/src/Resources/config/app/workflow.yaml b/src/Resources/config/integrations/workflow.yaml similarity index 100% rename from src/Resources/config/app/workflow.yaml rename to src/Resources/config/integrations/workflow.yaml diff --git a/tests/Application/Kernel.php b/tests/Application/Kernel.php index 2dcdfde2..e47c5e3a 100644 --- a/tests/Application/Kernel.php +++ b/tests/Application/Kernel.php @@ -5,28 +5,15 @@ namespace Tests\Sylius\RefundPlugin\Application; use PSS\SymfonyMockerContainer\DependencyInjection\MockerContainer; -use Sylius\Bundle\CoreBundle\Application\Kernel as SyliusKernel; +use Sylius\Bundle\CoreBundle\SyliusCoreBundle; use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; -use Symfony\Component\Config\Loader\LoaderInterface; -use Symfony\Component\Config\Resource\FileResource; -use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Bundle\BundleInterface; use Symfony\Component\HttpKernel\Kernel as BaseKernel; -use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator; final class Kernel extends BaseKernel { use MicroKernelTrait; - private const CONFIG_EXTS = '.{php,xml,yaml,yml}'; - - private const IGNORED_SERVICES_DURING_CLEANUP = [ - 'kernel', - 'http_kernel', - 'liip_imagine.mime_type_guesser', - 'liip_imagine.extension_guesser', - ]; - public function getCacheDir(): string { return $this->getProjectDir() . '/var/cache/' . $this->environment; @@ -44,26 +31,6 @@ public function registerBundles(): iterable } } - protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void - { - foreach ($this->getBundleListFiles() as $file) { - $container->addResource(new FileResource($file)); - } - - $container->setParameter('container.dumper.inline_class_loader', true); - - foreach ($this->getConfigurationDirectories() as $confDir) { - $this->loadContainerConfiguration($loader, $confDir); - } - } - - protected function configureRoutes(RoutingConfigurator $routes): void - { - foreach ($this->getConfigurationDirectories() as $confDir) { - $this->loadRoutesConfiguration($routes, $confDir); - } - } - protected function getContainerBaseClass(): string { if ($this->isTestEnvironment() && class_exists(MockerContainer::class)) { @@ -75,22 +42,7 @@ protected function getContainerBaseClass(): string private function isTestEnvironment(): bool { - return 0 === strpos($this->getEnvironment(), 'test'); - } - - private function loadContainerConfiguration(LoaderInterface $loader, string $confDir): void - { - $loader->load($confDir . '/{packages}/*' . self::CONFIG_EXTS, 'glob'); - $loader->load($confDir . '/{packages}/' . $this->environment . '/**/*' . self::CONFIG_EXTS, 'glob'); - $loader->load($confDir . '/{services}' . self::CONFIG_EXTS, 'glob'); - $loader->load($confDir . '/{services}_' . $this->environment . self::CONFIG_EXTS, 'glob'); - } - - private function loadRoutesConfiguration(RoutingConfigurator $routes, string $confDir): void - { - $routes->import($confDir . '/{routes}/*' . self::CONFIG_EXTS); - $routes->import($confDir . '/{routes}/' . $this->environment . '/**/*' . self::CONFIG_EXTS); - $routes->import($confDir . '/{routes}' . self::CONFIG_EXTS); + return str_starts_with($this->getEnvironment(), 'test'); } /** @@ -100,6 +52,7 @@ private function registerBundlesFromFile(string $bundlesFile): iterable { $contents = require $bundlesFile; + /** @var BundleInterface $class */ foreach ($contents as $class => $envs) { if (isset($envs['all']) || isset($envs[$this->environment])) { yield new $class(); @@ -130,7 +83,7 @@ private function getConfigurationDirectories(): array { $directories = [ $this->getProjectDir() . '/config', - $this->getProjectDir() . '/config/sylius/' . SyliusKernel::MAJOR_VERSION . '.' . SyliusKernel::MINOR_VERSION, + $this->getProjectDir() . '/config/sylius/' . SyliusCoreBundle::MAJOR_VERSION . '.' . SyliusCoreBundle::MINOR_VERSION, ]; return array_filter($directories, 'file_exists'); diff --git a/tests/Application/config/bundles.php b/tests/Application/config/bundles.php index 7c53154e..f82c7db5 100644 --- a/tests/Application/config/bundles.php +++ b/tests/Application/config/bundles.php @@ -1,6 +1,6 @@ ['all' => true], @@ -8,6 +8,7 @@ Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true], Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true], Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true], + League\FlysystemBundle\FlysystemBundle::class => ['all' => true], Sylius\Bundle\OrderBundle\SyliusOrderBundle::class => ['all' => true], Sylius\Bundle\MoneyBundle\SyliusMoneyBundle::class => ['all' => true], Sylius\Bundle\CurrencyBundle\SyliusCurrencyBundle::class => ['all' => true], @@ -61,13 +62,7 @@ Symfony\WebpackEncoreBundle\WebpackEncoreBundle::class => ['all' => true], ]; -if (SyliusKernel::MINOR_VERSION > 11) { - $bundles[League\FlysystemBundle\FlysystemBundle::class] = ['all' => true]; -} else { - $bundles[Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle::class] = ['all' => true]; -} - -if (SyliusKernel::MINOR_VERSION == 13) { +if (SyliusCoreBundle::VERSION_ID >= '11300') { $bundles[Sylius\Abstraction\StateMachine\SyliusStateMachineAbstractionBundle::class] = ['all' => true]; } diff --git a/tests/Application/config/sylius/1.12/_sylius.yaml b/tests/Application/config/sylius/1.12/_sylius.yaml deleted file mode 100644 index faeb14bb..00000000 --- a/tests/Application/config/sylius/1.12/_sylius.yaml +++ /dev/null @@ -1,3 +0,0 @@ -parameters: - test_default_state_machine_adapter: 'winzou_state_machine' - test_sylius_state_machine_adapter: '%env(string:default:test_default_state_machine_adapter:TEST_SYLIUS_STATE_MACHINE_ADAPTER)%' diff --git a/tests/Application/config/sylius/1.13/_sylius.yaml b/tests/Application/config/sylius/1.13/_sylius.yaml index 1e5c4392..76aa43aa 100644 --- a/tests/Application/config/sylius/1.13/_sylius.yaml +++ b/tests/Application/config/sylius/1.13/_sylius.yaml @@ -2,7 +2,6 @@ parameters: test_default_state_machine_adapter: 'symfony_workflow' test_sylius_state_machine_adapter: '%env(string:default:test_default_state_machine_adapter:TEST_SYLIUS_STATE_MACHINE_ADAPTER)%' - sylius_state_machine_abstraction: graphs_to_adapters_mapping: sylius_refund_refund_payment: '%test_sylius_state_machine_adapter%' diff --git a/tests/Application/config/sylius/1.13/workflow.yaml b/tests/Application/config/sylius/1.13/workflow.yaml deleted file mode 100644 index cea8c72c..00000000 --- a/tests/Application/config/sylius/1.13/workflow.yaml +++ /dev/null @@ -1,21 +0,0 @@ -framework: - workflows: - sylius_refund_refund_payment: - type: state_machine - marking_store: - type: method - property: state - supports: - - Sylius\RefundPlugin\Entity\RefundPayment - initial_marking: new - places: - - !php/const Sylius\RefundPlugin\Entity\RefundPaymentInterface::STATE_NEW - - !php/const Sylius\RefundPlugin\Entity\RefundPaymentInterface::STATE_COMPLETED - transitions: - complete: - from: !php/const Sylius\RefundPlugin\Entity\RefundPaymentInterface::STATE_NEW - to: !php/const Sylius\RefundPlugin\Entity\RefundPaymentInterface::STATE_COMPLETED - -sylius_state_machine_abstraction: - graphs_to_adapters_mapping: - sylius_refund_refund_payment: symfony_workflow diff --git a/tests/Application/public/media/image/.gitignore b/tests/Application/public/media/image/.gitignore deleted file mode 100644 index e69de29b..00000000