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

testAllowsEarlyExitFromDifferentPoints() public method

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