Skip to content

Commit

Permalink
Confirmed proper functioning of whereNot/orWhereNot (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
LaravelFreelancerNL authored Nov 10, 2024
1 parent f5e0625 commit 5f36deb
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/compatibility-list.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ rightJoin / rightJoinSub / joinWhere?
where / orWhere / whereNot / orWhereNot / whereColumn / whereExists
whereBetween / whereNotBetween / whereBetweenColumns / whereNotBetweenColumns /
whereJsonContains / whereJsonLength /
whereIn / whereNotIn / whereNull / whereNotNull /
whereIn / whereNotIn / whereNot / orWhereNot / whereNull / whereNotNull /
whereDate / whereMonth / whereDay / whereYear / whereTime /
whereRaw (use AQL) /
whereAll / orWhereAll / whereAny / orWhereAny
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<php>
<env name="APP_KEY" value="AckfSECXIvnK5r28GVIWUAxmbBSjTsmF"/>
<env name="ARANGODB_VERSION" value="3.12"/>
<env name="DB_ENDPOINT" value="https://localhost:8529"/>
<env name="LARAVEL_VERSION" value="11"/>
<env name="RAY_ENABLED" value="(true)"/>
<env name="SEND_CACHE_TO_RAY" value="(false)"/>
Expand Down
88 changes: 88 additions & 0 deletions tests/Query/WheresTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -530,3 +530,91 @@
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);

$this->assertSame(
'FOR characterDoc IN characters FILTER `characterDoc`.`surname` == @'
. $builder->getQueryId()
. '_where_1 and not `characterDoc`.`alive` == @'
. $builder->getQueryId()
. '_where_2 RETURN characterDoc',
$builder->toSql(),
);
});

test('whereNot nested', function () {
$query = getBuilder();
$query = $query
->select('*')
->from('characters')
->where('alive', true)
->whereNot(function ($query) {
$query->where('surname', 'lannister')
->orWhere('age', '<', 20);
});


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

$this->assertSame(
'FOR characterDoc IN characters FILTER `characterDoc`.`alive` == @' . $bindKeys[0]
. ' and not ( `characterDoc`.`surname` == @' . $bindKeys[1]
. ' or `characterDoc`.`age` < @' . $bindKeys[2]
. ') RETURN characterDoc',
$query->toSql(),
);
});

test('whereNot query results', function () {
$results = \DB::table('characters')
->where('alive', true)
->whereNot(function ($query) {
$query->where('surname', 'Lannister')
->orWhere('age', '<', 20);
})->get();

expect($results->count())->toBe(3);
});

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

$this->assertSame(
'FOR characterDoc IN characters FILTER `characterDoc`.`alive` == @'
. $builder->getQueryId()
. '_where_1 or not `characterDoc`.`surname` == @'
. $builder->getQueryId()
. '_where_2 RETURN characterDoc',
$builder->toSql(),
);
});


test('orWhereNot query results', function () {
$results = \DB::table('characters')
->where('alive', true)
->orWhereNot('surname', 'Lannister')
->get();

ray($results);

expect($results->count())->toBe(27);
});

test('nest whereNot & orWhereNot', function () {
$builder = \DB::table('characters')
->where('alive', true)
->where(function ($query) {
$query->whereNot('surname', 'Lannister')
->orWhereNot('age', '<', 20);
});

$results = $builder->get();

expect($results->count())->toBe(27);
});

0 comments on commit 5f36deb

Please sign in to comment.