Skip to content

Commit 114a6a6

Browse files
committed
Add proper cleanup in test teardown
Added a tearDown() function to the SqlQueryInterceptModuleTest, SqlQueryModuleTest, and SqlQueryTest classes. This method takes care of appropriately cleaning up the SQLite connection after each test, preventing potential issues related to connection leakage.
1 parent e70ecfb commit 114a6a6

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

tests/SqlQueryInterceptModuleTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414

1515
class SqlQueryInterceptModuleTest extends TestCase
1616
{
17+
/** @var ExtendedPdo */
18+
private $pdo;
19+
1720
/** @var FakeRo */
1821
private $fakeRo;
1922

@@ -45,11 +48,19 @@ protected function configure()
4548
$this->bind(FakeBar::class);
4649
}
4750
};
51+
$this->pdo = $pdo;
4852
$injector = new Injector($module, __DIR__ . '/tmp');
4953
$this->fakeRo = $injector->getInstance(FakeRo::class);
5054
$this->fakeBar = $injector->getInstance(FakeBar::class);
5155
}
5256

57+
protected function tearDown(): void
58+
{
59+
unset($this->pdo); // This effectively closes the SQLite connection
60+
61+
parent::tearDown();
62+
}
63+
5364
public function testResourceObject200(): void
5465
{
5566
$response = $this->fakeRo->onGet('1');

tests/SqlQueryModuleTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@
1919

2020
class SqlQueryModuleTest extends TestCase
2121
{
22+
/** @var ExtendedPdo */
23+
private $pdo;
24+
2225
/** @var AbstractModule */
2326
private $module;
27+
2428
protected function setUp(): void
2529
{
2630
$pdo = new ExtendedPdo('sqlite::memory:');
@@ -45,6 +49,14 @@ protected function configure()
4549
$this->install(new SqlQueryModule(__DIR__ . '/Fake/sql'));
4650
}
4751
};
52+
$this->pdo = $pdo;
53+
}
54+
55+
protected function tearDown(): void
56+
{
57+
unset($this->pdo); // This effectively closes the SQLite connection
58+
59+
parent::tearDown();
4860
}
4961

5062
public function testProviderInject(): void

tests/SqlQueryTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ protected function setUp(): void
2929
$this->pdo = $pdo;
3030
}
3131

32+
protected function tearDown(): void
33+
{
34+
unset($this->pdo); // This effectively closes the SQLite connection
35+
36+
parent::tearDown();
37+
}
38+
3239
public function testInvoke(): void
3340
{
3441
$sql = (string) file_get_contents(__DIR__ . '/Fake/sql/todo_item_by_id.sql');

0 commit comments

Comments
 (0)