Skip to content

Commit 5f36deb

Browse files
Confirmed proper functioning of whereNot/orWhereNot (#165)
1 parent f5e0625 commit 5f36deb

File tree

3 files changed

+90
-1
lines changed

3 files changed

+90
-1
lines changed

docs/compatibility-list.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ rightJoin / rightJoinSub / joinWhere?
7474
where / orWhere / whereNot / orWhereNot / whereColumn / whereExists
7575
whereBetween / whereNotBetween / whereBetweenColumns / whereNotBetweenColumns /
7676
whereJsonContains / whereJsonLength /
77-
whereIn / whereNotIn / whereNull / whereNotNull /
77+
whereIn / whereNotIn / whereNot / orWhereNot / whereNull / whereNotNull /
7878
whereDate / whereMonth / whereDay / whereYear / whereTime /
7979
whereRaw (use AQL) /
8080
whereAll / orWhereAll / whereAny / orWhereAny

phpunit.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
<php>
3131
<env name="APP_KEY" value="AckfSECXIvnK5r28GVIWUAxmbBSjTsmF"/>
3232
<env name="ARANGODB_VERSION" value="3.12"/>
33+
<env name="DB_ENDPOINT" value="https://localhost:8529"/>
3334
<env name="LARAVEL_VERSION" value="11"/>
3435
<env name="RAY_ENABLED" value="(true)"/>
3536
<env name="SEND_CACHE_TO_RAY" value="(false)"/>

tests/Query/WheresTest.php

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,3 +530,91 @@
530530
expect($results->count())->toBe(2);
531531
expect(($results->first())->name)->toBe('Stark');
532532
});
533+
534+
test('basic whereNot', function () {
535+
$builder = getBuilder();
536+
$builder->select('*')->from('characters')->where('surname', 'Lannister')->whereNot('alive', true);
537+
538+
$this->assertSame(
539+
'FOR characterDoc IN characters FILTER `characterDoc`.`surname` == @'
540+
. $builder->getQueryId()
541+
. '_where_1 and not `characterDoc`.`alive` == @'
542+
. $builder->getQueryId()
543+
. '_where_2 RETURN characterDoc',
544+
$builder->toSql(),
545+
);
546+
});
547+
548+
test('whereNot nested', function () {
549+
$query = getBuilder();
550+
$query = $query
551+
->select('*')
552+
->from('characters')
553+
->where('alive', true)
554+
->whereNot(function ($query) {
555+
$query->where('surname', 'lannister')
556+
->orWhere('age', '<', 20);
557+
});
558+
559+
560+
$binds = $query->getBindings();
561+
$bindKeys = array_keys($binds);
562+
563+
$this->assertSame(
564+
'FOR characterDoc IN characters FILTER `characterDoc`.`alive` == @' . $bindKeys[0]
565+
. ' and not ( `characterDoc`.`surname` == @' . $bindKeys[1]
566+
. ' or `characterDoc`.`age` < @' . $bindKeys[2]
567+
. ') RETURN characterDoc',
568+
$query->toSql(),
569+
);
570+
});
571+
572+
test('whereNot query results', function () {
573+
$results = \DB::table('characters')
574+
->where('alive', true)
575+
->whereNot(function ($query) {
576+
$query->where('surname', 'Lannister')
577+
->orWhere('age', '<', 20);
578+
})->get();
579+
580+
expect($results->count())->toBe(3);
581+
});
582+
583+
test('basic orWhereNot', function () {
584+
$builder = getBuilder();
585+
$builder->select('*')->from('characters')->where('alive', true)->orWhereNot('surname', 'Lannister');
586+
587+
$this->assertSame(
588+
'FOR characterDoc IN characters FILTER `characterDoc`.`alive` == @'
589+
. $builder->getQueryId()
590+
. '_where_1 or not `characterDoc`.`surname` == @'
591+
. $builder->getQueryId()
592+
. '_where_2 RETURN characterDoc',
593+
$builder->toSql(),
594+
);
595+
});
596+
597+
598+
test('orWhereNot query results', function () {
599+
$results = \DB::table('characters')
600+
->where('alive', true)
601+
->orWhereNot('surname', 'Lannister')
602+
->get();
603+
604+
ray($results);
605+
606+
expect($results->count())->toBe(27);
607+
});
608+
609+
test('nest whereNot & orWhereNot', function () {
610+
$builder = \DB::table('characters')
611+
->where('alive', true)
612+
->where(function ($query) {
613+
$query->whereNot('surname', 'Lannister')
614+
->orWhereNot('age', '<', 20);
615+
});
616+
617+
$results = $builder->get();
618+
619+
expect($results->count())->toBe(27);
620+
});

0 commit comments

Comments
 (0)