Skip to content

Commit

Permalink
test: ensure cleanup of sqlite3 db files after test
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbalandan committed Jan 29, 2024
1 parent 9200417 commit 84134b8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion tests/system/Database/Live/SQLite3/AlterTableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected function setUp(): void
'database' => ':memory:',
'DBDebug' => true,
];
$this->db = db_connect($config);
$this->db = db_connect($config, false);
$this->forge = Database::forge($config);
$this->table = new Table($this->db, $this->forge);

Expand Down
11 changes: 10 additions & 1 deletion tests/system/Database/Live/SQLite3/GetFieldDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,19 @@ protected function createForge(): void
'database' => 'database.db',
'DBDebug' => true,
];
$this->db = db_connect($config);
$this->db = db_connect($config, false);
$this->forge = Database::forge($config);
}

protected function tearDown(): void
{
parent::tearDown();

if (is_file(WRITEPATH . 'database.db')) {
unlink(WRITEPATH . 'database.db');
}
}

public function testGetFieldData(): void
{
$fields = $this->db->getFieldData('test1');
Expand Down
11 changes: 10 additions & 1 deletion tests/system/Database/Live/SQLite3/GetIndexDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,19 @@ protected function setUp(): void
'database' => 'database.db',
'DBDebug' => true,
];
$this->db = db_connect($config);
$this->db = db_connect($config, false);
$this->forge = Database::forge($config);
}

protected function tearDown(): void
{
parent::tearDown();

if (is_file(WRITEPATH . 'database.db')) {
unlink(WRITEPATH . 'database.db');
}
}

public function testGetIndexData(): void
{
// INTEGER PRIMARY KEY AUTO_INCREMENT doesn't get an index by default
Expand Down
4 changes: 4 additions & 0 deletions tests/system/Database/Migrations/MigrationRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,10 @@ public function testMigrationUsesSameConnectionAsMigrationRunner(): void
$this->assertCount(2, $tables);
$this->assertSame('migrations', $tables[0]);
$this->assertSame('foo', $tables[1]);

if (is_file($config['database'])) {
unlink($config['database']);
}
}

protected function resetTables($db = null): void
Expand Down

0 comments on commit 84134b8

Please sign in to comment.