Skip to content

Commit

Permalink
Fix NOT_LIKE operator in @whereConditions
Browse files Browse the repository at this point in the history
  • Loading branch information
spawnia committed Aug 4, 2023
1 parent 3504af5 commit 165eda2
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ You can find and compare releases at the [GitHub release page](https://github.co

## Unreleased

## v6.16.2

### Fixed

- Fix `NOT_LIKE` operator in `@whereConditions`

## v6.16.1

### Fixed
Expand Down
3 changes: 2 additions & 1 deletion src/WhereConditions/SQLOperator.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ enum SQLOperator {
LIKE @enum(value: "LIKE")
"Negation of simple pattern matching (`NOT LIKE`)"
NOT_LIKE @enum(value: "NOT_LIKE")
NOT_LIKE @enum(value: "NOT LIKE")
"Whether a value is within a set of values (`IN`)"
IN @enum(value: "In")
Expand Down Expand Up @@ -111,6 +111,7 @@ public function applyConditions(QueryBuilder|EloquentBuilder $builder, array $wh

// The condition methods always have the `$boolean` arg after the value
$args[] = $boolean;
// dd($method, $args);

return $builder->{$method}(...$args);
}
Expand Down
35 changes: 35 additions & 0 deletions tests/Integration/WhereConditions/WhereConditionsDirectiveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,41 @@ public function testOverwritesTheOperator(): void
')->assertJsonCount(2, 'data.users');
}

public function testOperatorNotLike(): void
{
$user1 = factory(User::class)->make();
assert($user1 instanceof User);
$user1->name = 'foo';
$user1->save();

$user2 = factory(User::class)->make();
assert($user2 instanceof User);
$user2->name = 'bar';
$user2->save();

$this->graphQL(/** @lang GraphQL */ '
{
users(
where: {
column: "name"
operator: NOT_LIKE
value: "ba%"
}
) {
id
}
}
')->assertExactJson([
'data' => [
'users' => [
[
'id' => "{$user1->id}",
],
],
],
]);
}

public function testOperatorIn(): void
{
factory(User::class, 5)->create();
Expand Down

0 comments on commit 165eda2

Please sign in to comment.