1 | <?php |
||
23 | class IteratorNodeTest extends AbstractTestCase |
||
24 | { |
||
25 | public function testImplements() |
||
26 | { |
||
27 | $node = new IteratorNode([]); |
||
28 | static::assertInstanceOf(Iterator::class, $node); |
||
29 | static::assertInstanceOf(IteratorNodeInterface::class, $node); |
||
30 | } |
||
31 | |||
32 | public function testInstantiateWithArray() |
||
33 | { |
||
34 | $node = new IteratorNode(['first', 'second']); |
||
35 | static::assertEquals(['first', 'second'], iterator_to_array($node)); |
||
36 | } |
||
37 | |||
38 | public function testInstantiateWithArrayAndKeys() |
||
39 | { |
||
40 | $node = new IteratorNode(['first' => 'value1', 'second' => 'value2']); |
||
41 | static::assertEquals(['first' => 'value1', 'second' => 'value2'], iterator_to_array($node, true)); |
||
42 | } |
||
43 | |||
44 | public function testInstantiateWithIterator() |
||
45 | { |
||
46 | $node = new IteratorNode(new ArrayIterator(['first', 'second'])); |
||
47 | static::assertEquals(['first', 'second'], iterator_to_array($node)); |
||
48 | } |
||
49 | |||
50 | public function testFetchWillReturnAnIterator() |
||
51 | { |
||
52 | $node = new IteratorNode(['first', 'second']); |
||
53 | $iterator = $node->fetch(); |
||
54 | static::assertInstanceOf(Iterator::class, $iterator); |
||
55 | static::assertInstanceOf(Traversable::class, $iterator); |
||
56 | static::assertEquals(['first', 'second'], iterator_to_array($iterator)); |
||
57 | } |
||
58 | |||
59 | public function testFetchWillFilterOnCallable() |
||
60 | { |
||
61 | $node = new IteratorNode(['first', 'second']); |
||
62 | $iterator = $node->fetch(function ($value) { |
||
63 | return $value == 'first'; |
||
64 | }); |
||
65 | static::assertEquals(['first'], iterator_to_array($iterator)); |
||
66 | } |
||
67 | |||
68 | public function testClone() |
||
69 | { |
||
70 | $iterator = new ArrayIterator(['first', 'second']); |
||
71 | $node = new IteratorNode($iterator); |
||
72 | $clone = $node->getClone(); |
||
73 | |||
74 | static::assertNotSame($clone, $node); |
||
75 | |||
76 | $iterator->append('third'); |
||
77 | |||
78 | static::assertEquals(['first', 'second', 'third'], iterator_to_array($node)); |
||
79 | static::assertEquals(['first', 'second'], iterator_to_array($clone)); |
||
80 | } |
||
81 | |||
82 | public function testToString() |
||
86 | } |
||
87 | } |
||
88 |