Skip to content

Commit 6791a9d

Browse files
committed
test: add test for deallocation of prepared query
1 parent 3a0d072 commit 6791a9d

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\Exceptions\DatabaseException;
1617
use CodeIgniter\Database\Query;
@@ -148,4 +149,26 @@ public function testExecuteRunsInvalidQuery()
148149

149150
$this->query->execute('foo', '[email protected]', 'US');
150151
}
152+
153+
public function testDeallocatePreparedQuery()
154+
{
155+
$this->query = $this->db->prepare(static fn ($db) => $db->table('user')->insert([
156+
'name' => 'a',
157+
'email' => '[email protected]',
158+
'country' => 'x',
159+
]));
160+
161+
$this->query->execute('foo', '[email protected]', 'US');
162+
163+
$this->query->close();
164+
165+
try {
166+
$this->query->execute('bar', '[email protected]', 'GB');
167+
} catch (BadMethodCallException $e) {
168+
$this->assertSame('You must call prepare before trying to execute a prepared statement.', $e->getMessage());
169+
}
170+
171+
$this->seeInDatabase($this->db->DBPrefix . 'user', ['name' => 'foo', 'email' => '[email protected]']);
172+
$this->dontSeeInDatabase($this->db->DBPrefix . 'user', ['name' => 'bar', 'email' => '[email protected]']);
173+
}
151174
}

0 commit comments

Comments
 (0)