From 22c7eea7895db9f88c4624872226822747794a25 Mon Sep 17 00:00:00 2001 From: Steve Bauman Date: Mon, 13 May 2024 11:53:15 -0400 Subject: [PATCH 1/2] Flush container on directory fake tear down --- src/Testing/DirectoryFake.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Testing/DirectoryFake.php b/src/Testing/DirectoryFake.php index 478bc804..90cbf7ae 100644 --- a/src/Testing/DirectoryFake.php +++ b/src/Testing/DirectoryFake.php @@ -40,9 +40,10 @@ public static function tearDown(): void { foreach (static::$replaced as $name => $connection) { Container::getConnection($name)->tearDown(); - Container::addConnection($connection, $name); } + Container::flush(); + static::$replaced = []; } From 8963628107ee09efaf5671f9303b424d02c8643a Mon Sep 17 00:00:00 2001 From: Steve Bauman Date: Mon, 13 May 2024 11:56:00 -0400 Subject: [PATCH 2/2] Add test --- tests/Unit/Testing/DirectoryFakeTest.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/Unit/Testing/DirectoryFakeTest.php b/tests/Unit/Testing/DirectoryFakeTest.php index 517ec16d..20f395bb 100644 --- a/tests/Unit/Testing/DirectoryFakeTest.php +++ b/tests/Unit/Testing/DirectoryFakeTest.php @@ -30,4 +30,17 @@ public function testSetupCreatesConnectedFakeConnectionAndLdapInstance() $this->assertInstanceOf(ConnectionFake::class, $fake); $this->assertInstanceOf(LdapFake::class, $fake->getLdapConnection()); } + + public function testTearDownFlushesContainer() + { + Container::addConnection(new Connection); + + DirectoryFake::setup(); + + $this->assertCount(1, Container::getConnections()); + + DirectoryFake::tearDown(); + + $this->assertCount(0, Container::getConnections()); + } }