Completed
Push — master ( 7a3cb1...e42624 )
by Harry
9s
created

MapIteratorTest::testMapIterator()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 28
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 28
rs 8.8571
cc 1
eloc 19
nc 1
nop 0
1
<?php
2
/**
3
 * This file is part of graze/data-file
4
 *
5
 * Copyright (c) 2016 Nature Delivered Ltd. <https://www.graze.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license https://github.com/graze/data-file/blob/master/LICENSE.md
11
 * @link    https://github.com/graze/data-file
12
 */
13
14
namespace Graze\DataFile\Test\Unit\Helper;
15
16
use Akamon\MockeryCallableMock\MockeryCallableMock;
17
use ArrayIterator;
18
use Graze\DataFile\Helper\MapIterator;
19
use Graze\DataFile\Test\TestCase;
20
use Mockery as m;
21
22
class MapIteratorTest extends TestCase
23
{
24
    public function testMapIterator()
25
    {
26
        $callback = new MockeryCallableMock();
27
        $iterator = new ArrayIterator(['key' => 'value', 'second' => 'monkey', 'third']);
28
29
        $mapIterator = new MapIterator($iterator, $callback);
30
31
        $callback->shouldBeCalled()
32
                 ->with('value', 'key', $iterator)
33
                 ->andReturn('modified');
34
        $callback->shouldBeCalled()
35
                 ->with('monkey', 'second', $iterator)
36
                 ->andReturn('fish');
37
        $callback->shouldBeCalled()
38
                 ->with('third', 0, $iterator)
39
                 ->andReturn('cake');
40
41
        $results = iterator_to_array($mapIterator, true);
42
43
        static::assertEquals(
44
            [
45
                'key'    => 'modified',
46
                'second' => 'fish',
47
                'cake',
48
            ],
49
            $results
50
        );
51
    }
52
}
53