diff --git a/tests/_support/Config/Registrar.php b/tests/_support/Config/Registrar.php index b92c5e24bb16..43e44de30fc7 100644 --- a/tests/_support/Config/Registrar.php +++ b/tests/_support/Config/Registrar.php @@ -134,9 +134,9 @@ public static function Database(): array // Under GitHub Actions, we can set an ENV var named 'DB' // so that we can test against multiple databases. - if (($group = getenv('DB')) && isset(self::$dbConfig[$group])) { - $config['tests'] = self::$dbConfig[$group]; - } + $group = env('DB', 'SQLite3'); + + $config['tests'] = self::$dbConfig[$group] ?? []; return $config; } diff --git a/tests/system/Commands/CreateDatabaseTest.php b/tests/system/Commands/CreateDatabaseTest.php index af5b6d3b1682..a7e0fe11638f 100644 --- a/tests/system/Commands/CreateDatabaseTest.php +++ b/tests/system/Commands/CreateDatabaseTest.php @@ -14,7 +14,6 @@ namespace CodeIgniter\Commands; use CodeIgniter\Database\BaseConnection; -use CodeIgniter\Database\Database as DatabaseFactory; use CodeIgniter\Database\OCI8\Connection as OCI8Connection; use CodeIgniter\Database\SQLite3\Connection as SQLite3Connection; use CodeIgniter\Test\CIUnitTestCase; @@ -51,16 +50,13 @@ protected function tearDown(): void private function dropDatabase(): void { if ($this->connection instanceof SQLite3Connection) { - $file = WRITEPATH . 'foobar.db'; + $file = WRITEPATH . 'database.db'; + if (is_file($file)) { unlink($file); } - } else { - $util = (new DatabaseFactory())->loadUtils($this->connection); - - if ($util->databaseExists('foobar')) { - Database::forge()->dropDatabase('foobar'); - } + } elseif (Database::utils('tests')->databaseExists('database')) { + Database::forge()->dropDatabase('database'); } } @@ -75,7 +71,7 @@ public function testCreateDatabase(): void $this->markTestSkipped('Needs to run on non-OCI8 drivers.'); } - command('db:create foobar'); + command('db:create database'); $this->assertStringContainsString('successfully created.', $this->getBuffer()); } @@ -85,10 +81,10 @@ public function testSqliteDatabaseDuplicated(): void $this->markTestSkipped('Needs to run on SQLite3.'); } - command('db:create foobar'); + command('db:create database'); $this->resetStreamFilterBuffer(); - command('db:create foobar --ext db'); + command('db:create database --ext db'); $this->assertStringContainsString('already exists.', $this->getBuffer()); } @@ -98,10 +94,10 @@ public function testOtherDriverDuplicatedDatabase(): void $this->markTestSkipped('Needs to run on non-SQLite3 and non-OCI8 drivers.'); } - command('db:create foobar'); + command('db:create database'); $this->resetStreamFilterBuffer(); - command('db:create foobar'); + command('db:create database'); $this->assertStringContainsString('Unable to create the specified database.', $this->getBuffer()); } } diff --git a/tests/system/Commands/Database/MigrateStatusTest.php b/tests/system/Commands/Database/MigrateStatusTest.php index b08557790de0..c9d9b20cc489 100644 --- a/tests/system/Commands/Database/MigrateStatusTest.php +++ b/tests/system/Commands/Database/MigrateStatusTest.php @@ -15,6 +15,7 @@ use CodeIgniter\CLI\CLI; use CodeIgniter\Test\CIUnitTestCase; +use CodeIgniter\Test\DatabaseTestTrait; use CodeIgniter\Test\StreamFilterTrait; use Config\Database; use PHPUnit\Framework\Attributes\Group; @@ -26,17 +27,18 @@ final class MigrateStatusTest extends CIUnitTestCase { use StreamFilterTrait; + use DatabaseTestTrait; private string $migrationFileFrom = SUPPORTPATH . 'MigrationTestMigrations/Database/Migrations/2018-01-24-102301_Some_migration.php'; private string $migrationFileTo = APPPATH . 'Database/Migrations/2018-01-24-102301_Some_migration.php'; protected function setUp(): void { - $forge = Database::forge(); - $forge->dropTable('foo', true); - parent::setUp(); + Database::connect()->table('migrations')->emptyTable(); + Database::forge()->dropTable('foo', true); + if (! is_file($this->migrationFileFrom)) { $this->fail(clean_path($this->migrationFileFrom) . ' is not found.'); } @@ -63,8 +65,7 @@ protected function tearDown(): void { parent::tearDown(); - $db = db_connect(); - $db->table('migrations')->emptyTable(); + Database::connect()->table('migrations')->emptyTable(); if (is_file($this->migrationFileTo)) { @unlink($this->migrationFileTo);