Skip to content

fix: DatabaseLive tests failing locally #9669

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions tests/_support/Config/Registrar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
22 changes: 9 additions & 13 deletions tests/system/Commands/CreateDatabaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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');
}
}

Expand All @@ -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());
}

Expand All @@ -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());
}

Expand All @@ -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());
}
}
11 changes: 6 additions & 5 deletions tests/system/Commands/Database/MigrateStatusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.');
}
Expand All @@ -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);
Expand Down
Loading