testConvertWithNoArrayArgument()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
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
            'foo' => 'test',
26
            'bar' => 'test'
27
        );
28
29
        $addBarConverter = function($input) { return 'bar'.$input; };
30
        $addBazConverter = function($input) { return 'baz'.$input; };
31
32
        $converter = new ArrayValueConverterMap(
33
            array(
34
                'foo' => array($addBarConverter),
35
                'bar' => array($addBazConverter, $addBarConverter),
36
            )
37
        );
38
39
        $data = call_user_func($converter, $data);
40
41
        $this->assertEquals('bartest', $data['foo']);
42
        $this->assertEquals('barbaztest', $data['bar']);
43
    }
44
}
45