Hoa central
Multiple.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 
51 {
52  public function case_classic()
53  {
54  $this
55  ->given(
56  $foo = new LUT\Map(['f', 'o', 'o']),
57  $bar = new LUT\Map(['b', 'a', 'r']),
58  $multiple = new LUT\Multiple(
59  LUT\Multiple::MIT_NEED_ANY
60  | LUT\Multiple::MIT_KEYS_ASSOC
61  ),
62  $multiple->attachIterator($foo, 'one'),
63  $multiple->attachIterator($bar, 'two')
64  )
65  ->when($result = iterator_to_array($multiple, false))
66  ->then
67  ->array($result)
68  ->isEqualTo([
69  ['one' => 'f', 'two' => 'b'],
70  ['one' => 'o', 'two' => 'a'],
71  ['one' => 'o', 'two' => 'r']
72  ]);
73  }
74 
75  public function case_default_value()
76  {
77  $this
78  ->given(
79  $foobar = new LUT\Map(['f', 'o', 'o', 'b', 'a', 'r']),
80  $baz = new LUT\Map(['b', 'a', 'z']),
81  $multiple = new LUT\Multiple(
82  LUT\Multiple::MIT_NEED_ANY
83  | LUT\Multiple::MIT_KEYS_ASSOC
84  ),
85  $multiple->attachIterator($foobar, 'one', '!'),
86  $multiple->attachIterator($baz, 'two', '?')
87  )
88  ->when($result = iterator_to_array($multiple, false))
89  ->then
90  ->array($result)
91  ->isEqualTo([
92  ['one' => 'f', 'two' => 'b'],
93  ['one' => 'o', 'two' => 'a'],
94  ['one' => 'o', 'two' => 'z'],
95  ['one' => 'b', 'two' => '?'],
96  ['one' => 'a', 'two' => '?'],
97  ['one' => 'r', 'two' => '?'],
98  ]);
99  }
100 
101  public function case_empty()
102  {
103  $this
104  ->given($multiple = new LUT\Multiple())
105  ->when($result = iterator_to_array($multiple))
106  ->then
107  ->array($result)
108  ->isEmpty();
109  }
110 }