|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Ddeboer\DataImport\Tests\ValueConverter; |
|
4
|
|
|
|
|
5
|
|
|
use Ddeboer\DataImport\ValueConverter\ObjectConverter; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* @author Markus Bachmann <[email protected] |
|
9
|
|
|
*/ |
|
10
|
|
|
class ObjectConverterTest extends \PHPUnit_Framework_TestCase |
|
11
|
|
|
{ |
|
12
|
|
|
public function testGetAndSetPropertyPath() |
|
13
|
|
|
{ |
|
14
|
|
|
$converter = new ObjectConverter(); |
|
15
|
|
|
$this->assertNull($converter->getPropertyPath()); |
|
16
|
|
|
|
|
17
|
|
|
$converter->setPropertyPath('foo.bar'); |
|
18
|
|
|
$this->assertEquals('foo.bar', $converter->getPropertyPath()); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
public function testConvertWithToString() |
|
22
|
|
|
{ |
|
23
|
|
|
$converter = new ObjectConverter(); |
|
24
|
|
|
$object = new ToStringDummy(); |
|
25
|
|
|
|
|
26
|
|
|
$this->assertEquals('foo', call_user_func($converter, $object)); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function testConvertWithPropertyPath() |
|
30
|
|
|
{ |
|
31
|
|
|
$converter = new ObjectConverter('foo'); |
|
32
|
|
|
$object = new Dummy(); |
|
33
|
|
|
|
|
34
|
|
|
$this->assertEquals('bar', call_user_func($converter, $object)); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @expectedException RuntimeException |
|
39
|
|
|
*/ |
|
40
|
|
|
public function testConvertAObjectWithoutToString() |
|
41
|
|
|
{ |
|
42
|
|
|
$converter = new ObjectConverter; |
|
43
|
|
|
call_user_func($converter, new Dummy()); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @expectedException Ddeboer\DataImport\Exception\UnexpectedTypeException |
|
48
|
|
|
*/ |
|
49
|
|
|
public function testConvetANonObject() |
|
50
|
|
|
{ |
|
51
|
|
|
$converter = new ObjectConverter(); |
|
52
|
|
|
call_user_func($converter, 'foo'); |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
class Dummy |
|
57
|
|
|
{ |
|
58
|
|
|
public $foo = 'bar'; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
class ToStringDummy |
|
62
|
|
|
{ |
|
63
|
|
|
public function __toString() |
|
64
|
|
|
{ |
|
65
|
|
|
return 'foo'; |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|