From 4ed5536a810f032487d03fa2e770898e21fed7ea Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Thu, 4 Jul 2024 19:03:49 +0400 Subject: [PATCH] test: DatabaseTestCase now always drops DB on tearDown --- tests/src/Functional/ActiveRecordTest.php | 17 ----------------- tests/src/Functional/DatabaseTestCase.php | 17 +++++++++++++++++ tests/src/Functional/Query/ActiveQueryTest.php | 18 ------------------ 3 files changed, 17 insertions(+), 35 deletions(-) diff --git a/tests/src/Functional/ActiveRecordTest.php b/tests/src/Functional/ActiveRecordTest.php index 902fd73..402dd8e 100644 --- a/tests/src/Functional/ActiveRecordTest.php +++ b/tests/src/Functional/ActiveRecordTest.php @@ -6,8 +6,6 @@ use Cycle\ActiveRecord\Facade; use Cycle\App\Entity\User; -use Cycle\Database\Database; -use Cycle\Database\DatabaseManager; use Cycle\ORM\Select\Repository; use PHPUnit\Framework\Attributes\Test; @@ -167,19 +165,4 @@ public function it_gets_default_repository_of_entity(): void self::assertInstanceOf(Repository::class, $repository); } - - /** - * @throws \Throwable - */ - public function tearDown(): void - { - parent::tearDown(); - - $databaseManager = $this->getContainer()->get(DatabaseManager::class); - /** @var Database $database */ - $database = $databaseManager->database('default'); - - $this->dropDatabase($database); - Facade::reset(); - } } diff --git a/tests/src/Functional/DatabaseTestCase.php b/tests/src/Functional/DatabaseTestCase.php index 6e4f5ac..0891537 100644 --- a/tests/src/Functional/DatabaseTestCase.php +++ b/tests/src/Functional/DatabaseTestCase.php @@ -4,8 +4,10 @@ namespace Cycle\Tests\Functional; +use Cycle\ActiveRecord\Facade; use Cycle\Database\Database; use Cycle\Database\DatabaseInterface; +use Cycle\Database\DatabaseManager; use Cycle\Database\Driver\DriverInterface; use Cycle\Database\Driver\HandlerInterface; use Cycle\Database\Table; @@ -56,6 +58,21 @@ protected function setUp(): void ]); } + /** + * @throws \Throwable + */ + protected function tearDown(): void + { + parent::tearDown(); + + $databaseManager = $this->getContainer()->get(DatabaseManager::class); + /** @var Database $database */ + $database = $databaseManager->database('default'); + + $this->dropDatabase($database); + Facade::reset(); + } + /** * @throws \Throwable */ diff --git a/tests/src/Functional/Query/ActiveQueryTest.php b/tests/src/Functional/Query/ActiveQueryTest.php index eade012..018c852 100644 --- a/tests/src/Functional/Query/ActiveQueryTest.php +++ b/tests/src/Functional/Query/ActiveQueryTest.php @@ -4,10 +4,7 @@ namespace Cycle\Tests\Functional\Query; -use Cycle\ActiveRecord\Facade; use Cycle\App\Entity\User; -use Cycle\Database\Database; -use Cycle\Database\DatabaseManager; use Cycle\Tests\Functional\DatabaseTestCase; use PHPUnit\Framework\Attributes\Test; @@ -20,19 +17,4 @@ public function it_gets_role_from_query(): void self::assertSame(User::class, $query->getRole()); } - - /** - * @throws \Throwable - */ - public function tearDown(): void - { - parent::tearDown(); - - $databaseManager = $this->getContainer()->get(DatabaseManager::class); - /** @var Database $database */ - $database = $databaseManager->database('default'); - - $this->dropDatabase($database); - Facade::reset(); - } }