From 22cbb0d0f5008a72f7552b7cb23b06e8d1d688f4 Mon Sep 17 00:00:00 2001 From: othillo Date: Wed, 15 Nov 2017 21:12:10 +0100 Subject: [PATCH] saga should not be enabled by default --- src/DependencyInjection/BroadwayExtension.php | 2 +- .../RegisterSagaStateRepositoryCompilerPass.php | 4 ++++ .../RegisterSagaStateRepositoryCompilerPassTest.php | 3 ++- test/DependencyInjection/Extension/SagaExtensionTest.php | 9 +++++++++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/DependencyInjection/BroadwayExtension.php b/src/DependencyInjection/BroadwayExtension.php index cbf0f2f..4080e1a 100644 --- a/src/DependencyInjection/BroadwayExtension.php +++ b/src/DependencyInjection/BroadwayExtension.php @@ -38,7 +38,7 @@ protected function loadInternal(array $mergedConfig, ContainerBuilder $container $this->loadCommandBus($mergedConfig['command_handling'], $container, $loader); $this->loadSerializers($mergedConfig['serializer'], $container, $loader); - if (isset($mergedConfig['saga'])) { + if (isset($mergedConfig['saga']) && isset($mergedConfig['saga']['enabled']) && $mergedConfig['saga']['enabled']) { $loader->load('saga.xml'); if (isset($mergedConfig['saga']['state_repository'])) { diff --git a/src/DependencyInjection/RegisterSagaStateRepositoryCompilerPass.php b/src/DependencyInjection/RegisterSagaStateRepositoryCompilerPass.php index d4f44ee..4ca7ad4 100644 --- a/src/DependencyInjection/RegisterSagaStateRepositoryCompilerPass.php +++ b/src/DependencyInjection/RegisterSagaStateRepositoryCompilerPass.php @@ -18,6 +18,10 @@ class RegisterSagaStateRepositoryCompilerPass extends CompilerPass { public function process(ContainerBuilder $container) { + if (! $container->hasDefinition('broadway.saga.state.in_memory_repository')) { + return; + } + $serviceParameter = 'broadway.saga.state.repository.service_id'; if (! $container->hasParameter($serviceParameter)) { $container->setAlias( diff --git a/test/DependencyInjection/CompilerPass/RegisterSagaStateRepositoryCompilerPassTest.php b/test/DependencyInjection/CompilerPass/RegisterSagaStateRepositoryCompilerPassTest.php index 9f642af..dacdb77 100644 --- a/test/DependencyInjection/CompilerPass/RegisterSagaStateRepositoryCompilerPassTest.php +++ b/test/DependencyInjection/CompilerPass/RegisterSagaStateRepositoryCompilerPassTest.php @@ -11,7 +11,6 @@ namespace Broadway\Bundle\BroadwayBundle\DependencyInjection; -use Broadway\EventStore\EventStore; use Broadway\Saga\State\RepositoryInterface; use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -24,6 +23,8 @@ class RegisterSagaStateRepositoryCompilerPassTest extends AbstractCompilerPassTe */ protected function registerCompilerPass(ContainerBuilder $container) { + $this->setDefinition('broadway.saga.state.in_memory_repository', new Definition(RepositoryInterface::class)); + $container->addCompilerPass(new RegisterSagaStateRepositoryCompilerPass()); } diff --git a/test/DependencyInjection/Extension/SagaExtensionTest.php b/test/DependencyInjection/Extension/SagaExtensionTest.php index 879a03c..f8fc827 100644 --- a/test/DependencyInjection/Extension/SagaExtensionTest.php +++ b/test/DependencyInjection/Extension/SagaExtensionTest.php @@ -26,6 +26,15 @@ protected function getContainerExtensions() ]; } + /** + * @test + */ + public function it_does_not_register_the_saga_state_manager_service_when_not_configured() + { + $this->load([]); + + $this->assertFalse($this->container->hasDefinition('broadway.saga.state.state_manager')); + } /** * @test