-
-
Notifications
You must be signed in to change notification settings - Fork 561
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initialize
directives
and arguments
in Node
with empty NodeList
- Loading branch information
Showing
12 changed files
with
170 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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace GraphQL\Tests\Utils; | ||
|
||
use GraphQL\Language\AST\FieldNode; | ||
use GraphQL\Language\AST\FragmentDefinitionNode; | ||
use GraphQL\Language\AST\FragmentSpreadNode; | ||
use GraphQL\Language\AST\InlineFragmentNode; | ||
use GraphQL\Language\AST\NodeList; | ||
use GraphQL\Language\AST\OperationDefinitionNode; | ||
use GraphQL\Language\AST\VariableDefinitionNode; | ||
use GraphQL\Utils\AST; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class AstFromArrayTest extends TestCase | ||
{ | ||
public function testFromArray(): void | ||
{ | ||
$res = AST::fromArray([ | ||
'kind' => 'VariableDefinition', | ||
'directives' => [], | ||
]); | ||
assert($res instanceof VariableDefinitionNode); | ||
self::assertEquals($res->directives, new NodeList([])); | ||
|
||
$res = AST::fromArray([ | ||
'kind' => 'OperationDefinition', | ||
'directives' => [], | ||
]); | ||
assert($res instanceof OperationDefinitionNode); | ||
self::assertEquals($res->directives, new NodeList([])); | ||
|
||
$res = AST::fromArray([ | ||
'kind' => 'Field', | ||
'directives' => [], | ||
'arguments' => [], | ||
]); | ||
assert($res instanceof FieldNode); | ||
self::assertEquals($res->directives, new NodeList([])); | ||
self::assertEquals($res->arguments, new NodeList([])); | ||
|
||
$res = AST::fromArray([ | ||
'kind' => 'FragmentSpread', | ||
'directives' => [], | ||
]); | ||
assert($res instanceof FragmentSpreadNode); | ||
self::assertEquals($res->directives, new NodeList([])); | ||
|
||
$res = AST::fromArray([ | ||
'kind' => 'FragmentDefinition', | ||
'directives' => [], | ||
]); | ||
assert($res instanceof FragmentDefinitionNode); | ||
self::assertEquals($res->directives, new NodeList([])); | ||
|
||
$res = AST::fromArray([ | ||
'kind' => 'InlineFragment', | ||
'directives' => [], | ||
]); | ||
assert($res instanceof InlineFragmentNode); | ||
self::assertEquals($res->directives, new NodeList([])); | ||
} | ||
|
||
public function testFromOptimizedArray(): void | ||
{ | ||
$res = AST::fromArray([ | ||
'kind' => 'VariableDefinition', | ||
]); | ||
assert($res instanceof VariableDefinitionNode); | ||
self::assertEquals($res->directives, new NodeList([])); | ||
|
||
$res = AST::fromArray([ | ||
'kind' => 'OperationDefinition', | ||
]); | ||
assert($res instanceof OperationDefinitionNode); | ||
self::assertEquals($res->directives, new NodeList([])); | ||
|
||
$res = AST::fromArray([ | ||
'kind' => 'Field', | ||
]); | ||
assert($res instanceof FieldNode); | ||
self::assertEquals($res->directives, new NodeList([])); | ||
self::assertEquals($res->arguments, new NodeList([])); | ||
|
||
$res = AST::fromArray([ | ||
'kind' => 'FragmentSpread', | ||
]); | ||
assert($res instanceof FragmentSpreadNode); | ||
self::assertEquals($res->directives, new NodeList([])); | ||
|
||
$res = AST::fromArray([ | ||
'kind' => 'FragmentDefinition', | ||
]); | ||
assert($res instanceof FragmentDefinitionNode); | ||
self::assertEquals($res->directives, new NodeList([])); | ||
|
||
$res = AST::fromArray([ | ||
'kind' => 'InlineFragment', | ||
]); | ||
assert($res instanceof InlineFragmentNode); | ||
self::assertEquals($res->directives, new NodeList([])); | ||
} | ||
} |