diff --git a/src/Compiler/DumpXmlContainer.php b/src/Compiler/DumpXmlContainer.php new file mode 100644 index 00000000..15e78ab3 --- /dev/null +++ b/src/Compiler/DumpXmlContainer.php @@ -0,0 +1,32 @@ +configCache = $configCache; + } + + public function process(ContainerBuilder $container): void + { + if (! $container->getParameter('app.devmode') || ! $this->configCache->isFresh()) { + return; + } + + $this->configCache->write((new XmlDumper($container))->dump(), $container->getResources()); + } +} diff --git a/test/Compiler/DumpXmlContainerTest.php b/test/Compiler/DumpXmlContainerTest.php new file mode 100644 index 00000000..fd472a29 --- /dev/null +++ b/test/Compiler/DumpXmlContainerTest.php @@ -0,0 +1,89 @@ +configCache = $this->createMock(ConfigCacheInterface::class); + } + + /** + * @test + * + * @covers \Lcobucci\DependencyInjection\Compiler\DumpXmlContainer::__construct + * @covers \Lcobucci\DependencyInjection\Compiler\DumpXmlContainer::process + */ + public function processShouldBeSkippedWhenDevModeIsNotEnabled(): void + { + $this->configCache->expects($this->never()) + ->method('isFresh'); + + $this->configCache->expects($this->never()) + ->method('write'); + + $pass = new DumpXmlContainer($this->configCache); + $pass->process(new ContainerBuilder(new Parameters(['app.devmode' => false]))); + } + + /** + * @test + * + * @covers \Lcobucci\DependencyInjection\Compiler\DumpXmlContainer::__construct + * @covers \Lcobucci\DependencyInjection\Compiler\DumpXmlContainer::process + */ + public function processShouldBeSkippedWhenCacheIsNotFresh(): void + { + $this->configCache->method('isFresh') + ->willReturn(false); + + $this->configCache->expects($this->never()) + ->method('write'); + + $pass = new DumpXmlContainer($this->configCache); + $pass->process(new ContainerBuilder(new Parameters(['app.devmode' => true]))); + } + + /** + * @test + * + * @covers \Lcobucci\DependencyInjection\Compiler\DumpXmlContainer::__construct + * @covers \Lcobucci\DependencyInjection\Compiler\DumpXmlContainer::process + */ + public function processShouldDumpTheContainerUsingTheXmlDumper(): void + { + $assertXmlHeader = new StringContains( + '' + ); + + $this->configCache->method('isFresh') + ->willReturn(true); + + $this->configCache->expects($this->once()) + ->method('write') + ->with($assertXmlHeader, []); + + $pass = new DumpXmlContainer($this->configCache); + $pass->process(new ContainerBuilder(new Parameters(['app.devmode' => true]))); + } +}