From dbbc1e6e7fbc7aaf5a16a15c9f6664bde42bdf6d Mon Sep 17 00:00:00 2001 From: Wojdylak Date: Wed, 20 Mar 2024 11:19:49 +0100 Subject: [PATCH] [Maintenance] Enable symfony workflow tests --- .../config/sylius/1.13/_sylius.yaml | 6 --- .../config/sylius/1.13/packages/_sylius.yaml | 8 ++++ tests/Application/src/Kernel.php | 40 +++++++++++++++++++ 3 files changed, 48 insertions(+), 6 deletions(-) delete mode 100644 tests/Application/config/sylius/1.13/_sylius.yaml create mode 100644 tests/Application/config/sylius/1.13/packages/_sylius.yaml diff --git a/tests/Application/config/sylius/1.13/_sylius.yaml b/tests/Application/config/sylius/1.13/_sylius.yaml deleted file mode 100644 index 320a1c56..00000000 --- a/tests/Application/config/sylius/1.13/_sylius.yaml +++ /dev/null @@ -1,6 +0,0 @@ -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: - default_adapter: '%test_sylius_state_machine_adapter%' diff --git a/tests/Application/config/sylius/1.13/packages/_sylius.yaml b/tests/Application/config/sylius/1.13/packages/_sylius.yaml new file mode 100644 index 00000000..a2043583 --- /dev/null +++ b/tests/Application/config/sylius/1.13/packages/_sylius.yaml @@ -0,0 +1,8 @@ +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_payment: '%test_sylius_state_machine_adapter%' + default_adapter: '%test_sylius_state_machine_adapter%' diff --git a/tests/Application/src/Kernel.php b/tests/Application/src/Kernel.php index 54a35f17..38d1d069 100644 --- a/tests/Application/src/Kernel.php +++ b/tests/Application/src/Kernel.php @@ -8,7 +8,9 @@ use Sylius\Bundle\CoreBundle\SyliusCoreBundle; 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; @@ -21,12 +23,15 @@ use Symfony\Component\HttpKernel\Bundle\BundleInterface; use Symfony\Component\HttpKernel\Config\FileLocator; use Symfony\Component\HttpKernel\Kernel as BaseKernel; +use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator; use Webmozart\Assert\Assert; final class Kernel extends BaseKernel { use MicroKernelTrait; + private const CONFIG_EXTS = '.{php,xml,yaml,yml}'; + public function getCacheDir(): string { return $this->getProjectDir() . '/var/cache/' . $this->environment; @@ -44,6 +49,26 @@ 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,6 +100,21 @@ private function isTestEnvironment(): bool return str_starts_with($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 BundleInterface[] */