Skip to content

Commit ff9b257

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

File tree

2 files changed

+22
-54
lines changed

2 files changed

+22
-54
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 & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Tpetry\PostgresqlEnhanced\Tests\Query;
66

7-
use Illuminate\Support\Facades\App;
87
use Tpetry\PostgresqlEnhanced\Tests\TestCase;
98

109
class WhereTest extends TestCase
@@ -99,19 +98,10 @@ public function testOrWhereLike(): void
9998
$this->getConnection()->table('example')->orWhereLike('str', 'ZsbBUJmR')->orWhereLike('str', '7Cc1Uf8t')->get();
10099
$this->getConnection()->table('example')->orWhereLike('str', 'OamekKIC', true)->orWhereLike('str', 'HmC3xURl', true)->get();
101100
});
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-
101+
$this->assertEquals(
102+
['select * from "example" where "str"::text ilike ? or "str"::text ilike ?', 'select * from "example" where "str"::text like ? or "str"::text like ?'],
103+
array_column($queries, 'query'),
104+
);
115105
$this->assertEquals(
116106
[['ZsbBUJmR', '7Cc1Uf8t'], ['OamekKIC', 'HmC3xURl']],
117107
array_column($queries, 'bindings'),
@@ -190,19 +180,10 @@ public function testOrWhereNotLike(): void
190180
$this->getConnection()->table('example')->orWhereNotLike('str', 'ZsbBUJmR')->orWhereNotLike('str', '7Cc1Uf8t')->get();
191181
$this->getConnection()->table('example')->orWhereNotLike('str', 'OamekKIC', true)->orWhereNotLike('str', 'HmC3xURl', true)->get();
192182
});
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-
183+
$this->assertEquals(
184+
['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 ?'],
185+
array_column($queries, 'query'),
186+
);
206187
$this->assertEquals(
207188
[['ZsbBUJmR', '7Cc1Uf8t'], ['OamekKIC', 'HmC3xURl']],
208189
array_column($queries, 'bindings'),
@@ -294,19 +275,10 @@ public function testWhereLike(): void
294275
$this->getConnection()->table('example')->whereLike('str', 'UkAymQlg')->get();
295276
$this->getConnection()->table('example')->whereLike('str', 'IcuC5Cqz', true)->get();
296277
});
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-
278+
$this->assertEquals(
279+
['select * from "example" where "str"::text ilike ?', 'select * from "example" where "str"::text like ?'],
280+
array_column($queries, 'query'),
281+
);
310282
$this->assertEquals(
311283
[['UkAymQlg'], ['IcuC5Cqz']],
312284
array_column($queries, 'bindings'),
@@ -385,19 +357,10 @@ public function testWhereNotLike(): void
385357
$this->getConnection()->table('example')->whereNotLike('str', 'UkAymQlg')->get();
386358
$this->getConnection()->table('example')->whereNotLike('str', 'IcuC5Cqz', true)->get();
387359
});
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-
360+
$this->assertEquals(
361+
['select * from "example" where "str"::text not ilike ?', 'select * from "example" where "str"::text not like ?'],
362+
array_column($queries, 'query'),
363+
);
401364
$this->assertEquals(
402365
[['UkAymQlg'], ['IcuC5Cqz']],
403366
array_column($queries, 'bindings'),

0 commit comments

Comments
 (0)