GraphQL\Tests\Language\VisitorTest::testAllowsEarlyExitWhileLeaving PHP Method

testAllowsEarlyExitWhileLeaving() public method

    public function testAllowsEarlyExitWhileLeaving()
    {
        $visited = [];
        $ast = Parser::parse('{ a, b { x }, c }');
        Visitor::visit($ast, ['enter' => function ($node) use(&$visited) {
            $visited[] = ['enter', $node->kind, isset($node->value) ? $node->value : null];
        }, 'leave' => function ($node) use(&$visited) {
            $visited[] = ['leave', $node->kind, isset($node->value) ? $node->value : null];
            if ($node->kind === NodeKind::NAME && $node->value === 'x') {
                return Visitor::stop();
            }
        }]);
        $this->assertEquals($visited, [['enter', 'Document', null], ['enter', 'OperationDefinition', null], ['enter', 'SelectionSet', null], ['enter', 'Field', null], ['enter', 'Name', 'a'], ['leave', 'Name', 'a'], ['leave', 'Field', null], ['enter', 'Field', null], ['enter', 'Name', 'b'], ['leave', 'Name', 'b'], ['enter', 'SelectionSet', null], ['enter', 'Field', null], ['enter', 'Name', 'x'], ['leave', 'Name', 'x']]);
    }