Skip to content

Commit

Permalink
Fix styling
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexVanderbist authored and github-actions[bot] committed May 10, 2024
1 parent 769f3c4 commit cf51acb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/Filters/FiltersPartial.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ private static function escapeLike(string $value): string

private static function maybeSpecifyEscapeChar(): string
{
if(!in_array(DB::getDriverName(), ["sqlite","pgsql","sqlsrv"])){
if(! in_array(DB::getDriverName(), ["sqlite","pgsql","sqlsrv"])) {
return "";
}

return " ESCAPE '\'";
return " ESCAPE '\'";
}
}
9 changes: 5 additions & 4 deletions tests/FilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Support\Facades\DB;

use Pest\Expectation;

use function PHPUnit\Framework\assertObjectHasProperty;

use Spatie\QueryBuilder\AllowedFilter;
Expand Down Expand Up @@ -92,13 +93,13 @@

it('specifies escape character in supported databases', function (string $dbDriver) {
$fakeConnection = "test_{$dbDriver}";

DB::connectUsing($fakeConnection, [
'driver' => $dbDriver,
'database' => null,
]);

DB::usingConnection($fakeConnection, function() use ($dbDriver){
DB::usingConnection($fakeConnection, function () use ($dbDriver) {
$request = new Request([
'filter' => ['name' => 'to_find'],
]);
Expand All @@ -107,8 +108,8 @@
->allowedFilters('name', 'id')
->toSql();

expect($queryBuilderSql)->when(in_array($dbDriver, ["sqlite","pgsql","sqlsrv"]), fn(Expectation $query) => $query->toContain("ESCAPE '\'"));
expect($queryBuilderSql)->when($dbDriver === 'mysql', fn(Expectation $query) => $query->not->toContain("ESCAPE '\'"));
expect($queryBuilderSql)->when(in_array($dbDriver, ["sqlite","pgsql","sqlsrv"]), fn (Expectation $query) => $query->toContain("ESCAPE '\'"));
expect($queryBuilderSql)->when($dbDriver === 'mysql', fn (Expectation $query) => $query->not->toContain("ESCAPE '\'"));
});
})->with(['sqlite', 'mysql', 'pgsql', 'sqlsrv']);

Expand Down

0 comments on commit cf51acb

Please sign in to comment.