From c5b3dcde27a56aef8290fef8304cb678830003b1 Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Sat, 8 Mar 2025 23:34:54 +0100 Subject: [PATCH] use cached DI container in non productive mode too --- d3DicHandler.php | 8 +++---- tests/unit/autoload/functions_oxDICTest.php | 7 +++--- tests/unit/d3DicHandlerTest.php | 26 ++++++++++----------- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/d3DicHandler.php b/d3DicHandler.php index e7ef7f6..2ef776f 100644 --- a/d3DicHandler.php +++ b/d3DicHandler.php @@ -144,7 +144,7 @@ class d3DicHandler implements d3DicHandlerInterface { startProfile(__METHOD__); - if ($this->d3UseCachedContainer()) { + if ($this->d3UseCachedContainer() && $compileAndDump) { $container = $this->d3GetCacheContainer(); } else { $container = $this->getContainerBuilder(); @@ -166,9 +166,9 @@ class d3DicHandler implements d3DicHandlerInterface { $config = $this->d3GetConfig(); - return $config->isProductiveMode() -// && !$config->getConfigParam('iDebug') - && $this->cacheFileExists(); + return // $config->isProductiveMode() && +// !$config->getConfigParam('iDebug') && + $this->cacheFileExists(); } public function getContainerBuilder(): ContainerBuilder diff --git a/tests/unit/autoload/functions_oxDICTest.php b/tests/unit/autoload/functions_oxDICTest.php index 21fcd4b..3863654 100644 --- a/tests/unit/autoload/functions_oxDICTest.php +++ b/tests/unit/autoload/functions_oxDICTest.php @@ -17,11 +17,10 @@ declare(strict_types=1); namespace D3\DIContainerHandler\tests\unit\autoload; -use D3\DIContainerHandler\d3DicException; use D3\TestingTools\Development\CanAccessRestricted; use Exception; use PHPUnit\Framework\TestCase; -use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Container; class functions_oxDICTest extends TestCase { @@ -37,7 +36,7 @@ class functions_oxDICTest extends TestCase error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING); $this->assertInstanceOf( - ContainerBuilder::class, + Container::class, d3GetOxidDIC_withExceptions() ); } @@ -52,7 +51,7 @@ class functions_oxDICTest extends TestCase error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING); $this->assertInstanceOf( - ContainerBuilder::class, + Container::class, d3GetOxidDIC() ); } diff --git a/tests/unit/d3DicHandlerTest.php b/tests/unit/d3DicHandlerTest.php index 40a421b..8b18e24 100644 --- a/tests/unit/d3DicHandlerTest.php +++ b/tests/unit/d3DicHandlerTest.php @@ -59,25 +59,25 @@ class d3DicHandlerTest extends TestCase null ); - $containerBuilder = $this->callMethod( + $container = $this->callMethod( $sut, 'getInstance' ); $this->assertInstanceOf( - ContainerBuilder::class, - $containerBuilder + Container::class, + $container ); $this->assertSame( - $containerBuilder, + $container, $this->callMethod( $sut, 'getInstance' ) ); - $this->assertTrue($containerBuilder->isCompiled()); + $this->assertTrue($container->isCompiled()); } /** @@ -90,17 +90,17 @@ class d3DicHandlerTest extends TestCase $sut = new d3DicHandler(); // test new instance - $containerBuilder = $this->callMethod( + $container = $this->callMethod( $sut, 'getUncompiledInstance' ); $this->assertInstanceOf( - ContainerBuilder::class, - $containerBuilder + Container::class, + $container ); - $this->assertFalse($containerBuilder->isCompiled()); + $this->assertFalse($container->isCompiled()); // test if compiled instance is getting resetted $this->callMethod( @@ -112,11 +112,11 @@ class d3DicHandlerTest extends TestCase 'getInstance' ); - $containerBuilder = $this->callMethod( + $container = $this->callMethod( $sut, 'getUncompiledInstance' ); - $this->assertFalse($containerBuilder->isCompiled()); + $this->assertFalse($container->isCompiled()); } /** @@ -420,7 +420,7 @@ class d3DicHandlerTest extends TestCase { yield "can't use cached container, do compile" => [false, true]; yield "can't use cached container, don't compile" => [false, false]; - yield "use cached container" => [true, false]; + yield "use cached container" => [true, true]; yield "can't use cached container, do compile, default" => [false, true, true]; } @@ -463,7 +463,7 @@ class d3DicHandlerTest extends TestCase public function canUseCachedContainerDataProvider(): Generator { - yield "not productive" => [false, 0, true, false]; + yield "not productive" => [false, 0, true, true]; yield 'is debug' => [true, 1, true, true]; yield 'no cache file' => [true, 0, false, false]; yield 'can use cached' => [true, 0, true, true];