Skip to content

Commit

Permalink
Confirmed proper functioning of whereNone/orWhereNone (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
LaravelFreelancerNL authored Nov 10, 2024
1 parent 5f36deb commit 9e1b965
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
3 changes: 2 additions & 1 deletion docs/compatibility-list.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ rightJoin / rightJoinSub / joinWhere?
where / orWhere / whereNot / orWhereNot / whereColumn / whereExists
whereBetween / whereNotBetween / whereBetweenColumns / whereNotBetweenColumns /
whereJsonContains / whereJsonLength /
whereIn / whereNotIn / whereNot / orWhereNot / whereNull / whereNotNull /
whereIn / whereNotIn / whereNone / orWhereNone / whereNot / orWhereNot /
whereNull / whereNotNull /
whereDate / whereMonth / whereDay / whereYear / whereTime /
whereRaw (use AQL) /
whereAll / orWhereAll / whereAny / orWhereAny
Expand Down
43 changes: 43 additions & 0 deletions tests/Query/WheresTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,49 @@
expect(($results->first())->name)->toBe('Stark');
});

test('whereNone', function () {
$query = \DB::table('houses')
->whereNone(['en.coat-of-arms', 'en.description'], 'LIKE', '%war%');

$binds = $query->getBindings();
$bindKeys = array_keys($binds);

$this->assertSame(
'FOR houseDoc IN houses FILTER not ( `houseDoc`.`en`.`coat-of-arms` LIKE @' . $bindKeys[0]
. ' or `houseDoc`.`en`.`description` LIKE @' . $bindKeys[1]
. ') RETURN houseDoc',
$query->toSql(),
);

$results = $query->get();
expect($results->count())->toBe(1);
expect(($results->first())->name)->toBe('Targaryen');
});

test('orWhereNone', function () {
$query = \DB::table('houses')
->where('name', 'Stark')
->orWhereNone(['en.coat-of-arms', 'en.description'], 'LIKE', '%war%');

$binds = $query->getBindings();
$bindKeys = array_keys($binds);

$this->assertSame(
'FOR houseDoc IN houses FILTER `houseDoc`.`name` == @' . $bindKeys[0]

. ' or not ( `houseDoc`.`en`.`coat-of-arms` LIKE @' . $bindKeys[1]
. ' or `houseDoc`.`en`.`description` LIKE @' . $bindKeys[2]
. ') RETURN houseDoc',
$query->toSql(),
);

$results = $query->get();
expect($results->count())->toBe(2);
expect(($results->first())->name)->toBe('Stark');
});



test('basic whereNot', function () {
$builder = getBuilder();
$builder->select('*')->from('characters')->where('surname', 'Lannister')->whereNot('alive', true);
Expand Down

0 comments on commit 9e1b965

Please sign in to comment.