2021-12-31 16:10:55 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace CuyZ\Valinor\Tests\Unit\Mapper\Tree;
|
|
|
|
|
|
|
|
use CuyZ\Valinor\Mapper\Tree\Node;
|
|
|
|
use CuyZ\Valinor\Mapper\Tree\NodeTraverser;
|
2022-07-10 18:17:16 +02:00
|
|
|
use CuyZ\Valinor\Tests\Fake\Mapper\Tree\FakeNode;
|
2021-12-31 16:10:55 +01:00
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
final class NodeTraverserTest extends TestCase
|
|
|
|
{
|
|
|
|
public function test_nodes_are_visited(): void
|
|
|
|
{
|
2022-07-10 18:17:16 +02:00
|
|
|
$children = [
|
|
|
|
'foo' => FakeNode::any(),
|
|
|
|
'bar' => FakeNode::any(),
|
|
|
|
];
|
|
|
|
|
|
|
|
$node = FakeNode::branch($children);
|
2021-12-31 16:10:55 +01:00
|
|
|
|
|
|
|
$visited = [...(new NodeTraverser(
|
|
|
|
fn (Node $node) => $node
|
|
|
|
))->traverse($node)];
|
|
|
|
|
|
|
|
self::assertContains($node, $visited);
|
2022-07-10 18:17:16 +02:00
|
|
|
self::assertContains($children['foo'], $visited);
|
|
|
|
self::assertContains($children['bar'], $visited);
|
2021-12-31 16:10:55 +01:00
|
|
|
}
|
|
|
|
}
|