|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\ORM\Hydration; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\Tests\Mocks\HydratorMockStatement; |
|
6
|
|
|
use Doctrine\ORM\Query\ResultSetMapping; |
|
7
|
|
|
|
|
8
|
|
|
class SimpleObjectHydratorTest extends HydrationTestCase |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* @group DDC-1470 |
|
12
|
|
|
* |
|
13
|
|
|
* @expectedException \Doctrine\ORM\Internal\Hydration\HydrationException |
|
14
|
|
|
* @expectedExceptionMessage The discriminator column "discr" is missing for "Doctrine\Tests\Models\Company\CompanyPerson" using the DQL alias "p". |
|
15
|
|
|
*/ |
|
16
|
|
|
public function testMissingDiscriminatorColumnException() |
|
17
|
|
|
{ |
|
18
|
|
|
$rsm = new ResultSetMapping; |
|
19
|
|
|
$rsm->addEntityResult('Doctrine\Tests\Models\Company\CompanyPerson', 'p'); |
|
20
|
|
|
$rsm->addFieldResult('p', 'p__id', 'id'); |
|
21
|
|
|
$rsm->addFieldResult('p', 'p__name', 'name'); |
|
22
|
|
|
$rsm->addMetaResult('p ', 'discr', 'discr', false, 'string'); |
|
23
|
|
|
$rsm->setDiscriminatorColumn('p', 'discr'); |
|
24
|
|
|
$resultSet = array( |
|
25
|
|
|
array( |
|
26
|
|
|
'u__id' => '1', |
|
27
|
|
|
'u__name' => 'Fabio B. Silva' |
|
28
|
|
|
), |
|
29
|
|
|
); |
|
30
|
|
|
|
|
31
|
|
|
$stmt = new HydratorMockStatement($resultSet); |
|
32
|
|
|
$hydrator = new \Doctrine\ORM\Internal\Hydration\SimpleObjectHydrator($this->_em); |
|
33
|
|
|
$hydrator->hydrateAll($stmt, $rsm); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function testExtraFieldInResultSetShouldBeIgnore() |
|
37
|
|
|
{ |
|
38
|
|
|
$rsm = new ResultSetMapping; |
|
39
|
|
|
$rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsAddress', 'a'); |
|
40
|
|
|
$rsm->addFieldResult('a', 'a__id', 'id'); |
|
41
|
|
|
$rsm->addFieldResult('a', 'a__city', 'city'); |
|
42
|
|
|
$resultSet = array( |
|
43
|
|
|
array( |
|
44
|
|
|
'a__id' => '1', |
|
45
|
|
|
'a__city' => 'Cracow', |
|
46
|
|
|
'doctrine_rownum' => '1' |
|
47
|
|
|
), |
|
48
|
|
|
); |
|
49
|
|
|
|
|
50
|
|
|
$expectedEntity = new \Doctrine\Tests\Models\CMS\CmsAddress(); |
|
51
|
|
|
$expectedEntity->id = 1; |
|
52
|
|
|
$expectedEntity->city = 'Cracow'; |
|
53
|
|
|
|
|
54
|
|
|
$stmt = new HydratorMockStatement($resultSet); |
|
55
|
|
|
$hydrator = new \Doctrine\ORM\Internal\Hydration\SimpleObjectHydrator($this->_em); |
|
56
|
|
|
$result = $hydrator->hydrateAll($stmt, $rsm); |
|
57
|
|
|
$this->assertEquals($result[0], $expectedEntity); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @group DDC-3076 |
|
62
|
|
|
* |
|
63
|
|
|
* @expectedException \Doctrine\ORM\Internal\Hydration\HydrationException |
|
64
|
|
|
* @expectedExceptionMessage The discriminator value "subworker" is invalid. It must be one of "person", "manager", "employee". |
|
65
|
|
|
*/ |
|
66
|
|
|
public function testInvalidDiscriminatorValueException() |
|
67
|
|
|
{ |
|
68
|
|
|
$rsm = new ResultSetMapping; |
|
69
|
|
|
|
|
70
|
|
|
$rsm->addEntityResult('Doctrine\Tests\Models\Company\CompanyPerson', 'p'); |
|
71
|
|
|
|
|
72
|
|
|
$rsm->addFieldResult('p', 'p__id', 'id'); |
|
73
|
|
|
$rsm->addFieldResult('p', 'p__name', 'name'); |
|
74
|
|
|
$rsm->addMetaResult('p', 'discr', 'discr', false, 'string'); |
|
75
|
|
|
$rsm->setDiscriminatorColumn('p', 'discr'); |
|
76
|
|
|
|
|
77
|
|
|
$resultSet = array( |
|
78
|
|
|
array( |
|
79
|
|
|
'p__id' => '1', |
|
80
|
|
|
'p__name' => 'Fabio B. Silva', |
|
81
|
|
|
'discr' => 'subworker' |
|
82
|
|
|
), |
|
83
|
|
|
); |
|
84
|
|
|
|
|
85
|
|
|
$stmt = new HydratorMockStatement($resultSet); |
|
86
|
|
|
$hydrator = new \Doctrine\ORM\Internal\Hydration\SimpleObjectHydrator($this->_em); |
|
87
|
|
|
$hydrator->hydrateAll($stmt, $rsm); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @group issue-5989 |
|
92
|
|
|
*/ |
|
93
|
|
|
public function testNullValueShouldNotOverwriteFieldWithSameNameInJoinedInheritance() |
|
94
|
|
|
{ |
|
95
|
|
|
$rsm = new ResultSetMapping; |
|
96
|
|
|
$rsm->addEntityResult('Doctrine\Tests\Models\Issue5989\Issue5989Person', 'p'); |
|
97
|
|
|
$rsm->addFieldResult('p', 'p__id', 'id'); |
|
98
|
|
|
$rsm->addFieldResult('p', 'm__tags', 'tags', 'Doctrine\Tests\Models\Issue5989\Issue5989Manager'); |
|
99
|
|
|
$rsm->addFieldResult('p', 'e__tags', 'tags', 'Doctrine\Tests\Models\Issue5989\Issue5989Employee'); |
|
100
|
|
|
$rsm->addMetaResult('p', 'discr', 'discr', false, 'string'); |
|
101
|
|
|
$resultSet = array( |
|
102
|
|
|
array( |
|
103
|
|
|
'p__id' => '1', |
|
104
|
|
|
'm__tags' => 'tag1,tag2', |
|
105
|
|
|
'e__tags' => null, |
|
106
|
|
|
'discr' => 'manager' |
|
107
|
|
|
), |
|
108
|
|
|
); |
|
109
|
|
|
|
|
110
|
|
|
$expectedEntity = new \Doctrine\Tests\Models\Issue5989\Issue5989Manager(); |
|
111
|
|
|
$expectedEntity->id = 1; |
|
112
|
|
|
$expectedEntity->tags = ['tag1', 'tag2']; |
|
113
|
|
|
|
|
114
|
|
|
$stmt = new HydratorMockStatement($resultSet); |
|
115
|
|
|
$hydrator = new \Doctrine\ORM\Internal\Hydration\SimpleObjectHydrator($this->_em); |
|
116
|
|
|
$result = $hydrator->hydrateAll($stmt, $rsm); |
|
117
|
|
|
$this->assertEquals($result[0], $expectedEntity); |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|