Skip to content

Commit 873c932

Browse files
committed
test: ensure cleanup of sqlite3 db files after test
1 parent 7b7e63c commit 873c932

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

tests/system/Database/Live/SQLite/GetIndexDataTest.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,32 @@ final class GetIndexDataTest extends CIUnitTestCase
4141

4242
private Forge $forge;
4343

44+
/**
45+
* @var array{DBDriver: string, database: string, DBDebug: bool}
46+
*/
47+
private array $config = [];
48+
4449
protected function setUp(): void
4550
{
4651
parent::setUp();
4752

48-
$config = [
53+
$this->config = [
4954
'DBDriver' => 'SQLite3',
50-
'database' => 'database.db',
55+
'database' => WRITEPATH . 'database.db',
5156
'DBDebug' => true,
5257
];
5358

54-
$this->db = db_connect($config);
55-
$this->forge = Database::forge($config);
59+
$this->db = db_connect($this->config);
60+
$this->forge = Database::forge($this->config);
61+
}
62+
63+
protected function tearDown(): void
64+
{
65+
parent::tearDown();
66+
67+
if (is_file($this->config['database'])) {
68+
unlink($this->config['database']);
69+
}
5670
}
5771

5872
public function testGetIndexData(): void

tests/system/Database/Migrations/MigrationRunnerTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,10 @@ public function testMigrationUsesSameConnectionAsMigrationRunner(): void
470470
$this->assertCount(2, $tables);
471471
$this->assertSame('migrations', $tables[0]);
472472
$this->assertSame('foo', $tables[1]);
473+
474+
if (is_file($config['database'])) {
475+
unlink($config['database']);
476+
}
473477
}
474478

475479
protected function resetTables($db = null): void

0 commit comments

Comments
 (0)