Hoa central
Map.php
Go to the documentation of this file.
1 <?php
2 
37 namespace Hoa\Iterator\Test\Unit;
38 
39 use Hoa\Iterator as LUT;
40 use Hoa\Test;
41 
50 class Map extends Test\Unit\Suite
51 {
52  private static $_dummyArray = ['f', 'o', 'o', 'b', 'a', 'r'];
53 
54 
55 
56  public function case_classic()
57  {
58  $this
59  ->given($iterator = new LUT\Map(self::$_dummyArray))
60  ->when($result = iterator_to_array($iterator))
61  ->then
62  ->array($result)
63  ->isEqualTo(self::$_dummyArray);
64  }
65 
66  public function case_empty()
67  {
68  $this
69  ->given($iterator = new LUT\Map())
70  ->when($result = iterator_to_array($iterator))
71  ->then
72  ->array($result)
73  ->isEmpty();
74  }
75 
76  public function case_recursive()
77  {
78  $this
79  ->given(
80  $array = [
81  'a' => ['b', 'c', 'd'],
82  'e' => ['f', 'g', 'i'],
83  'k'
84  ],
85  $iterator = new LUT\Recursive\Map($array)
86  )
87  ->when(function () use ($iterator) {
88  foreach ($iterator as $key => $value) {
89  if ('a' === $key) {
90  $this
91  ->boolean($iterator->hasChildren())
92  ->isTrue()
93  ->object($children = $iterator->getChildren())
94  ->isInstanceOf('Hoa\Iterator\Recursive\Map')
95  ->array(iterator_to_array($children))
96  ->isEqualTo(['b', 'c', 'd']);
97  } elseif ('e' === $key) {
98  $this
99  ->boolean($iterator->hasChildren())
100  ->isTrue()
101  ->object($children = $iterator->getChildren())
102  ->isInstanceOf('Hoa\Iterator\Recursive\Map')
103  ->array(iterator_to_array($children))
104  ->isEqualTo(['f', 'g', 'i']);
105  } elseif ('k' === $value) {
106  $this
107  ->boolean($iterator->hasChildren())
108  ->isFalse();
109  }
110  }
111  });
112  }
113 }