From 8ac5e9a394a0799102fe8277fa54b96e3e4a82f7 Mon Sep 17 00:00:00 2001 From: Mcsky Date: Fri, 15 Nov 2019 15:21:44 +0100 Subject: [PATCH] Don't register DomainDenormalizer if Symfony serializer isn't installed --- ...EnableDomainDenormalizerCompilerPassTest.php | 17 ++++++++++------- .../EnableDomainDenormalizerCompilerPass.php | 14 ++++++++------ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/Tests/Symfony/DependencyInjection/CompilerPass/EnableDomainDenormalizerCompilerPassTest.php b/Tests/Symfony/DependencyInjection/CompilerPass/EnableDomainDenormalizerCompilerPassTest.php index b72be8a..295137d 100644 --- a/Tests/Symfony/DependencyInjection/CompilerPass/EnableDomainDenormalizerCompilerPassTest.php +++ b/Tests/Symfony/DependencyInjection/CompilerPass/EnableDomainDenormalizerCompilerPassTest.php @@ -28,10 +28,10 @@ public function testItAddsDefinitionServiceForApiPlatformDomainDenormalizer() public function testItAddsDefinitionServiceForDomainDenormalizer() { $compilerPass = new EnableDomainDenormalizerCompilerPass(); - $compilerPass->process($this->getContainerMock()); + $compilerPass->process($this->getContainerMock(false, true)); } - private function getContainerMock($apiPlatform = false) + private function getContainerMock($apiPlatform = false, $symfonySerializer = false) { $container = $this->prophesize(ContainerBuilder::class); $definition = $this->prophesize(Definition::class); @@ -39,6 +39,7 @@ private function getContainerMock($apiPlatform = false) $container->hasDefinition('api_platform.jsonld.normalizer.item')->willReturn($apiPlatform ? $apiPlatform : []); $container->hasDefinition('api_platform.serializer.normalizer.item')->willReturn($apiPlatform ? $apiPlatform : []); $container->hasDefinition('api_platform.hal.normalizer.item')->willReturn($apiPlatform ? $apiPlatform : []); + $container->hasDefinition('serializer.normalizer.object')->willReturn($symfonySerializer ? $symfonySerializer : []); if ($apiPlatform) { //api_platform.jsonld.normalizer.item @@ -64,11 +65,13 @@ private function getContainerMock($apiPlatform = false) } - $definition->setDecoratedService(Argument::type('string'))->willReturn($definition)->shouldBeCalled(); - $definition->addArgument(Argument::type(Reference::class))->willReturn($definition)->shouldBeCalled(); - $definition->addArgument(new Reference('biig_domain.dispatcher'))->willReturn($definition)->shouldBeCalled(); - $definition->setPublic(false)->willReturn($definition)->shouldBeCalled(); - $container->register('biig.domain_denormalizer', DomainDenormalizer::class)->willReturn($definition); + if ($symfonySerializer) { + $definition->setDecoratedService(Argument::type('string'))->willReturn($definition)->shouldBeCalled(); + $definition->addArgument(Argument::type(Reference::class))->willReturn($definition)->shouldBeCalled(); + $definition->addArgument(new Reference('biig_domain.dispatcher'))->willReturn($definition)->shouldBeCalled(); + $definition->setPublic(false)->willReturn($definition)->shouldBeCalled(); + $container->register('biig.domain_denormalizer', DomainDenormalizer::class)->willReturn($definition); + } return $container->reveal(); } diff --git a/src/Integration/Symfony/DependencyInjection/CompilerPass/EnableDomainDenormalizerCompilerPass.php b/src/Integration/Symfony/DependencyInjection/CompilerPass/EnableDomainDenormalizerCompilerPass.php index 62a7d1e..4567d56 100644 --- a/src/Integration/Symfony/DependencyInjection/CompilerPass/EnableDomainDenormalizerCompilerPass.php +++ b/src/Integration/Symfony/DependencyInjection/CompilerPass/EnableDomainDenormalizerCompilerPass.php @@ -39,11 +39,13 @@ public function process(ContainerBuilder $container) ; } - $container->register($serviceId, DomainDenormalizer::class) - ->setDecoratedService('serializer.normalizer.object') - ->addArgument(new Reference($serviceId . '.inner')) - ->addArgument(new Reference('biig_domain.dispatcher')) - ->setPublic(false) - ; + if ($container->hasDefinition('serializer.normalizer.object')) { + $container->register($serviceId, DomainDenormalizer::class) + ->setDecoratedService('serializer.normalizer.object') + ->addArgument(new Reference($serviceId . '.inner')) + ->addArgument(new Reference('biig_domain.dispatcher')) + ->setPublic(false) + ; + } } }