Failed Conditions
Branch master (01ba0d)
by Arnold
06:58 queued 01:45
created

IterableSeparateTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 45
rs 10
c 0
b 0
f 0
wmc 6
1
<?php
2
3
namespace Jasny\Tests;
4
5
use PHPUnit\Framework\TestCase;
6
use function Jasny\iterable_separate;
7
8
/**
9
 * @covers \Jasny\iterable_separate
10
 */
11
class IterableSeparateTest extends TestCase
12
{
13
    use ProvideIterablesTrait;
14
15
    public function provider()
16
    {
17
        $tests = $this->provideIterables(['one' => 'uno', 'two' => 'dos', 'three' => 'tres']);
18
19
        foreach ($tests as &$test) {
20
            $test[1] = ['keys' => array_keys($test[1]), 'values' => array_values($test[1])];
21
        }
22
23
        return $tests;
24
    }
25
26
    /**
27
     * @dataProvider provider
28
     */
29
    public function test($values, $expected)
30
    {
31
        $result = iterable_separate($values);
32
        $this->assertEquals($expected, $result);
33
    }
34
35
    public function testIterateGenerator()
36
    {
37
        $keys = [(object)['a' => 'a'], ['b' => 'b'], null, 'd', 'd'];
38
        $values = [1, 2, 3, 4, null];
39
40
        $loop = function($keys, $values) {
41
            foreach ($keys as $i => $key) {
42
                yield $key => $values[$i];
43
            }
44
        };
45
46
        $generator = $loop($keys, $values);
47
        $result = iterable_separate($generator);
48
49
        $this->assertSame(compact('keys', 'values'), $result);
50
    }
51
52
    public function testIterateEmpty()
53
    {
54
        $result = iterable_separate(new \EmptyIterator());
55
        $this->assertSame(['keys' => [], 'values' => []], $result);
56
    }
57
}
58