Skip to content

Commit

Permalink
Don't register DomainDenormalizer if Symfony serializer isn't installed
Browse files Browse the repository at this point in the history
  • Loading branch information
mcsky committed Nov 15, 2019
1 parent 99f28d4 commit 8ac5e9a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,18 @@ 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);

$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
Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
;
}
}
}

0 comments on commit 8ac5e9a

Please sign in to comment.