Skip to content

Commit c2d9440

Browse files
authored
fix: DatabaseLive tests failing locally (#9669)
* replicate error in GitHub Actions * add fix * rename tested db to `database` to coincide with other tests' db name * revert 1st commit
1 parent 076e882 commit c2d9440

File tree

3 files changed

+18
-21
lines changed

3 files changed

+18
-21
lines changed

tests/_support/Config/Registrar.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,9 @@ public static function Database(): array
134134

135135
// Under GitHub Actions, we can set an ENV var named 'DB'
136136
// so that we can test against multiple databases.
137-
if (($group = getenv('DB')) && isset(self::$dbConfig[$group])) {
138-
$config['tests'] = self::$dbConfig[$group];
139-
}
137+
$group = env('DB', 'SQLite3');
138+
139+
$config['tests'] = self::$dbConfig[$group] ?? [];
140140

141141
return $config;
142142
}

tests/system/Commands/CreateDatabaseTest.php

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
namespace CodeIgniter\Commands;
1515

1616
use CodeIgniter\Database\BaseConnection;
17-
use CodeIgniter\Database\Database as DatabaseFactory;
1817
use CodeIgniter\Database\OCI8\Connection as OCI8Connection;
1918
use CodeIgniter\Database\SQLite3\Connection as SQLite3Connection;
2019
use CodeIgniter\Test\CIUnitTestCase;
@@ -51,16 +50,13 @@ protected function tearDown(): void
5150
private function dropDatabase(): void
5251
{
5352
if ($this->connection instanceof SQLite3Connection) {
54-
$file = WRITEPATH . 'foobar.db';
53+
$file = WRITEPATH . 'database.db';
54+
5555
if (is_file($file)) {
5656
unlink($file);
5757
}
58-
} else {
59-
$util = (new DatabaseFactory())->loadUtils($this->connection);
60-
61-
if ($util->databaseExists('foobar')) {
62-
Database::forge()->dropDatabase('foobar');
63-
}
58+
} elseif (Database::utils('tests')->databaseExists('database')) {
59+
Database::forge()->dropDatabase('database');
6460
}
6561
}
6662

@@ -75,7 +71,7 @@ public function testCreateDatabase(): void
7571
$this->markTestSkipped('Needs to run on non-OCI8 drivers.');
7672
}
7773

78-
command('db:create foobar');
74+
command('db:create database');
7975
$this->assertStringContainsString('successfully created.', $this->getBuffer());
8076
}
8177

@@ -85,10 +81,10 @@ public function testSqliteDatabaseDuplicated(): void
8581
$this->markTestSkipped('Needs to run on SQLite3.');
8682
}
8783

88-
command('db:create foobar');
84+
command('db:create database');
8985
$this->resetStreamFilterBuffer();
9086

91-
command('db:create foobar --ext db');
87+
command('db:create database --ext db');
9288
$this->assertStringContainsString('already exists.', $this->getBuffer());
9389
}
9490

@@ -98,10 +94,10 @@ public function testOtherDriverDuplicatedDatabase(): void
9894
$this->markTestSkipped('Needs to run on non-SQLite3 and non-OCI8 drivers.');
9995
}
10096

101-
command('db:create foobar');
97+
command('db:create database');
10298
$this->resetStreamFilterBuffer();
10399

104-
command('db:create foobar');
100+
command('db:create database');
105101
$this->assertStringContainsString('Unable to create the specified database.', $this->getBuffer());
106102
}
107103
}

tests/system/Commands/Database/MigrateStatusTest.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
use CodeIgniter\CLI\CLI;
1717
use CodeIgniter\Test\CIUnitTestCase;
18+
use CodeIgniter\Test\DatabaseTestTrait;
1819
use CodeIgniter\Test\StreamFilterTrait;
1920
use Config\Database;
2021
use PHPUnit\Framework\Attributes\Group;
@@ -26,17 +27,18 @@
2627
final class MigrateStatusTest extends CIUnitTestCase
2728
{
2829
use StreamFilterTrait;
30+
use DatabaseTestTrait;
2931

3032
private string $migrationFileFrom = SUPPORTPATH . 'MigrationTestMigrations/Database/Migrations/2018-01-24-102301_Some_migration.php';
3133
private string $migrationFileTo = APPPATH . 'Database/Migrations/2018-01-24-102301_Some_migration.php';
3234

3335
protected function setUp(): void
3436
{
35-
$forge = Database::forge();
36-
$forge->dropTable('foo', true);
37-
3837
parent::setUp();
3938

39+
Database::connect()->table('migrations')->emptyTable();
40+
Database::forge()->dropTable('foo', true);
41+
4042
if (! is_file($this->migrationFileFrom)) {
4143
$this->fail(clean_path($this->migrationFileFrom) . ' is not found.');
4244
}
@@ -63,8 +65,7 @@ protected function tearDown(): void
6365
{
6466
parent::tearDown();
6567

66-
$db = db_connect();
67-
$db->table('migrations')->emptyTable();
68+
Database::connect()->table('migrations')->emptyTable();
6869

6970
if (is_file($this->migrationFileTo)) {
7071
@unlink($this->migrationFileTo);

0 commit comments

Comments
 (0)