|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace RZ\TreeWalker\Tests; |
| 6 | + |
| 7 | +use Doctrine\Common\Collections\Collection; |
| 8 | +use RZ\TreeWalker\EmptyWalkerContext; |
| 9 | +use RZ\TreeWalker\Tests\Mock\Dummy; |
| 10 | +use RZ\TreeWalker\Tests\Walker\DummyWalker; |
| 11 | + |
| 12 | +class DummyTest extends SerializerTestCase |
| 13 | +{ |
| 14 | + public function testBuild(): void |
| 15 | + { |
| 16 | + $firstItem = new Dummy('ancestor'); |
| 17 | + $walker = DummyWalker::build( |
| 18 | + $firstItem, |
| 19 | + new EmptyWalkerContext(), |
| 20 | + 3 // max level count |
| 21 | + ); |
| 22 | + $children = $walker->getChildren(); |
| 23 | + $this->assertInstanceOf(Collection::class, $children); |
| 24 | + $this->assertCount(3, $children); |
| 25 | + |
| 26 | + $this->assertInstanceOf(DummyWalker::class, $children[0]); |
| 27 | + |
| 28 | + $this->assertEquals('ancestor - child 1', $children[0]->getItem()->name); |
| 29 | + $this->assertEquals('ancestor - child 2', $children[1]->getItem()->name); |
| 30 | + $this->assertEquals('ancestor - child 3', $children[2]->getItem()->name); |
| 31 | + } |
| 32 | + |
| 33 | + public function testSerialize(): void |
| 34 | + { |
| 35 | + $firstItem = new Dummy('ancestor'); |
| 36 | + $walker = DummyWalker::build( |
| 37 | + $firstItem, |
| 38 | + new EmptyWalkerContext(), |
| 39 | + 3 // max level count |
| 40 | + ); |
| 41 | + |
| 42 | + $this->assertJsonStringEqualsJsonFile( |
| 43 | + __DIR__ . '/fixtures/dummy-walker.json', |
| 44 | + $this->getSerializer()->serialize($walker, 'json', ['groups' => ['children', 'walker', 'dummy']]) |
| 45 | + ); |
| 46 | + } |
| 47 | +} |
0 commit comments