diff --git a/src/Di/Di.php b/src/Di/Di.php index 47f34c05d..f0cea1004 100644 --- a/src/Di/Di.php +++ b/src/Di/Di.php @@ -176,6 +176,11 @@ public static function autowire(callable $entry, array $args = []): array public static function reset(): void { self::$dependencies = []; + self::resetContainer(); + } + + public static function resetContainer(): void + { self::$container = []; self::$resolving = []; } diff --git a/tests/Unit/Di/DiTest.php b/tests/Unit/Di/DiTest.php index f49efbca6..e9197739d 100644 --- a/tests/Unit/Di/DiTest.php +++ b/tests/Unit/Di/DiTest.php @@ -309,5 +309,26 @@ public function testDiReset(): void $this->assertEmpty($containerProperty->getValue()); } + + public function testDiResetContainer(): void + { + Di::register(DummyService::class); + + Di::get(DummyService::class); + + $this->assertTrue(Di::isRegistered(DummyService::class)); + + Di::resetContainer(); + + $dependenciesProperty = new ReflectionProperty(Di::class, 'dependencies'); + $dependenciesProperty->setAccessible(true); + + $containerProperty = new ReflectionProperty(Di::class, 'container'); + $containerProperty->setAccessible(true); + + $this->assertNotEmpty($dependenciesProperty->getValue()); + + $this->assertEmpty($containerProperty->getValue()); + } } }