-
-
Notifications
You must be signed in to change notification settings - Fork 437
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
tests/Integration/Schema/Directives/InDirectiveTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Schema\Directives; | ||
|
||
use Tests\DBTestCase; | ||
use Tests\Utils\Models\User; | ||
|
||
final class InDirectiveTest extends DBTestCase | ||
{ | ||
public function testInIDs(): void | ||
{ | ||
$user1 = factory(User::class)->create(); | ||
assert($user1 instanceof User); | ||
|
||
factory(User::class)->create(); | ||
|
||
$this->schema = /** @lang GraphQL */ ' | ||
type User { | ||
id: ID! | ||
} | ||
type Query { | ||
users(ids: [ID!] @in(key: "id")): [User!]! @all | ||
} | ||
'; | ||
|
||
$user1ID = (string) $user1->id; | ||
|
||
$this | ||
->graphQL(/** @lang GraphQL */ ' | ||
query ($ids: [ID!]) { | ||
users(ids: $ids) { | ||
id | ||
} | ||
} | ||
', [ | ||
'ids' => [$user1ID], | ||
]) | ||
->assertJson([ | ||
'data' => [ | ||
'users' => [ | ||
[ | ||
'id' => $user1ID, | ||
], | ||
], | ||
], | ||
]); | ||
} | ||
|
||
public function testExplicitNull(): void | ||
{ | ||
$users = factory(User::class, 2)->create(); | ||
|
||
$this->schema = /** @lang GraphQL */ ' | ||
type User { | ||
id: ID! | ||
} | ||
type Query { | ||
users(ids: [ID!] @in(key: "id")): [User!]! @all | ||
} | ||
'; | ||
|
||
$this | ||
->graphQL(/** @lang GraphQL */ ' | ||
query ($ids: [ID!]) { | ||
users(ids: $ids) { | ||
id | ||
} | ||
} | ||
', [ | ||
'ids' => null, | ||
]) | ||
->assertJsonCount($users->count(), 'data.users'); | ||
} | ||
|
||
public function testExplicitNullInArray(): void | ||
{ | ||
factory(User::class, 2)->create(); | ||
|
||
$this->schema = /** @lang GraphQL */ ' | ||
type User { | ||
id: ID! | ||
} | ||
type Query { | ||
users(ids: [ID] @in(key: "id")): [User!]! @all | ||
} | ||
'; | ||
|
||
$this | ||
->graphQL(/** @lang GraphQL */ ' | ||
query ($ids: [ID]) { | ||
users(ids: $ids) { | ||
id | ||
} | ||
} | ||
', [ | ||
'ids' => [null], | ||
]) | ||
->assertJsonCount(0, 'data.users'); | ||
} | ||
|
||
public function testEmptyArray(): void | ||
{ | ||
factory(User::class, 2)->create(); | ||
|
||
$this->schema = /** @lang GraphQL */ ' | ||
type User { | ||
id: ID! | ||
} | ||
type Query { | ||
users(ids: [ID!] @in(key: "id")): [User!]! @all | ||
} | ||
'; | ||
|
||
$this | ||
->graphQL(/** @lang GraphQL */ ' | ||
query ($ids: [ID!]) { | ||
users(ids: $ids) { | ||
id | ||
} | ||
} | ||
', [ | ||
'ids' => [], | ||
]) | ||
->assertJsonCount(0, 'data.users'); | ||
} | ||
} |