Skip to content

Commit 4f93f76

Browse files
mmachatschekMarkus Machatschek
authored andcommitted
chore: align queries with laravel 11.17+ behaviour
1 parent 4e64ea3 commit 4f93f76

File tree

2 files changed

+22
-53
lines changed

2 files changed

+22
-53
lines changed

src/Query/GrammarWhere.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,12 @@ public function whereLike(Builder $query, $where): string
5858
$operator = $where['not'] ? 'not ' : '';
5959
$operator .= $where['caseSensitive'] ? 'like' : 'ilike';
6060

61-
return "{$this->wrap($where['column'])} {$operator} {$this->parameter($where['value'])}";
61+
return sprintf(
62+
'%s::text %s %s',
63+
$this->wrap($where['column']),
64+
$operator,
65+
$this->parameter($where['value']),
66+
);
6267
}
6368

6469
/**

tests/Query/WhereTest.php

Lines changed: 16 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,10 @@ public function testOrWhereLike(): void
9999
$this->getConnection()->table('example')->orWhereLike('str', 'ZsbBUJmR')->orWhereLike('str', '7Cc1Uf8t')->get();
100100
$this->getConnection()->table('example')->orWhereLike('str', 'OamekKIC', true)->orWhereLike('str', 'HmC3xURl', true)->get();
101101
});
102-
103-
if (version_compare(App::version(), '11.17.0', '>=')) {
104-
$this->assertEquals(
105-
['select * from "example" where "str"::text ilike ? or "str"::text ilike ?', 'select * from "example" where "str"::text like ? or "str"::text like ?'],
106-
array_column($queries, 'query'),
107-
);
108-
} else {
109-
$this->assertEquals(
110-
['select * from "example" where "str" ilike ? or "str" ilike ?', 'select * from "example" where "str" like ? or "str" like ?'],
111-
array_column($queries, 'query'),
112-
);
113-
}
114-
102+
$this->assertEquals(
103+
['select * from "example" where "str"::text ilike ? or "str"::text ilike ?', 'select * from "example" where "str"::text like ? or "str"::text like ?'],
104+
array_column($queries, 'query'),
105+
);
115106
$this->assertEquals(
116107
[['ZsbBUJmR', '7Cc1Uf8t'], ['OamekKIC', 'HmC3xURl']],
117108
array_column($queries, 'bindings'),
@@ -190,19 +181,10 @@ public function testOrWhereNotLike(): void
190181
$this->getConnection()->table('example')->orWhereNotLike('str', 'ZsbBUJmR')->orWhereNotLike('str', '7Cc1Uf8t')->get();
191182
$this->getConnection()->table('example')->orWhereNotLike('str', 'OamekKIC', true)->orWhereNotLike('str', 'HmC3xURl', true)->get();
192183
});
193-
194-
if (version_compare(App::version(), '11.17.0', '>=')) {
195-
$this->assertEquals(
196-
['select * from "example" where "str"::text not ilike ? or "str"::text not ilike ?', 'select * from "example" where "str"::text not like ? or "str"::text not like ?'],
197-
array_column($queries, 'query'),
198-
);
199-
} else {
200-
$this->assertEquals(
201-
['select * from "example" where "str" not ilike ? or "str" not ilike ?', 'select * from "example" where "str" not like ? or "str" not like ?'],
202-
array_column($queries, 'query'),
203-
);
204-
}
205-
184+
$this->assertEquals(
185+
['select * from "example" where "str"::text not ilike ? or "str"::text not ilike ?', 'select * from "example" where "str"::text not like ? or "str"::text not like ?'],
186+
array_column($queries, 'query'),
187+
);
206188
$this->assertEquals(
207189
[['ZsbBUJmR', '7Cc1Uf8t'], ['OamekKIC', 'HmC3xURl']],
208190
array_column($queries, 'bindings'),
@@ -294,19 +276,10 @@ public function testWhereLike(): void
294276
$this->getConnection()->table('example')->whereLike('str', 'UkAymQlg')->get();
295277
$this->getConnection()->table('example')->whereLike('str', 'IcuC5Cqz', true)->get();
296278
});
297-
298-
if (version_compare(App::version(), '11.17.0', '>=')) {
299-
$this->assertEquals(
300-
['select * from "example" where "str"::text ilike ?', 'select * from "example" where "str"::text like ?'],
301-
array_column($queries, 'query'),
302-
);
303-
} else {
304-
$this->assertEquals(
305-
['select * from "example" where "str" ilike ?', 'select * from "example" where "str" like ?'],
306-
array_column($queries, 'query'),
307-
);
308-
}
309-
279+
$this->assertEquals(
280+
['select * from "example" where "str"::text ilike ?', 'select * from "example" where "str"::text like ?'],
281+
array_column($queries, 'query'),
282+
);
310283
$this->assertEquals(
311284
[['UkAymQlg'], ['IcuC5Cqz']],
312285
array_column($queries, 'bindings'),
@@ -385,19 +358,10 @@ public function testWhereNotLike(): void
385358
$this->getConnection()->table('example')->whereNotLike('str', 'UkAymQlg')->get();
386359
$this->getConnection()->table('example')->whereNotLike('str', 'IcuC5Cqz', true)->get();
387360
});
388-
389-
if (version_compare(App::version(), '11.17.0', '>=')) {
390-
$this->assertEquals(
391-
['select * from "example" where "str"::text not ilike ?', 'select * from "example" where "str"::text not like ?'],
392-
array_column($queries, 'query'),
393-
);
394-
} else {
395-
$this->assertEquals(
396-
['select * from "example" where "str" not ilike ?', 'select * from "example" where "str" not like ?'],
397-
array_column($queries, 'query'),
398-
);
399-
}
400-
361+
$this->assertEquals(
362+
['select * from "example" where "str"::text not ilike ?', 'select * from "example" where "str"::text not like ?'],
363+
array_column($queries, 'query'),
364+
);
401365
$this->assertEquals(
402366
[['UkAymQlg'], ['IcuC5Cqz']],
403367
array_column($queries, 'bindings'),

0 commit comments

Comments
 (0)