Skip to content

Commit a4329dd

Browse files
committed
test: fix invalid prepared query
1 parent 5beb33b commit a4329dd

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

‎tests/system/Database/Live/PreparedQueryTest.php‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ final class PreparedQueryTest extends CIUnitTestCase
3232
protected function setUp(): void
3333
{
3434
parent::setUp();
35+
3536
$this->query = null;
3637
}
3738

@@ -47,26 +48,27 @@ protected function tearDown(): void
4748
public function testPrepareReturnsPreparedQuery()
4849
{
4950
$this->query = $this->db->prepare(static fn ($db) => $db->table('user')->insert([
50-
'name' => 'a',
51-
'email' => 'b@example.com',
51+
'name' => 'a',
52+
'email' => 'b@example.com',
53+
'country' => 'JP',
5254
]));
5355

5456
$this->assertInstanceOf(BasePreparedQuery::class, $this->query);
5557

5658
$ec = $this->db->escapeChar;
5759
$pre = $this->db->DBPrefix;
5860

59-
$placeholders = '?, ?';
61+
$placeholders = '?, ?, ?';
6062

6163
if ($this->db->DBDriver === 'Postgre') {
62-
$placeholders = '$1, $2';
64+
$placeholders = '$1, $2, $3';
6365
}
6466

6567
if ($this->db->DBDriver === 'SQLSRV') {
6668
$database = $this->db->getDatabase();
67-
$expected = "INSERT INTO {$ec}{$database}{$ec}.{$ec}{$this->db->schema}{$ec}.{$ec}{$pre}user{$ec} ({$ec}name{$ec},{$ec}email{$ec}) VALUES ({$placeholders})";
69+
$expected = "INSERT INTO {$ec}{$database}{$ec}.{$ec}{$this->db->schema}{$ec}.{$ec}{$pre}user{$ec} ({$ec}name{$ec},{$ec}email{$ec},{$ec}country{$ec}) VALUES ({$placeholders})";
6870
} else {
69-
$expected = "INSERT INTO {$ec}{$pre}user{$ec} ({$ec}name{$ec}, {$ec}email{$ec}) VALUES ({$placeholders})";
71+
$expected = "INSERT INTO {$ec}{$pre}user{$ec} ({$ec}name{$ec}, {$ec}email{$ec}, {$ec}country{$ec}) VALUES ({$placeholders})";
7072
}
7173

7274
$this->assertSame($expected, $this->query->getQueryString());

0 commit comments

Comments
 (0)