diff --git a/d3DicHandler.php b/d3DicHandler.php index 468f155..e7ef7f6 100644 --- a/d3DicHandler.php +++ b/d3DicHandler.php @@ -50,6 +50,7 @@ class d3DicHandler implements d3DicHandlerInterface */ public static function getUncompiledInstance(): Container { + if (self::$_instance !== null && self::$_instance->isCompiled()) {self::removeInstance();} return oxNew(d3DicHandler::class)->createInstance(false); } diff --git a/tests/unit/d3DicHandlerTest.php b/tests/unit/d3DicHandlerTest.php index 2418a25..40a421b 100644 --- a/tests/unit/d3DicHandlerTest.php +++ b/tests/unit/d3DicHandlerTest.php @@ -89,6 +89,7 @@ class d3DicHandlerTest extends TestCase { $sut = new d3DicHandler(); + // test new instance $containerBuilder = $this->callMethod( $sut, 'getUncompiledInstance' @@ -100,6 +101,22 @@ class d3DicHandlerTest extends TestCase ); $this->assertFalse($containerBuilder->isCompiled()); + + // test if compiled instance is getting resetted + $this->callMethod( + $sut, + 'removeInstance' + ); + $this->callMethod( + $sut, + 'getInstance' + ); + + $containerBuilder = $this->callMethod( + $sut, + 'getUncompiledInstance' + ); + $this->assertFalse($containerBuilder->isCompiled()); } /**