Skip to content

Commit 741d488

Browse files
authored
Merge pull request #5244 from kenjis/fix-test-CreateDatabaseTest
Fix CreateDatabaseTest::testCreateDatabase()
2 parents 9a39199 + d7c9ad2 commit 741d488

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

tests/system/Commands/CreateDatabaseTest.php

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
namespace CodeIgniter\Commands;
1313

1414
use CodeIgniter\Database\BaseConnection;
15-
use CodeIgniter\Database\SQLite3\Connection;
15+
use CodeIgniter\Database\Database as DatabaseFactory;
16+
use CodeIgniter\Database\SQLite3\Connection as SQLite3Connection;
1617
use CodeIgniter\Test\CIUnitTestCase;
1718
use CodeIgniter\Test\Filters\CITestStreamFilter;
1819
use Config\Database;
@@ -38,21 +39,24 @@ protected function setUp(): void
3839
$this->connection = Database::connect();
3940

4041
parent::setUp();
41-
}
4242

43-
protected function tearDown(): void
44-
{
45-
stream_filter_remove($this->streamFilter);
46-
47-
if ($this->connection instanceof Connection) {
43+
if ($this->connection instanceof SQLite3Connection) {
4844
$file = WRITEPATH . 'foobar.db';
49-
5045
if (file_exists($file)) {
5146
unlink($file);
5247
}
5348
} else {
54-
Database::forge()->dropDatabase('foobar');
49+
$util = (new DatabaseFactory())->loadUtils($this->connection);
50+
51+
if ($util->databaseExists('foobar')) {
52+
Database::forge()->dropDatabase('foobar');
53+
}
5554
}
55+
}
56+
57+
protected function tearDown(): void
58+
{
59+
stream_filter_remove($this->streamFilter);
5660

5761
parent::tearDown();
5862
}
@@ -70,7 +74,7 @@ public function testCreateDatabase()
7074

7175
public function testSqliteDatabaseDuplicated()
7276
{
73-
if (! $this->connection instanceof Connection) {
77+
if (! $this->connection instanceof SQLite3Connection) {
7478
$this->markTestSkipped('Needs to run on SQLite3.');
7579
}
7680

@@ -83,7 +87,7 @@ public function testSqliteDatabaseDuplicated()
8387

8488
public function testOtherDriverDuplicatedDatabase()
8589
{
86-
if ($this->connection instanceof Connection) {
90+
if ($this->connection instanceof SQLite3Connection) {
8791
$this->markTestSkipped('Needs to run on non-SQLite3 drivers.');
8892
}
8993

0 commit comments

Comments
 (0)