Compare commits

...

1 Commits

Author SHA1 Message Date
c5b3dcde27
use cached DI container in non productive mode too 2025-03-08 23:34:54 +01:00
3 changed files with 20 additions and 21 deletions

View File

@ -144,7 +144,7 @@ class d3DicHandler implements d3DicHandlerInterface
{ {
startProfile(__METHOD__); startProfile(__METHOD__);
if ($this->d3UseCachedContainer()) { if ($this->d3UseCachedContainer() && $compileAndDump) {
$container = $this->d3GetCacheContainer(); $container = $this->d3GetCacheContainer();
} else { } else {
$container = $this->getContainerBuilder(); $container = $this->getContainerBuilder();
@ -166,9 +166,9 @@ class d3DicHandler implements d3DicHandlerInterface
{ {
$config = $this->d3GetConfig(); $config = $this->d3GetConfig();
return $config->isProductiveMode() return // $config->isProductiveMode() &&
// && !$config->getConfigParam('iDebug') // !$config->getConfigParam('iDebug') &&
&& $this->cacheFileExists(); $this->cacheFileExists();
} }
public function getContainerBuilder(): ContainerBuilder public function getContainerBuilder(): ContainerBuilder

View File

@ -17,11 +17,10 @@ declare(strict_types=1);
namespace D3\DIContainerHandler\tests\unit\autoload; namespace D3\DIContainerHandler\tests\unit\autoload;
use D3\DIContainerHandler\d3DicException;
use D3\TestingTools\Development\CanAccessRestricted; use D3\TestingTools\Development\CanAccessRestricted;
use Exception; use Exception;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Container;
class functions_oxDICTest extends TestCase class functions_oxDICTest extends TestCase
{ {
@ -37,7 +36,7 @@ class functions_oxDICTest extends TestCase
error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING); error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING);
$this->assertInstanceOf( $this->assertInstanceOf(
ContainerBuilder::class, Container::class,
d3GetOxidDIC_withExceptions() d3GetOxidDIC_withExceptions()
); );
} }
@ -52,7 +51,7 @@ class functions_oxDICTest extends TestCase
error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING); error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING);
$this->assertInstanceOf( $this->assertInstanceOf(
ContainerBuilder::class, Container::class,
d3GetOxidDIC() d3GetOxidDIC()
); );
} }

View File

@ -59,25 +59,25 @@ class d3DicHandlerTest extends TestCase
null null
); );
$containerBuilder = $this->callMethod( $container = $this->callMethod(
$sut, $sut,
'getInstance' 'getInstance'
); );
$this->assertInstanceOf( $this->assertInstanceOf(
ContainerBuilder::class, Container::class,
$containerBuilder $container
); );
$this->assertSame( $this->assertSame(
$containerBuilder, $container,
$this->callMethod( $this->callMethod(
$sut, $sut,
'getInstance' 'getInstance'
) )
); );
$this->assertTrue($containerBuilder->isCompiled()); $this->assertTrue($container->isCompiled());
} }
/** /**
@ -90,17 +90,17 @@ class d3DicHandlerTest extends TestCase
$sut = new d3DicHandler(); $sut = new d3DicHandler();
// test new instance // test new instance
$containerBuilder = $this->callMethod( $container = $this->callMethod(
$sut, $sut,
'getUncompiledInstance' 'getUncompiledInstance'
); );
$this->assertInstanceOf( $this->assertInstanceOf(
ContainerBuilder::class, Container::class,
$containerBuilder $container
); );
$this->assertFalse($containerBuilder->isCompiled()); $this->assertFalse($container->isCompiled());
// test if compiled instance is getting resetted // test if compiled instance is getting resetted
$this->callMethod( $this->callMethod(
@ -112,11 +112,11 @@ class d3DicHandlerTest extends TestCase
'getInstance' 'getInstance'
); );
$containerBuilder = $this->callMethod( $container = $this->callMethod(
$sut, $sut,
'getUncompiledInstance' '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, do compile" => [false, true];
yield "can't use cached container, don't compile" => [false, false]; 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]; yield "can't use cached container, do compile, default" => [false, true, true];
} }
@ -463,7 +463,7 @@ class d3DicHandlerTest extends TestCase
public function canUseCachedContainerDataProvider(): Generator 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 'is debug' => [true, 1, true, true];
yield 'no cache file' => [true, 0, false, false]; yield 'no cache file' => [true, 0, false, false];
yield 'can use cached' => [true, 0, true, true]; yield 'can use cached' => [true, 0, true, true];