Skip to content

Commit bd2154e

Browse files
committed
test: add test for deallocation of prepared query
1 parent 1cb7e5b commit bd2154e

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

tests/system/Database/Live/PreparedQueryTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace CodeIgniter\Database\Live;
1313

14+
use BadMethodCallException;
1415
use CodeIgniter\Database\BasePreparedQuery;
1516
use CodeIgniter\Database\Query;
1617
use CodeIgniter\Test\CIUnitTestCase;
@@ -134,4 +135,26 @@ public function testExecuteRunsQueryAndReturnsManualResultObject()
134135
$this->seeInDatabase($this->db->DBPrefix . 'user', ['name' => 'foo', 'email' => '[email protected]']);
135136
$this->seeInDatabase($this->db->DBPrefix . 'user', ['name' => 'bar', 'email' => '[email protected]']);
136137
}
138+
139+
public function testDeallocatePreparedQuery()
140+
{
141+
$this->query = $this->db->prepare(static fn ($db) => $db->table('user')->insert([
142+
'name' => 'a',
143+
'email' => '[email protected]',
144+
'country' => 'x',
145+
]));
146+
147+
$this->query->execute('foo', '[email protected]', 'US');
148+
149+
$this->query->close();
150+
151+
try {
152+
$this->query->execute('bar', '[email protected]', 'GB');
153+
} catch (BadMethodCallException $e) {
154+
$this->assertSame('You must call prepare before trying to execute a prepared statement.', $e->getMessage());
155+
}
156+
157+
$this->seeInDatabase($this->db->DBPrefix . 'user', ['name' => 'foo', 'email' => '[email protected]']);
158+
$this->dontSeeInDatabase($this->db->DBPrefix . 'user', ['name' => 'bar', 'email' => '[email protected]']);
159+
}
137160
}

0 commit comments

Comments
 (0)