getConvertData()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.6333
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
namespace Mathielen\DataImport\ItemConverter;
3
4
use TestEntities\Address;
5
6
class UnknownPropertiesItemConverterTest extends \PHPUnit_Framework_TestCase
7
{
8
9
    /**
10
     * @dataProvider getConvertData
11
     */
12
    public function testConvert(array $knownProperties, $targetProperty, $skipEmptyKey, $inputData, array $expectedResult)
13
    {
14
        $converter = new UnknownPropertiesItemConverter($knownProperties, $targetProperty, $skipEmptyKey);
15
16
        $this->assertEquals($expectedResult, $converter->convert($inputData));
17
    }
18
19
    public function testFromClass()
20
    {
21
        $converter = UnknownPropertiesItemConverter::fromClass(Address::class);
22
23
        $this->assertEquals(['name' => 1, 'ATTRIBUTES' => ['unknown' => 1]], $converter->convert(['name' => 1, 'unknown' => 1]));
24
    }
25
26
    public function getConvertData()
27
    {
28
        return array(
29
            array(
30
                array('a', 'b', 'property_with_underscore'),
31
                'target',
32
                true,
33
                array('a' => 1, 'b' => 2, 'c' => 3, '' => '', 'propertywithunderscore' => 1),
34
                array('a' => 1, 'b' => 2, 'target' => array('c' => 3), 'propertywithunderscore' => 1)
35
            ),
36
            array(
37
                array('a', 'b'),
38
                'target',
39
                false,
40
                array('a' => 1, 'b' => 2, '' => ''),
41
                array('a' => 1, 'b' => 2, 'target' => array('' => ''))
42
            )
43
        );
44
    }
45
46
}
47