Skip to content

Commit d938267

Browse files
committed
test(database): assert condition regression binds
Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
1 parent fe0e605 commit d938267

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

system/Database/BaseBuilder.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,6 +1120,7 @@ protected function whereHaving(string $qbKey, $key, $value = null, string $type
11201120
/**
11211121
* @param 'QBHaving'|'QBWhere' $clause
11221122
* @param array<string, mixed> $condition
1123+
* @param non-empty-string $type
11231124
*/
11241125
private function addWhereHavingCondition(string $clause, array $condition, string $type): void
11251126
{

tests/system/Database/Builder/WhereTest.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,20 +152,22 @@ public function testWhereLikeInAssociateArray(): void
152152
}
153153

154154
/**
155-
* @param mixed $value
155+
* @param mixed $value
156+
* @param array<string, array{mixed, bool}> $expectedBinds
156157
*/
157158
#[DataProvider('provideWhereOperatorRegressionCases')]
158-
public function testWhereOperatorRegressionCases(string $key, $value, string $expectedSQL): void
159+
public function testWhereOperatorRegressionCases(string $key, $value, string $expectedSQL, array $expectedBinds): void
159160
{
160161
$builder = $this->db->table('jobs job');
161162

162163
$builder->where($key, $value);
163164

164165
$this->assertSame($expectedSQL, str_replace("\n", ' ', $builder->getCompiledSelect()));
166+
$this->assertSame($expectedBinds, $builder->getBinds());
165167
}
166168

167169
/**
168-
* @return iterable<string, array{string, mixed, string}>
170+
* @return iterable<string, array{string, mixed, string, array<string, array{mixed, bool}>}>
169171
*/
170172
public static function provideWhereOperatorRegressionCases(): iterable
171173
{
@@ -174,16 +176,24 @@ public static function provideWhereOperatorRegressionCases(): iterable
174176
'job.status LIKE',
175177
'p%',
176178
'SELECT * FROM "jobs" "job" WHERE "job"."status" LIKE \'p%\'',
179+
[
180+
'job.status' => [
181+
'p%',
182+
true,
183+
],
184+
],
177185
],
178186
'equals operator with null' => [
179187
'job.deleted_at =',
180188
null,
181189
'SELECT * FROM "jobs" "job" WHERE "job"."deleted_at" IS NULL',
190+
[],
182191
],
183192
'not equals operator with null' => [
184193
'job.deleted_at !=',
185194
null,
186195
'SELECT * FROM "jobs" "job" WHERE "job"."deleted_at" IS NOT NULL',
196+
[],
187197
],
188198
];
189199
}

0 commit comments

Comments
 (0)