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

ArrayValueConverterMapTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 2
c 2
b 0
f 0
lcom 0
cbo 1
dl 0
loc 43
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testConvertWithNoArrayArgument() 0 5 1
B testConvertWithMultipleFields() 0 31 1
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