Just posting this in case anyone comes across this post and is interested in using whereJsonContains and not blowing out their sqlite testing configuration.
You can specify a custom grammar for the connection and add support for JSON_CONTAINS method like so:
class PatchedSQLiteGrammar extends SQLiteGrammar
{
public function __construct()
{
DB::connection()->getPdo()->sqliteCreateFunction('JSON_CONTAINS', function ($json, $val, $path = null) {
$array = json_decode($json, true, 512, JSON_THROW_ON_ERROR);
$val = trim($val, '"');
if ($path) {
return $array[$path] == $val;
}
return in_array($val, $array, true);
});
}
protected function compileJsonContains($column, $value)
{
[$field, $path] = $this->wrapJsonFieldAndPath($column);
return 'json_contains('.$field.', '.$value.$path.')';
}
}
And in the setup method of your test suite, you can swap the grammar out:
app('db.connection')->setQueryGrammar(new PatchedSQLiteGrammar());