From f3199afbf890a17c83523f91849403b369be49e5 Mon Sep 17 00:00:00 2001 From: Arman <407448+armanist@users.noreply.github.com> Date: Sun, 15 Mar 2026 23:21:40 +0400 Subject: [PATCH] Adding new resetContainer method to Di class and updating tests --- src/Di/Di.php | 5 +++++ tests/Unit/Di/DiTest.php | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+) 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()); + } } }