SelectIteratorTest   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 13
dl 0
loc 29
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getIteratorYeildsResults() 0 23 1
1
<?php
2
3
namespace SubjectivePHPTest\Linq;
4
5
use ArrayIterator;
6
use PHPUnit\Framework\TestCase;
7
use SubjectivePHP\Linq\SelectIterator;
8
9
/**
10
 * @coversDefaultClass \SubjectivePHP\Linq\SelectIterator
11
 * @covers ::__construct
12
 */
13
final class SelectIteratorTest extends TestCase
14
{
15
    /**
16
     * @test
17
     * @covers ::getIterator
18
     */
19
    public function getIteratorYeildsResults()
20
    {
21
        $iterator = new ArrayIterator(
22
           [
23
               ['id' => 1, 'price' => 1.0],
24
               ['id' => 2, 'price' => 2.0],
25
               ['id' => 2, 'price' => 2.0],
26
           ]
27
        );
28
29
        $selector = function (array $item) : array {
30
            return ['id' => $item['id']];
31
        };
32
33
        $selectIterator = new SelectIterator($iterator, $selector);
34
35
        $this->assertSame(
36
            [
37
                ['id' => 1],
38
                ['id' => 2],
39
                ['id' => 2],
40
            ],
41
            iterator_to_array($selectIterator)
42
        );
43
    }
44
}
45