Skip to content

Commit

Permalink
fix some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
abbasudo committed Jun 4, 2024
1 parent 180b167 commit 443952c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/Filters/Strategies/ContainsCaseSensitiveFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function apply(): Closure
$query->whereRaw("`{$this->column}` COLLATE BINARY like ?", ["%{$value}%"]);
break;
case 'pgsql':
$query->whereRaw("`{$this->column}`::bytea LIKE ?", ["%{$value}%"]);
$query->where($this->column, 'LIKE', "%{$value}%");
break;
case 'sqlsrv':
$query->whereRaw("`{$this->column}` COLLATE Latin1_General_BIN LIKE ?", ["%{$value}%"]);
Expand Down
8 changes: 4 additions & 4 deletions src/Filters/Strategies/EndsWithCaseSensitiveFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ public function apply(): Closure
foreach ($this->values as $value) {
switch ($connection) {
case 'mysql':
$query->whereRaw("BINARY `{$this->column}` like ?", '%'.$value);
$query->whereRaw("BINARY `{$this->column}` like ?", '%' . $value);
break;
case 'sqlite':
$query->whereRaw("`{$this->column}` COLLATE BINARY like ?", '%'.$value);
$query->whereRaw("`{$this->column}` COLLATE BINARY like ?", '%' . $value);
break;
case 'pgsql':
$query->whereRaw("`{$this->column}` LIKE ?", '%'.$value);
$query->where($this->column, 'LIKE', '%' . $value);
break;
case 'sqlsrv':
$query->whereRaw("`{$this->column}` COLLATE Latin1_General_BIN LIKE ?", '%'.$value);
$query->whereRaw("`{$this->column}` COLLATE Latin1_General_BIN LIKE ?", '%' . $value);
break;
default:
throw new RuntimeException("Unsupported database driver: {$connection}");
Expand Down
2 changes: 1 addition & 1 deletion src/Filters/Strategies/NotContainsSensitiveFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function apply(): Closure
$query->whereRaw("`{$this->column}` COLLATE BINARY not like ?", ["%{$value}%"]);
break;
case 'pgsql':
$query->whereRaw("`{$this->column}` not LIKE ?", ["%{$value}%"]);
$query->whereNot($this->column, 'LIKE', "%{$value}%");
break;
case 'sqlsrv':
$query->whereRaw("`{$this->column}` COLLATE Latin1_General_BIN not LIKE ?", ["%{$value}%"]);
Expand Down
8 changes: 4 additions & 4 deletions src/Filters/Strategies/StartsWithCaseSensitiveFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ public function apply(): Closure
foreach ($this->values as $value) {
switch ($connection) {
case 'mysql':
$query->whereRaw("BINARY `{$this->column}` like ?", $value.'%');
$query->whereRaw("BINARY `{$this->column}` like ?", $value . '%');
break;
case 'sqlite':
$query->whereRaw("`{$this->column}` COLLATE BINARY like ?", $value.'%');
$query->whereRaw("`{$this->column}` COLLATE BINARY like ?", $value . '%');
break;
case 'pgsql':
$query->whereRaw("`{$this->column}` LIKE ?", $value.'%');
$query->where($this->column, 'LIKE', $value . '%');
break;
case 'sqlsrv':
$query->whereRaw("`{$this->column}` COLLATE Latin1_General_BIN LIKE ?", $value.'%');
$query->whereRaw("`{$this->column}` COLLATE Latin1_General_BIN LIKE ?", $value . '%');
break;
default:
throw new RuntimeException("Unsupported database driver: {$connection}");
Expand Down
4 changes: 2 additions & 2 deletions tests/Feature/FilterableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ public function it_can_filter_with_notIn_operator(): void
/** @test */
public function it_can_filter_with_contains_operator(): void
{
$response = $this->getJson('/posts?filters[title][$contains]=LARAVEL');
$response = $this->getJson('/posts?filters[title][$contains]=laravel');

$response->assertOk();
$response->assertJsonCount(1);
Expand All @@ -289,7 +289,7 @@ public function it_can_filter_with_notContains_operator(): void
/** @test */
public function it_can_filter_with_containsc_operator(): void
{
$response = $this->getJson('/posts?filters[title][$containsc]=lara');
$response = $this->getJson('/posts?filters[title][$containsc]=laravel');
$response->assertOk();
$response->assertJsonCount(1);
}
Expand Down

0 comments on commit 443952c

Please sign in to comment.