createDocumentFragment(); $fragment->appendXML( trim( $html ) ); $expected = static::getJson( $expectedPath ); $actual = []; CommentUtils::linearWalk( $fragment, static function ( $event, $node ) use ( &$actual ) { $actual[] = "$event {$node->nodeName}({$node->nodeType})"; } ); $actualBackwards = []; CommentUtils::linearWalkBackwards( $fragment, static function ( $event, $node ) use ( &$actualBackwards ) { $actualBackwards[] = "$event {$node->nodeName}({$node->nodeType})"; } ); // Optionally write updated content to the JSON files if ( getenv( 'DISCUSSIONTOOLS_OVERWRITE_TESTS' ) ) { static::overwriteJsonFile( $expectedPath, $actual ); } static::assertEquals( $expected, $actual, $name ); $expectedBackwards = array_map( static function ( $a ) { return ( substr( $a, 0, 5 ) === 'enter' ? 'leave' : 'enter' ) . substr( $a, 5 ); }, array_reverse( $expected ) ); static::assertEquals( $expectedBackwards, $actualBackwards, $name . ' (backwards)' ); } public function provideLinearWalk(): array { return static::getJson( '../cases/linearWalk.json' ); } }