diff --git a/src/Filters/FiltersPartial.php b/src/Filters/FiltersPartial.php index 77db819c..31d77100 100644 --- a/src/Filters/FiltersPartial.php +++ b/src/Filters/FiltersPartial.php @@ -69,12 +69,12 @@ protected static function escapeLike(string $value): string } /** - * @param 'sqlite'|'pgsql'|'sqlsrc'|'mysql' $driver + * @param 'sqlite'|'pgsql'|'sqlsrc'|'mysql'|'mariadb' $driver * @return string */ protected static function maybeSpecifyEscapeChar(string $driver): string { - if (! in_array($driver, ['sqlite','pgsql','sqlsrv'])) { + if (! in_array($driver, ['sqlite','sqlsrv'])) { return ''; } diff --git a/tests/FilterTest.php b/tests/FilterTest.php index e4cea386..56486037 100644 --- a/tests/FilterTest.php +++ b/tests/FilterTest.php @@ -92,6 +92,10 @@ }); it('specifies escape character in supported databases', function (string $dbDriver) { + if ($dbDriver === 'mariadb' && ! in_array('mariadb', DB::supportedDrivers())) { + $this->markTestSkipped('mariadb driver not supported in the installed version of illuminate/database dependency'); + } + $fakeConnection = "test_{$dbDriver}"; DB::connectUsing($fakeConnection, [ @@ -100,6 +104,7 @@ ]); DB::usingConnection($fakeConnection, function () use ($dbDriver) { + $request = new Request([ 'filter' => ['name' => 'to_find'], ]); @@ -108,10 +113,10 @@ ->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","sqlsrv"]), fn (Expectation $query) => $query->toContain("ESCAPE '\'")); + expect($queryBuilderSql)->when(in_array($dbDriver, ["mysql","mariadb", "pgsql"]), fn (Expectation $query) => $query->not->toContain("ESCAPE '\'")); }); -})->with(['sqlite', 'mysql', 'pgsql', 'sqlsrv']); +})->with(['sqlite', 'mysql', 'pgsql', 'sqlsrv', 'mariadb']); it('can filter results based on the existence of a property in an array', function () { $results = createQueryFromFilterRequest([