1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace JhFlexiTimeTest\Stdlib\Hydrator; |
4
|
|
|
|
5
|
|
|
use Doctrine\DBAL\Types\Type; |
6
|
|
|
use JhFlexiTime\Entity\Booking; |
7
|
|
|
use JhFlexiTime\Stdlib\Hydrator\DoctrineObject; |
8
|
|
|
use PHPUnit_Framework_TestCase; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class UserStrategyTest |
12
|
|
|
* @package JhFlexiTimeTest\Validator |
13
|
|
|
* @author Aydin Hassan <[email protected]> |
14
|
|
|
*/ |
15
|
|
|
class DoctrineObjectTest extends PHPUnit_Framework_TestCase |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var DoctrineObject |
19
|
|
|
*/ |
20
|
|
|
protected $hydrator; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var \Doctrine\Common\Persistence\Mapping\ClassMetadata |
24
|
|
|
*/ |
25
|
|
|
protected $metadata; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var \Doctrine\Common\Persistence\ObjectManager |
29
|
|
|
*/ |
30
|
|
|
protected $objectManager; |
31
|
|
|
|
32
|
|
|
public function setUp() |
33
|
|
|
{ |
34
|
|
|
$this->objectManager = $this->getMock('Doctrine\Common\Persistence\ObjectManager'); |
35
|
|
|
$this->hydrator = new DoctrineObject($this->objectManager); |
36
|
|
|
$this->metadata = $this->getMock('Doctrine\Common\Persistence\Mapping\ClassMetadata'); |
37
|
|
|
|
38
|
|
|
$this->objectManager->expects($this->any()) |
39
|
|
|
->method('getClassMetadata') |
40
|
|
|
->will($this->returnValue($this->metadata)); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testHandleTypeConversionsCustom() |
44
|
|
|
{ |
45
|
|
|
Type::overrideType('time', 'JhFlexiTime\DBAL\Types\TimeType'); |
46
|
|
|
|
47
|
|
|
$this |
|
|
|
|
48
|
|
|
->metadata |
49
|
|
|
->expects($this->any()) |
50
|
|
|
->method('getName') |
51
|
|
|
->will($this->returnValue('JhFlexiTime\Entity\Booking')); |
52
|
|
|
$this |
|
|
|
|
53
|
|
|
->metadata |
54
|
|
|
->expects($this->any()) |
55
|
|
|
->method('getAssociationNames') |
56
|
|
|
->will($this->returnValue(array())); |
57
|
|
|
|
58
|
|
|
$this |
|
|
|
|
59
|
|
|
->metadata |
60
|
|
|
->expects($this->any()) |
61
|
|
|
->method('getTypeOfField') |
62
|
|
|
->will($this->returnValue('time')); |
63
|
|
|
|
64
|
|
|
$booking = new Booking; |
65
|
|
|
$this->hydrator->hydrate(['startTime' => 1422486708], $booking); |
66
|
|
|
$this->assertInstanceOf('JhFlexiTime\DateTime\DateTime', $booking->getStartTime()); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function testHandleTypeConversionsWithNoCustomTypes() |
70
|
|
|
{ |
71
|
|
|
Type::overrideType('time', 'Doctrine\DBAL\Types\TimeType'); |
72
|
|
|
|
73
|
|
|
$this |
|
|
|
|
74
|
|
|
->metadata |
75
|
|
|
->expects($this->any()) |
76
|
|
|
->method('getName') |
77
|
|
|
->will($this->returnValue('JhFlexiTimeTest\Stdlib\Hydrator\TestEntity')); |
78
|
|
|
$this |
|
|
|
|
79
|
|
|
->metadata |
80
|
|
|
->expects($this->any()) |
81
|
|
|
->method('getAssociationNames') |
82
|
|
|
->will($this->returnValue(array())); |
83
|
|
|
|
84
|
|
|
$this |
|
|
|
|
85
|
|
|
->metadata |
86
|
|
|
->expects($this->any()) |
87
|
|
|
->method('getTypeOfField') |
88
|
|
|
->will($this->returnValue('time')); |
89
|
|
|
|
90
|
|
|
$booking = new TestEntity; |
91
|
|
|
$this->hydrator->hydrate(['startTime' => 1422486708], $booking); |
92
|
|
|
$this->assertInstanceOf('DateTime', $booking->getStartTime()); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.