Total Complexity | 7 |
Total Lines | 34 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
7 | trait ProvideIterablesTrait |
||
8 | { |
||
9 | protected function generateAssoc(iterable $values): \Generator |
||
10 | { |
||
11 | foreach ($values as $key => $value) { |
||
12 | yield $key => $value; |
||
13 | } |
||
14 | } |
||
15 | |||
16 | protected function generateTricky(iterable $values): \Generator |
||
17 | { |
||
18 | foreach ($values as $value) { |
||
19 | yield [] => $value; |
||
20 | } |
||
21 | } |
||
22 | |||
23 | public function provideIterables(array $values, $tricky = false, $fixedArray = true) |
||
24 | { |
||
25 | $tests = [ |
||
26 | [$values, $values], |
||
27 | [new \ArrayIterator($values), $values], |
||
28 | [new \ArrayObject($values), $values], |
||
29 | [$this->generateAssoc($values), $values] |
||
30 | ]; |
||
31 | |||
32 | if ($fixedArray) { |
||
33 | $tests[] = [\SplFixedArray::fromArray(array_values($values)), array_values($values)]; |
||
34 | } |
||
35 | |||
36 | if ($tricky) { |
||
37 | $tests[] = [$this->generateTricky($values), array_values($values)]; |
||
38 | } |
||
39 | |||
40 | return $tests; |
||
41 | } |
||
43 |