Skip to content

Commit bb20664

Browse files
committed
Add additional tests for Visitor
1 parent 4b109d2 commit bb20664

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

tests/Language/VisitorTest.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33
namespace GraphQL\Tests\Language;
44

55
use GraphQL\Language\AST\DocumentNode;
6+
use GraphQL\Language\AST\FieldDefinitionNode;
67
use GraphQL\Language\AST\FieldNode;
8+
use GraphQL\Language\AST\InputObjectTypeDefinitionNode;
9+
use GraphQL\Language\AST\InputValueDefinitionNode;
710
use GraphQL\Language\AST\NameNode;
811
use GraphQL\Language\AST\Node;
912
use GraphQL\Language\AST\NodeKind;
1013
use GraphQL\Language\AST\NodeList;
14+
use GraphQL\Language\AST\ObjectTypeDefinitionNode;
1115
use GraphQL\Language\AST\OperationDefinitionNode;
1216
use GraphQL\Language\AST\SelectionNode;
1317
use GraphQL\Language\AST\SelectionSetNode;
@@ -1684,4 +1688,48 @@ public function testMaintainsTypeInfoDuringEdit(): void
16841688
$visited
16851689
);
16861690
}
1691+
1692+
public function testAncestorsForInputValueDefinition(): void
1693+
{
1694+
$ast = Parser::parse('
1695+
input UserInput {
1696+
alwaysTwoItems: [Int]
1697+
}
1698+
');
1699+
1700+
Visitor::visit($ast, [
1701+
NodeKind::LIST_TYPE => [
1702+
'enter' => function (Node $node, $key, $parent, $path, $ancestors): void {
1703+
self::assertInstanceOf(InputValueDefinitionNode::class, $parent);
1704+
self::assertCount(4, $ancestors);
1705+
self::assertInstanceOf(DocumentNode::class, $ancestors[0]);
1706+
self::assertInstanceOf(NodeList::class, $ancestors[1]);
1707+
self::assertInstanceOf(InputObjectTypeDefinitionNode::class, $ancestors[2]);
1708+
self::assertInstanceOf(NodeList::class, $ancestors[3]);
1709+
},
1710+
],
1711+
]);
1712+
}
1713+
1714+
public function testAncestorsForObjectTypeDefinition(): void
1715+
{
1716+
$ast = Parser::parse('
1717+
type User {
1718+
alwaysTwoItems: [Int]
1719+
}
1720+
');
1721+
1722+
Visitor::visit($ast, [
1723+
NodeKind::LIST_TYPE => [
1724+
'enter' => function (Node $node, $key, $parent, $path, $ancestors): void {
1725+
self::assertInstanceOf(FieldDefinitionNode::class, $parent);
1726+
self::assertCount(4, $ancestors);
1727+
self::assertInstanceOf(DocumentNode::class, $ancestors[0]);
1728+
self::assertInstanceOf(NodeList::class, $ancestors[1]);
1729+
self::assertInstanceOf(ObjectTypeDefinitionNode::class, $ancestors[2]);
1730+
self::assertInstanceOf(NodeList::class, $ancestors[3]);
1731+
},
1732+
],
1733+
]);
1734+
}
16871735
}

0 commit comments

Comments
 (0)