Completed
Pull Request — master (#298)
by
unknown
03:49
created

testConvertWithMultipleFields()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 31
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 31
rs 8.8571
cc 1
eloc 19
nc 1
nop 0
1
<?php
2
3
namespace Ddeboer\DataImport\Tests\ValueConverter;
4
5
use Ddeboer\DataImport\ValueConverter\ArrayValueConverterMap;
6
use Ddeboer\DataImport\ValueConverter\CallbackValueConverter;
7
8
/**
9
 * @author Christoph Rosse <[email protected]>
10
 */
11
class ArrayValueConverterMapTest extends \PHPUnit_Framework_TestCase
12
{
13
    /**
14
     * @expectedException InvalidArgumentException
15
     */
16
    public function testConvertWithNoArrayArgument()
17
    {
18
        $converter = new ArrayValueConverterMap(array('foo' => function($input) {return $input;}));
19
        call_user_func($converter, 'foo');
20
    }
21
22
    public function testConvertWithMultipleFields()
23
    {
24
        $data = array(
25
            array(
26
                'foo' => 'test',
27
                'bar' => 'test'
28
            ),
29
            array(
30
                'foo' => 'test2',
31
                'bar' => 'test2'
32
            ),
33
        );
34
35
        $addBarConverter = function($input) { return 'bar'.$input; };
36
        $addBazConverter = function($input) { return 'baz'.$input; };
37
38
        $converter = new ArrayValueConverterMap(
39
            array(
40
                'foo' => array($addBarConverter),
41
                'bar' => array($addBazConverter, $addBarConverter),
42
            )
43
        );
44
45
        $data = call_user_func($converter, $data);
46
47
        $this->assertEquals('bartest', $data[0]['foo']);
48
        $this->assertEquals('barbaztest', $data[0]['bar']);
49
50
        $this->assertEquals('bartest2', $data[1]['foo']);
51
        $this->assertEquals('barbaztest2', $data[1]['bar']);
52
    }
53
}
54