ArrayValueConverterMapTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

2 Methods

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