|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\ORM\Mapping; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\Common\Persistence\Mapping\RuntimeReflectionService; |
|
6
|
|
|
use Doctrine\Common\Persistence\Mapping\StaticReflectionService; |
|
7
|
|
|
use Doctrine\ORM\Mapping\ClassMetadata; |
|
8
|
|
|
use Doctrine\ORM\Events; |
|
9
|
|
|
use Doctrine\ORM\Mapping\DefaultNamingStrategy; |
|
10
|
|
|
|
|
11
|
|
|
require_once __DIR__ . '/../../Models/Global/GlobalNamespaceModel.php'; |
|
12
|
|
|
|
|
13
|
|
|
class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase |
|
14
|
|
|
{ |
|
15
|
|
|
public function testClassMetadataInstanceSerialization() |
|
16
|
|
|
{ |
|
17
|
|
|
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); |
|
18
|
|
|
$cm->initializeReflection(new RuntimeReflectionService()); |
|
19
|
|
|
|
|
20
|
|
|
// Test initial state |
|
21
|
|
|
$this->assertTrue(count($cm->getReflectionProperties()) == 0); |
|
22
|
|
|
$this->assertInstanceOf('ReflectionClass', $cm->reflClass); |
|
23
|
|
|
$this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $cm->name); |
|
24
|
|
|
$this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $cm->rootEntityName); |
|
25
|
|
|
$this->assertEquals(array(), $cm->subClasses); |
|
26
|
|
|
$this->assertEquals(array(), $cm->parentClasses); |
|
27
|
|
|
$this->assertEquals(ClassMetadata::INHERITANCE_TYPE_NONE, $cm->inheritanceType); |
|
28
|
|
|
|
|
29
|
|
|
// Customize state |
|
30
|
|
|
$cm->setInheritanceType(ClassMetadata::INHERITANCE_TYPE_SINGLE_TABLE); |
|
31
|
|
|
$cm->setSubclasses(array("One", "Two", "Three")); |
|
32
|
|
|
$cm->setParentClasses(array("UserParent")); |
|
33
|
|
|
$cm->setCustomRepositoryClass("UserRepository"); |
|
34
|
|
|
$cm->setDiscriminatorColumn(array('name' => 'disc', 'type' => 'integer')); |
|
35
|
|
|
$cm->mapOneToOne(array('fieldName' => 'phonenumbers', 'targetEntity' => 'CmsAddress', 'mappedBy' => 'foo')); |
|
36
|
|
|
$cm->markReadOnly(); |
|
37
|
|
|
$cm->addNamedQuery(array('name' => 'dql', 'query' => 'foo')); |
|
38
|
|
|
$this->assertEquals(1, count($cm->associationMappings)); |
|
39
|
|
|
|
|
40
|
|
|
$serialized = serialize($cm); |
|
41
|
|
|
$cm = unserialize($serialized); |
|
42
|
|
|
$cm->wakeupReflection(new RuntimeReflectionService()); |
|
43
|
|
|
|
|
44
|
|
|
// Check state |
|
45
|
|
|
$this->assertTrue(count($cm->getReflectionProperties()) > 0); |
|
46
|
|
|
$this->assertEquals('Doctrine\Tests\Models\CMS', $cm->namespace); |
|
47
|
|
|
$this->assertInstanceOf('ReflectionClass', $cm->reflClass); |
|
48
|
|
|
$this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $cm->name); |
|
49
|
|
|
$this->assertEquals('UserParent', $cm->rootEntityName); |
|
50
|
|
|
$this->assertEquals(array('Doctrine\Tests\Models\CMS\One', 'Doctrine\Tests\Models\CMS\Two', 'Doctrine\Tests\Models\CMS\Three'), $cm->subClasses); |
|
51
|
|
|
$this->assertEquals(array('UserParent'), $cm->parentClasses); |
|
52
|
|
|
$this->assertEquals('Doctrine\Tests\Models\CMS\UserRepository', $cm->customRepositoryClassName); |
|
53
|
|
|
$this->assertEquals(array('name' => 'disc', 'type' => 'integer', 'fieldName' => 'disc'), $cm->discriminatorColumn); |
|
54
|
|
|
$this->assertTrue($cm->associationMappings['phonenumbers']['type'] == ClassMetadata::ONE_TO_ONE); |
|
55
|
|
|
$this->assertEquals(1, count($cm->associationMappings)); |
|
56
|
|
|
$oneOneMapping = $cm->getAssociationMapping('phonenumbers'); |
|
57
|
|
|
$this->assertTrue($oneOneMapping['fetch'] == ClassMetadata::FETCH_LAZY); |
|
58
|
|
|
$this->assertEquals('phonenumbers', $oneOneMapping['fieldName']); |
|
59
|
|
|
$this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddress', $oneOneMapping['targetEntity']); |
|
60
|
|
|
$this->assertTrue($cm->isReadOnly); |
|
61
|
|
|
$this->assertEquals(array('dql' => array('name'=>'dql','query'=>'foo','dql'=>'foo')), $cm->namedQueries); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function testFieldIsNullable() |
|
65
|
|
|
{ |
|
66
|
|
|
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); |
|
67
|
|
|
$cm->initializeReflection(new RuntimeReflectionService()); |
|
68
|
|
|
|
|
69
|
|
|
// Explicit Nullable |
|
70
|
|
|
$cm->mapField(array('fieldName' => 'status', 'nullable' => true, 'type' => 'string', 'length' => 50)); |
|
71
|
|
|
$this->assertTrue($cm->isNullable('status')); |
|
72
|
|
|
|
|
73
|
|
|
// Explicit Not Nullable |
|
74
|
|
|
$cm->mapField(array('fieldName' => 'username', 'nullable' => false, 'type' => 'string', 'length' => 50)); |
|
75
|
|
|
$this->assertFalse($cm->isNullable('username')); |
|
76
|
|
|
|
|
77
|
|
|
// Implicit Not Nullable |
|
78
|
|
|
$cm->mapField(array('fieldName' => 'name', 'type' => 'string', 'length' => 50)); |
|
79
|
|
|
$this->assertFalse($cm->isNullable('name'), "By default a field should not be nullable."); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @group DDC-115 |
|
84
|
|
|
*/ |
|
85
|
|
|
public function testMapAssociationInGlobalNamespace() |
|
86
|
|
|
{ |
|
87
|
|
|
require_once __DIR__."/../../Models/Global/GlobalNamespaceModel.php"; |
|
88
|
|
|
|
|
89
|
|
|
$cm = new ClassMetadata('DoctrineGlobal_Article'); |
|
90
|
|
|
$cm->initializeReflection(new RuntimeReflectionService()); |
|
91
|
|
|
$cm->mapManyToMany(array( |
|
92
|
|
|
'fieldName' => 'author', |
|
93
|
|
|
'targetEntity' => 'DoctrineGlobal_User', |
|
94
|
|
|
'joinTable' => array( |
|
95
|
|
|
'name' => 'bar', |
|
96
|
|
|
'joinColumns' => array(array('name' => 'bar_id', 'referencedColumnName' => 'id')), |
|
97
|
|
|
'inverseJoinColumns' => array(array('name' => 'baz_id', 'referencedColumnName' => 'id')), |
|
98
|
|
|
), |
|
99
|
|
|
)); |
|
100
|
|
|
|
|
101
|
|
|
$this->assertEquals("DoctrineGlobal_User", $cm->associationMappings['author']['targetEntity']); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
public function testMapManyToManyJoinTableDefaults() |
|
105
|
|
|
{ |
|
106
|
|
|
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); |
|
107
|
|
|
$cm->initializeReflection(new RuntimeReflectionService()); |
|
108
|
|
|
$cm->mapManyToMany( |
|
109
|
|
|
array( |
|
110
|
|
|
'fieldName' => 'groups', |
|
111
|
|
|
'targetEntity' => 'CmsGroup' |
|
112
|
|
|
)); |
|
113
|
|
|
|
|
114
|
|
|
$assoc = $cm->associationMappings['groups']; |
|
115
|
|
|
//$this->assertInstanceOf('Doctrine\ORM\Mapping\ManyToManyMapping', $assoc); |
|
116
|
|
|
$this->assertEquals(array( |
|
117
|
|
|
'name' => 'cmsuser_cmsgroup', |
|
118
|
|
|
'joinColumns' => array(array('name' => 'cmsuser_id', 'referencedColumnName' => 'id', 'onDelete' => 'CASCADE')), |
|
119
|
|
|
'inverseJoinColumns' => array(array('name' => 'cmsgroup_id', 'referencedColumnName' => 'id', 'onDelete' => 'CASCADE')) |
|
120
|
|
|
), $assoc['joinTable']); |
|
121
|
|
|
$this->assertTrue($assoc['isOnDeleteCascade']); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
public function testSerializeManyToManyJoinTableCascade() |
|
125
|
|
|
{ |
|
126
|
|
|
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); |
|
127
|
|
|
$cm->initializeReflection(new RuntimeReflectionService()); |
|
128
|
|
|
$cm->mapManyToMany( |
|
129
|
|
|
array( |
|
130
|
|
|
'fieldName' => 'groups', |
|
131
|
|
|
'targetEntity' => 'CmsGroup' |
|
132
|
|
|
)); |
|
133
|
|
|
|
|
134
|
|
|
/* @var $assoc \Doctrine\ORM\Mapping\ManyToManyMapping */ |
|
135
|
|
|
$assoc = $cm->associationMappings['groups']; |
|
136
|
|
|
$assoc = unserialize(serialize($assoc)); |
|
137
|
|
|
|
|
138
|
|
|
$this->assertTrue($assoc['isOnDeleteCascade']); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* @group DDC-115 |
|
143
|
|
|
*/ |
|
144
|
|
|
public function testSetDiscriminatorMapInGlobalNamespace() |
|
145
|
|
|
{ |
|
146
|
|
|
require_once __DIR__."/../../Models/Global/GlobalNamespaceModel.php"; |
|
147
|
|
|
|
|
148
|
|
|
$cm = new ClassMetadata('DoctrineGlobal_User'); |
|
149
|
|
|
$cm->initializeReflection(new RuntimeReflectionService()); |
|
150
|
|
|
$cm->setDiscriminatorMap(array('descr' => 'DoctrineGlobal_Article', 'foo' => 'DoctrineGlobal_User')); |
|
151
|
|
|
|
|
152
|
|
|
$this->assertEquals("DoctrineGlobal_Article", $cm->discriminatorMap['descr']); |
|
153
|
|
|
$this->assertEquals("DoctrineGlobal_User", $cm->discriminatorMap['foo']); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* @group DDC-115 |
|
158
|
|
|
*/ |
|
159
|
|
|
public function testSetSubClassesInGlobalNamespace() |
|
160
|
|
|
{ |
|
161
|
|
|
require_once __DIR__."/../../Models/Global/GlobalNamespaceModel.php"; |
|
162
|
|
|
|
|
163
|
|
|
$cm = new ClassMetadata('DoctrineGlobal_User'); |
|
164
|
|
|
$cm->initializeReflection(new RuntimeReflectionService()); |
|
165
|
|
|
$cm->setSubclasses(array('DoctrineGlobal_Article')); |
|
166
|
|
|
|
|
167
|
|
|
$this->assertEquals("DoctrineGlobal_Article", $cm->subClasses[0]); |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
/** |
|
171
|
|
|
* @group DDC-268 |
|
172
|
|
|
*/ |
|
173
|
|
|
public function testSetInvalidVersionMapping_ThrowsException() |
|
174
|
|
|
{ |
|
175
|
|
|
$field = array(); |
|
176
|
|
|
$field['fieldName'] = 'foo'; |
|
177
|
|
|
$field['type'] = 'string'; |
|
178
|
|
|
|
|
179
|
|
|
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); |
|
180
|
|
|
$cm->initializeReflection(new RuntimeReflectionService()); |
|
181
|
|
|
|
|
182
|
|
|
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); |
|
183
|
|
|
$cm->setVersionMapping($field); |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
public function testGetSingleIdentifierFieldName_MultipleIdentifierEntity_ThrowsException() |
|
187
|
|
|
{ |
|
188
|
|
|
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); |
|
189
|
|
|
$cm->initializeReflection(new RuntimeReflectionService()); |
|
190
|
|
|
$cm->isIdentifierComposite = true; |
|
191
|
|
|
|
|
192
|
|
|
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); |
|
193
|
|
|
$cm->getSingleIdentifierFieldName(); |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
|
|
public function testDuplicateAssociationMappingException() |
|
197
|
|
|
{ |
|
198
|
|
|
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); |
|
199
|
|
|
$cm->initializeReflection(new RuntimeReflectionService()); |
|
200
|
|
|
|
|
201
|
|
|
$a1 = array('fieldName' => 'foo', 'sourceEntity' => 'stdClass', 'targetEntity' => 'stdClass', 'mappedBy' => 'foo'); |
|
202
|
|
|
$a2 = array('fieldName' => 'foo', 'sourceEntity' => 'stdClass', 'targetEntity' => 'stdClass', 'mappedBy' => 'foo'); |
|
203
|
|
|
|
|
204
|
|
|
$cm->addInheritedAssociationMapping($a1); |
|
205
|
|
|
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); |
|
206
|
|
|
$cm->addInheritedAssociationMapping($a2); |
|
207
|
|
|
} |
|
208
|
|
|
|
|
209
|
|
|
public function testDuplicateColumnName_ThrowsMappingException() |
|
210
|
|
|
{ |
|
211
|
|
|
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); |
|
212
|
|
|
$cm->initializeReflection(new RuntimeReflectionService()); |
|
213
|
|
|
|
|
214
|
|
|
$cm->mapField(array('fieldName' => 'name', 'columnName' => 'name')); |
|
215
|
|
|
|
|
216
|
|
|
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); |
|
217
|
|
|
$cm->mapField(array('fieldName' => 'username', 'columnName' => 'name')); |
|
218
|
|
|
} |
|
219
|
|
|
|
|
220
|
|
|
public function testDuplicateColumnName_DiscriminatorColumn_ThrowsMappingException() |
|
221
|
|
|
{ |
|
222
|
|
|
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); |
|
223
|
|
|
$cm->initializeReflection(new RuntimeReflectionService()); |
|
224
|
|
|
|
|
225
|
|
|
$cm->mapField(array('fieldName' => 'name', 'columnName' => 'name')); |
|
226
|
|
|
|
|
227
|
|
|
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); |
|
228
|
|
|
$cm->setDiscriminatorColumn(array('name' => 'name')); |
|
229
|
|
|
} |
|
230
|
|
|
|
|
231
|
|
|
public function testDuplicateColumnName_DiscriminatorColumn2_ThrowsMappingException() |
|
232
|
|
|
{ |
|
233
|
|
|
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); |
|
234
|
|
|
$cm->initializeReflection(new RuntimeReflectionService()); |
|
235
|
|
|
|
|
236
|
|
|
$cm->setDiscriminatorColumn(array('name' => 'name')); |
|
237
|
|
|
|
|
238
|
|
|
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); |
|
239
|
|
|
$cm->mapField(array('fieldName' => 'name', 'columnName' => 'name')); |
|
240
|
|
|
} |
|
241
|
|
|
|
|
242
|
|
|
public function testDuplicateFieldAndAssociationMapping1_ThrowsException() |
|
243
|
|
|
{ |
|
244
|
|
|
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); |
|
245
|
|
|
$cm->initializeReflection(new RuntimeReflectionService()); |
|
246
|
|
|
|
|
247
|
|
|
$cm->mapField(array('fieldName' => 'name', 'columnName' => 'name')); |
|
248
|
|
|
|
|
249
|
|
|
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); |
|
250
|
|
|
$cm->mapOneToOne(array('fieldName' => 'name', 'targetEntity' => 'CmsUser')); |
|
251
|
|
|
} |
|
252
|
|
|
|
|
253
|
|
|
public function testDuplicateFieldAndAssociationMapping2_ThrowsException() |
|
254
|
|
|
{ |
|
255
|
|
|
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); |
|
256
|
|
|
$cm->initializeReflection(new RuntimeReflectionService()); |
|
257
|
|
|
|
|
258
|
|
|
$cm->mapOneToOne(array('fieldName' => 'name', 'targetEntity' => 'CmsUser')); |
|
259
|
|
|
|
|
260
|
|
|
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); |
|
261
|
|
|
$cm->mapField(array('fieldName' => 'name', 'columnName' => 'name')); |
|
262
|
|
|
} |
|
263
|
|
|
|
|
264
|
|
|
/** |
|
265
|
|
|
* @group DDC-1224 |
|
266
|
|
|
*/ |
|
267
|
|
|
public function testGetTemporaryTableNameSchema() |
|
268
|
|
|
{ |
|
269
|
|
|
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); |
|
270
|
|
|
$cm->initializeReflection(new RuntimeReflectionService()); |
|
271
|
|
|
|
|
272
|
|
|
$cm->setTableName('foo.bar'); |
|
|
|
|
|
|
273
|
|
|
|
|
274
|
|
|
$this->assertEquals('foo_bar_id_tmp', $cm->getTemporaryIdTableName()); |
|
275
|
|
|
} |
|
276
|
|
|
|
|
277
|
|
|
public function testDefaultTableName() |
|
278
|
|
|
{ |
|
279
|
|
|
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); |
|
280
|
|
|
$cm->initializeReflection(new RuntimeReflectionService()); |
|
281
|
|
|
|
|
282
|
|
|
// When table's name is not given |
|
283
|
|
|
$primaryTable = array(); |
|
284
|
|
|
$cm->setPrimaryTable($primaryTable); |
|
285
|
|
|
|
|
286
|
|
|
$this->assertEquals('CmsUser', $cm->getTableName()); |
|
287
|
|
|
$this->assertEquals('CmsUser', $cm->table['name']); |
|
288
|
|
|
|
|
289
|
|
|
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'); |
|
290
|
|
|
$cm->initializeReflection(new RuntimeReflectionService()); |
|
291
|
|
|
// When joinTable's name is not given |
|
292
|
|
|
$cm->mapManyToMany(array( |
|
293
|
|
|
'fieldName' => 'user', |
|
294
|
|
|
'targetEntity' => 'CmsUser', |
|
295
|
|
|
'inversedBy' => 'users', |
|
296
|
|
|
'joinTable' => array('joinColumns' => array(array('referencedColumnName' => 'id')), |
|
297
|
|
|
'inverseJoinColumns' => array(array('referencedColumnName' => 'id'))))); |
|
298
|
|
|
$this->assertEquals('cmsaddress_cmsuser', $cm->associationMappings['user']['joinTable']['name']); |
|
299
|
|
|
} |
|
300
|
|
|
|
|
301
|
|
|
public function testDefaultJoinColumnName() |
|
302
|
|
|
{ |
|
303
|
|
|
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'); |
|
304
|
|
|
$cm->initializeReflection(new RuntimeReflectionService()); |
|
305
|
|
|
|
|
306
|
|
|
// this is really dirty, but it's the simplest way to test whether |
|
307
|
|
|
// joinColumn's name will be automatically set to user_id |
|
308
|
|
|
$cm->mapOneToOne(array( |
|
309
|
|
|
'fieldName' => 'user', |
|
310
|
|
|
'targetEntity' => 'CmsUser', |
|
311
|
|
|
'joinColumns' => array(array('referencedColumnName' => 'id')))); |
|
312
|
|
|
$this->assertEquals('user_id', $cm->associationMappings['user']['joinColumns'][0]['name']); |
|
313
|
|
|
|
|
314
|
|
|
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'); |
|
315
|
|
|
$cm->initializeReflection(new RuntimeReflectionService()); |
|
316
|
|
|
$cm->mapManyToMany(array( |
|
317
|
|
|
'fieldName' => 'user', |
|
318
|
|
|
'targetEntity' => 'CmsUser', |
|
319
|
|
|
'inversedBy' => 'users', |
|
320
|
|
|
'joinTable' => array('name' => 'user_CmsUser', |
|
321
|
|
|
'joinColumns' => array(array('referencedColumnName' => 'id')), |
|
322
|
|
|
'inverseJoinColumns' => array(array('referencedColumnName' => 'id'))))); |
|
323
|
|
|
$this->assertEquals('cmsaddress_id', $cm->associationMappings['user']['joinTable']['joinColumns'][0]['name']); |
|
324
|
|
|
$this->assertEquals('cmsuser_id', $cm->associationMappings['user']['joinTable']['inverseJoinColumns'][0]['name']); |
|
325
|
|
|
} |
|
326
|
|
|
|
|
327
|
|
|
/** |
|
328
|
|
|
* @group DDC-559 |
|
329
|
|
|
*/ |
|
330
|
|
|
public function testUnderscoreNamingStrategyDefaults() |
|
331
|
|
|
{ |
|
332
|
|
|
$namingStrategy = new \Doctrine\ORM\Mapping\UnderscoreNamingStrategy(CASE_UPPER); |
|
333
|
|
|
$oneToOneMetadata = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress', $namingStrategy); |
|
334
|
|
|
$manyToManyMetadata = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress', $namingStrategy); |
|
335
|
|
|
|
|
336
|
|
|
$oneToOneMetadata->mapOneToOne(array( |
|
337
|
|
|
'fieldName' => 'user', |
|
338
|
|
|
'targetEntity' => 'CmsUser' |
|
339
|
|
|
)); |
|
340
|
|
|
|
|
341
|
|
|
$manyToManyMetadata->mapManyToMany(array( |
|
342
|
|
|
'fieldName' => 'user', |
|
343
|
|
|
'targetEntity' => 'CmsUser' |
|
344
|
|
|
)); |
|
345
|
|
|
|
|
346
|
|
|
$this->assertEquals(array('USER_ID'=>'ID'), $oneToOneMetadata->associationMappings['user']['sourceToTargetKeyColumns']); |
|
347
|
|
|
$this->assertEquals(array('USER_ID'=>'USER_ID'), $oneToOneMetadata->associationMappings['user']['joinColumnFieldNames']); |
|
348
|
|
|
$this->assertEquals(array('ID'=>'USER_ID'), $oneToOneMetadata->associationMappings['user']['targetToSourceKeyColumns']); |
|
349
|
|
|
|
|
350
|
|
|
$this->assertEquals('USER_ID', $oneToOneMetadata->associationMappings['user']['joinColumns'][0]['name']); |
|
351
|
|
|
$this->assertEquals('ID', $oneToOneMetadata->associationMappings['user']['joinColumns'][0]['referencedColumnName']); |
|
352
|
|
|
|
|
353
|
|
|
|
|
354
|
|
|
$this->assertEquals('CMS_ADDRESS_CMS_USER', $manyToManyMetadata->associationMappings['user']['joinTable']['name']); |
|
355
|
|
|
|
|
356
|
|
|
$this->assertEquals(array('CMS_ADDRESS_ID','CMS_USER_ID'), $manyToManyMetadata->associationMappings['user']['joinTableColumns']); |
|
357
|
|
|
$this->assertEquals(array('CMS_ADDRESS_ID'=>'ID'), $manyToManyMetadata->associationMappings['user']['relationToSourceKeyColumns']); |
|
358
|
|
|
$this->assertEquals(array('CMS_USER_ID'=>'ID'), $manyToManyMetadata->associationMappings['user']['relationToTargetKeyColumns']); |
|
359
|
|
|
|
|
360
|
|
|
$this->assertEquals('CMS_ADDRESS_ID', $manyToManyMetadata->associationMappings['user']['joinTable']['joinColumns'][0]['name']); |
|
361
|
|
|
$this->assertEquals('CMS_USER_ID', $manyToManyMetadata->associationMappings['user']['joinTable']['inverseJoinColumns'][0]['name']); |
|
362
|
|
|
|
|
363
|
|
|
$this->assertEquals('ID', $manyToManyMetadata->associationMappings['user']['joinTable']['joinColumns'][0]['referencedColumnName']); |
|
364
|
|
|
$this->assertEquals('ID', $manyToManyMetadata->associationMappings['user']['joinTable']['inverseJoinColumns'][0]['referencedColumnName']); |
|
365
|
|
|
|
|
366
|
|
|
|
|
367
|
|
|
$cm = new ClassMetadata('DoctrineGlobal_Article', $namingStrategy); |
|
368
|
|
|
$cm->mapManyToMany(array('fieldName' => 'author', 'targetEntity' => 'Doctrine\Tests\Models\CMS\CmsUser')); |
|
369
|
|
|
$this->assertEquals('DOCTRINE_GLOBAL_ARTICLE_CMS_USER', $cm->associationMappings['author']['joinTable']['name']); |
|
370
|
|
|
} |
|
371
|
|
|
|
|
372
|
|
|
/** |
|
373
|
|
|
* @group DDC-886 |
|
374
|
|
|
*/ |
|
375
|
|
|
public function testSetMultipleIdentifierSetsComposite() |
|
376
|
|
|
{ |
|
377
|
|
|
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); |
|
378
|
|
|
$cm->initializeReflection(new RuntimeReflectionService()); |
|
379
|
|
|
|
|
380
|
|
|
$cm->mapField(array('fieldName' => 'name')); |
|
381
|
|
|
$cm->mapField(array('fieldName' => 'username')); |
|
382
|
|
|
|
|
383
|
|
|
$cm->setIdentifier(array('name', 'username')); |
|
384
|
|
|
$this->assertTrue($cm->isIdentifierComposite); |
|
385
|
|
|
} |
|
386
|
|
|
|
|
387
|
|
|
/** |
|
388
|
|
|
* @group DDC-944 |
|
389
|
|
|
*/ |
|
390
|
|
|
public function testMappingNotFound() |
|
391
|
|
|
{ |
|
392
|
|
|
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); |
|
393
|
|
|
$cm->initializeReflection(new RuntimeReflectionService()); |
|
394
|
|
|
|
|
395
|
|
|
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException', "No mapping found for field 'foo' on class 'Doctrine\Tests\Models\CMS\CmsUser'."); |
|
396
|
|
|
$cm->getFieldMapping('foo'); |
|
397
|
|
|
} |
|
398
|
|
|
|
|
399
|
|
|
/** |
|
400
|
|
|
* @group DDC-961 |
|
401
|
|
|
*/ |
|
402
|
|
|
public function testJoinTableMappingDefaults() |
|
403
|
|
|
{ |
|
404
|
|
|
$cm = new ClassMetadata('DoctrineGlobal_Article'); |
|
405
|
|
|
$cm->initializeReflection(new RuntimeReflectionService()); |
|
406
|
|
|
|
|
407
|
|
|
$cm->mapManyToMany(array('fieldName' => 'author', 'targetEntity' => 'Doctrine\Tests\Models\CMS\CmsUser')); |
|
408
|
|
|
|
|
409
|
|
|
$this->assertEquals('doctrineglobal_article_cmsuser', $cm->associationMappings['author']['joinTable']['name']); |
|
410
|
|
|
} |
|
411
|
|
|
|
|
412
|
|
|
/** |
|
413
|
|
|
* @group DDC-117 |
|
414
|
|
|
*/ |
|
415
|
|
|
public function testMapIdentifierAssociation() |
|
416
|
|
|
{ |
|
417
|
|
|
$cm = new ClassMetadata('Doctrine\Tests\Models\DDC117\DDC117ArticleDetails'); |
|
418
|
|
|
$cm->initializeReflection(new RuntimeReflectionService()); |
|
419
|
|
|
|
|
420
|
|
|
$cm->mapOneToOne(array( |
|
421
|
|
|
'fieldName' => 'article', |
|
422
|
|
|
'id' => true, |
|
423
|
|
|
'targetEntity' => 'Doctrine\Tests\Models\DDC117\DDC117Article', |
|
424
|
|
|
'joinColumns' => array(), |
|
425
|
|
|
)); |
|
426
|
|
|
|
|
427
|
|
|
$this->assertTrue($cm->containsForeignIdentifier, "Identifier Association should set 'containsForeignIdentifier' boolean flag."); |
|
428
|
|
|
$this->assertEquals(array("article"), $cm->identifier); |
|
429
|
|
|
} |
|
430
|
|
|
|
|
431
|
|
|
/** |
|
432
|
|
|
* @group DDC-117 |
|
433
|
|
|
*/ |
|
434
|
|
|
public function testOrphanRemovalIdentifierAssociation() |
|
435
|
|
|
{ |
|
436
|
|
|
$cm = new ClassMetadata('Doctrine\Tests\Models\DDC117\DDC117ArticleDetails'); |
|
437
|
|
|
$cm->initializeReflection(new RuntimeReflectionService()); |
|
438
|
|
|
|
|
439
|
|
|
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException', 'The orphan removal option is not allowed on an association that'); |
|
440
|
|
|
$cm->mapOneToOne(array( |
|
441
|
|
|
'fieldName' => 'article', |
|
442
|
|
|
'id' => true, |
|
443
|
|
|
'targetEntity' => 'Doctrine\Tests\Models\DDC117\DDC117Article', |
|
444
|
|
|
'orphanRemoval' => true, |
|
445
|
|
|
'joinColumns' => array(), |
|
446
|
|
|
)); |
|
447
|
|
|
} |
|
448
|
|
|
|
|
449
|
|
|
/** |
|
450
|
|
|
* @group DDC-117 |
|
451
|
|
|
*/ |
|
452
|
|
|
public function testInverseIdentifierAssociation() |
|
453
|
|
|
{ |
|
454
|
|
|
$cm = new ClassMetadata('Doctrine\Tests\Models\DDC117\DDC117ArticleDetails'); |
|
455
|
|
|
$cm->initializeReflection(new RuntimeReflectionService()); |
|
456
|
|
|
|
|
457
|
|
|
|
|
458
|
|
|
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException', 'An inverse association is not allowed to be identifier in'); |
|
459
|
|
|
$cm->mapOneToOne(array( |
|
460
|
|
|
'fieldName' => 'article', |
|
461
|
|
|
'id' => true, |
|
462
|
|
|
'mappedBy' => 'details', // INVERSE! |
|
463
|
|
|
'targetEntity' => 'Doctrine\Tests\Models\DDC117\DDC117Article', |
|
464
|
|
|
'joinColumns' => array(), |
|
465
|
|
|
)); |
|
466
|
|
|
} |
|
467
|
|
|
|
|
468
|
|
|
/** |
|
469
|
|
|
* @group DDC-117 |
|
470
|
|
|
*/ |
|
471
|
|
|
public function testIdentifierAssociationManyToMany() |
|
472
|
|
|
{ |
|
473
|
|
|
$cm = new ClassMetadata('Doctrine\Tests\Models\DDC117\DDC117ArticleDetails'); |
|
474
|
|
|
$cm->initializeReflection(new RuntimeReflectionService()); |
|
475
|
|
|
|
|
476
|
|
|
|
|
477
|
|
|
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException', 'Many-to-many or one-to-many associations are not allowed to be identifier in'); |
|
478
|
|
|
$cm->mapManyToMany(array( |
|
479
|
|
|
'fieldName' => 'article', |
|
480
|
|
|
'id' => true, |
|
481
|
|
|
'targetEntity' => 'Doctrine\Tests\Models\DDC117\DDC117Article', |
|
482
|
|
|
'joinColumns' => array(), |
|
483
|
|
|
)); |
|
484
|
|
|
} |
|
485
|
|
|
|
|
486
|
|
|
/** |
|
487
|
|
|
* @group DDC-996 |
|
488
|
|
|
*/ |
|
489
|
|
|
public function testEmptyFieldNameThrowsException() |
|
490
|
|
|
{ |
|
491
|
|
|
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException', |
|
492
|
|
|
"The field or association mapping misses the 'fieldName' attribute in entity 'Doctrine\Tests\Models\CMS\CmsUser'."); |
|
493
|
|
|
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); |
|
494
|
|
|
$cm->initializeReflection(new RuntimeReflectionService()); |
|
495
|
|
|
|
|
496
|
|
|
$cm->mapField(array('fieldName' => '')); |
|
497
|
|
|
} |
|
498
|
|
|
|
|
499
|
|
|
public function testRetrievalOfNamedQueries() |
|
500
|
|
|
{ |
|
501
|
|
|
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); |
|
502
|
|
|
$cm->initializeReflection(new RuntimeReflectionService()); |
|
503
|
|
|
|
|
504
|
|
|
|
|
505
|
|
|
$this->assertEquals(0, count($cm->getNamedQueries())); |
|
506
|
|
|
|
|
507
|
|
|
$cm->addNamedQuery(array( |
|
508
|
|
|
'name' => 'userById', |
|
509
|
|
|
'query' => 'SELECT u FROM __CLASS__ u WHERE u.id = ?1' |
|
510
|
|
|
)); |
|
511
|
|
|
|
|
512
|
|
|
$this->assertEquals(1, count($cm->getNamedQueries())); |
|
513
|
|
|
} |
|
514
|
|
|
|
|
515
|
|
|
/** |
|
516
|
|
|
* @group DDC-1663 |
|
517
|
|
|
*/ |
|
518
|
|
|
public function testRetrievalOfResultSetMappings() |
|
519
|
|
|
{ |
|
520
|
|
|
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); |
|
521
|
|
|
$cm->initializeReflection(new RuntimeReflectionService()); |
|
522
|
|
|
|
|
523
|
|
|
|
|
524
|
|
|
$this->assertEquals(0, count($cm->getSqlResultSetMappings())); |
|
525
|
|
|
|
|
526
|
|
|
$cm->addSqlResultSetMapping(array( |
|
527
|
|
|
'name' => 'find-all', |
|
528
|
|
|
'entities' => array( |
|
529
|
|
|
array( |
|
530
|
|
|
'entityClass' => 'Doctrine\Tests\Models\CMS\CmsUser', |
|
531
|
|
|
), |
|
532
|
|
|
), |
|
533
|
|
|
)); |
|
534
|
|
|
|
|
535
|
|
|
$this->assertEquals(1, count($cm->getSqlResultSetMappings())); |
|
536
|
|
|
} |
|
537
|
|
|
|
|
538
|
|
|
public function testExistanceOfNamedQuery() |
|
539
|
|
|
{ |
|
540
|
|
|
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); |
|
541
|
|
|
$cm->initializeReflection(new RuntimeReflectionService()); |
|
542
|
|
|
|
|
543
|
|
|
|
|
544
|
|
|
$cm->addNamedQuery(array( |
|
545
|
|
|
'name' => 'all', |
|
546
|
|
|
'query' => 'SELECT u FROM __CLASS__ u' |
|
547
|
|
|
)); |
|
548
|
|
|
|
|
549
|
|
|
$this->assertTrue($cm->hasNamedQuery('all')); |
|
550
|
|
|
$this->assertFalse($cm->hasNamedQuery('userById')); |
|
551
|
|
|
} |
|
552
|
|
|
|
|
553
|
|
|
/** |
|
554
|
|
|
* @group DDC-1663 |
|
555
|
|
|
*/ |
|
556
|
|
|
public function testRetrieveOfNamedNativeQuery() |
|
557
|
|
|
{ |
|
558
|
|
|
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); |
|
559
|
|
|
$cm->initializeReflection(new RuntimeReflectionService()); |
|
560
|
|
|
|
|
561
|
|
|
$cm->addNamedNativeQuery(array( |
|
562
|
|
|
'name' => 'find-all', |
|
563
|
|
|
'query' => 'SELECT * FROM cms_users', |
|
564
|
|
|
'resultSetMapping' => 'result-mapping-name', |
|
565
|
|
|
'resultClass' => 'Doctrine\Tests\Models\CMS\CmsUser', |
|
566
|
|
|
)); |
|
567
|
|
|
|
|
568
|
|
|
$cm->addNamedNativeQuery(array( |
|
569
|
|
|
'name' => 'find-by-id', |
|
570
|
|
|
'query' => 'SELECT * FROM cms_users WHERE id = ?', |
|
571
|
|
|
'resultClass' => '__CLASS__', |
|
572
|
|
|
'resultSetMapping' => 'result-mapping-name', |
|
573
|
|
|
)); |
|
574
|
|
|
|
|
575
|
|
|
$mapping = $cm->getNamedNativeQuery('find-all'); |
|
576
|
|
|
$this->assertEquals('SELECT * FROM cms_users', $mapping['query']); |
|
577
|
|
|
$this->assertEquals('result-mapping-name', $mapping['resultSetMapping']); |
|
578
|
|
|
$this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $mapping['resultClass']); |
|
579
|
|
|
|
|
580
|
|
|
$mapping = $cm->getNamedNativeQuery('find-by-id'); |
|
581
|
|
|
$this->assertEquals('SELECT * FROM cms_users WHERE id = ?', $mapping['query']); |
|
582
|
|
|
$this->assertEquals('result-mapping-name', $mapping['resultSetMapping']); |
|
583
|
|
|
$this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $mapping['resultClass']); |
|
584
|
|
|
} |
|
585
|
|
|
|
|
586
|
|
|
/** |
|
587
|
|
|
* @group DDC-1663 |
|
588
|
|
|
*/ |
|
589
|
|
|
public function testRetrieveOfSqlResultSetMapping() |
|
590
|
|
|
{ |
|
591
|
|
|
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); |
|
592
|
|
|
$cm->initializeReflection(new RuntimeReflectionService()); |
|
593
|
|
|
|
|
594
|
|
|
$cm->addSqlResultSetMapping(array( |
|
595
|
|
|
'name' => 'find-all', |
|
596
|
|
|
'entities' => array( |
|
597
|
|
|
array( |
|
598
|
|
|
'entityClass' => '__CLASS__', |
|
599
|
|
|
'fields' => array( |
|
600
|
|
|
array( |
|
601
|
|
|
'name' => 'id', |
|
602
|
|
|
'column'=> 'id' |
|
603
|
|
|
), |
|
604
|
|
|
array( |
|
605
|
|
|
'name' => 'name', |
|
606
|
|
|
'column'=> 'name' |
|
607
|
|
|
) |
|
608
|
|
|
) |
|
609
|
|
|
), |
|
610
|
|
|
array( |
|
611
|
|
|
'entityClass' => 'Doctrine\Tests\Models\CMS\CmsEmail', |
|
612
|
|
|
'fields' => array( |
|
613
|
|
|
array( |
|
614
|
|
|
'name' => 'id', |
|
615
|
|
|
'column'=> 'id' |
|
616
|
|
|
), |
|
617
|
|
|
array( |
|
618
|
|
|
'name' => 'email', |
|
619
|
|
|
'column'=> 'email' |
|
620
|
|
|
) |
|
621
|
|
|
) |
|
622
|
|
|
) |
|
623
|
|
|
), |
|
624
|
|
|
'columns' => array( |
|
625
|
|
|
array( |
|
626
|
|
|
'name' => 'scalarColumn' |
|
627
|
|
|
) |
|
628
|
|
|
) |
|
629
|
|
|
)); |
|
630
|
|
|
|
|
631
|
|
|
$mapping = $cm->getSqlResultSetMapping('find-all'); |
|
632
|
|
|
|
|
633
|
|
|
$this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $mapping['entities'][0]['entityClass']); |
|
634
|
|
|
$this->assertEquals(array('name'=>'id','column'=>'id'), $mapping['entities'][0]['fields'][0]); |
|
635
|
|
|
$this->assertEquals(array('name'=>'name','column'=>'name'), $mapping['entities'][0]['fields'][1]); |
|
636
|
|
|
|
|
637
|
|
|
$this->assertEquals('Doctrine\Tests\Models\CMS\CmsEmail', $mapping['entities'][1]['entityClass']); |
|
638
|
|
|
$this->assertEquals(array('name'=>'id','column'=>'id'), $mapping['entities'][1]['fields'][0]); |
|
639
|
|
|
$this->assertEquals(array('name'=>'email','column'=>'email'), $mapping['entities'][1]['fields'][1]); |
|
640
|
|
|
|
|
641
|
|
|
$this->assertEquals('scalarColumn', $mapping['columns'][0]['name']); |
|
642
|
|
|
} |
|
643
|
|
|
|
|
644
|
|
|
/** |
|
645
|
|
|
* @group DDC-1663 |
|
646
|
|
|
*/ |
|
647
|
|
|
public function testExistanceOfSqlResultSetMapping() |
|
648
|
|
|
{ |
|
649
|
|
|
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); |
|
650
|
|
|
$cm->initializeReflection(new RuntimeReflectionService()); |
|
651
|
|
|
|
|
652
|
|
|
$cm->addSqlResultSetMapping(array( |
|
653
|
|
|
'name' => 'find-all', |
|
654
|
|
|
'entities' => array( |
|
655
|
|
|
array( |
|
656
|
|
|
'entityClass' => 'Doctrine\Tests\Models\CMS\CmsUser', |
|
657
|
|
|
), |
|
658
|
|
|
), |
|
659
|
|
|
)); |
|
660
|
|
|
|
|
661
|
|
|
$this->assertTrue($cm->hasSqlResultSetMapping('find-all')); |
|
662
|
|
|
$this->assertFalse($cm->hasSqlResultSetMapping('find-by-id')); |
|
663
|
|
|
} |
|
664
|
|
|
|
|
665
|
|
|
/** |
|
666
|
|
|
* @group DDC-1663 |
|
667
|
|
|
*/ |
|
668
|
|
|
public function testExistanceOfNamedNativeQuery() |
|
669
|
|
|
{ |
|
670
|
|
|
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); |
|
671
|
|
|
$cm->initializeReflection(new RuntimeReflectionService()); |
|
672
|
|
|
|
|
673
|
|
|
|
|
674
|
|
|
$cm->addNamedNativeQuery(array( |
|
675
|
|
|
'name' => 'find-all', |
|
676
|
|
|
'query' => 'SELECT * FROM cms_users', |
|
677
|
|
|
'resultClass' => 'Doctrine\Tests\Models\CMS\CmsUser', |
|
678
|
|
|
'resultSetMapping' => 'result-mapping-name' |
|
679
|
|
|
)); |
|
680
|
|
|
|
|
681
|
|
|
$this->assertTrue($cm->hasNamedNativeQuery('find-all')); |
|
682
|
|
|
$this->assertFalse($cm->hasNamedNativeQuery('find-by-id')); |
|
683
|
|
|
} |
|
684
|
|
|
|
|
685
|
|
|
public function testRetrieveOfNamedQuery() |
|
686
|
|
|
{ |
|
687
|
|
|
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); |
|
688
|
|
|
$cm->initializeReflection(new RuntimeReflectionService()); |
|
689
|
|
|
|
|
690
|
|
|
|
|
691
|
|
|
$cm->addNamedQuery(array( |
|
692
|
|
|
'name' => 'userById', |
|
693
|
|
|
'query' => 'SELECT u FROM __CLASS__ u WHERE u.id = ?1' |
|
694
|
|
|
)); |
|
695
|
|
|
|
|
696
|
|
|
$this->assertEquals('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = ?1', $cm->getNamedQuery('userById')); |
|
697
|
|
|
} |
|
698
|
|
|
|
|
699
|
|
|
/** |
|
700
|
|
|
* @group DDC-1663 |
|
701
|
|
|
*/ |
|
702
|
|
|
public function testRetrievalOfNamedNativeQueries() |
|
703
|
|
|
{ |
|
704
|
|
|
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); |
|
705
|
|
|
$cm->initializeReflection(new RuntimeReflectionService()); |
|
706
|
|
|
|
|
707
|
|
|
$this->assertEquals(0, count($cm->getNamedNativeQueries())); |
|
708
|
|
|
|
|
709
|
|
|
$cm->addNamedNativeQuery(array( |
|
710
|
|
|
'name' => 'find-all', |
|
711
|
|
|
'query' => 'SELECT * FROM cms_users', |
|
712
|
|
|
'resultClass' => 'Doctrine\Tests\Models\CMS\CmsUser', |
|
713
|
|
|
'resultSetMapping' => 'result-mapping-name' |
|
714
|
|
|
)); |
|
715
|
|
|
|
|
716
|
|
|
$this->assertEquals(1, count($cm->getNamedNativeQueries())); |
|
717
|
|
|
} |
|
718
|
|
|
|
|
719
|
|
|
/** |
|
720
|
|
|
* @group DDC-2451 |
|
721
|
|
|
*/ |
|
722
|
|
|
public function testSerializeEntityListeners() |
|
723
|
|
|
{ |
|
724
|
|
|
$metadata = new ClassMetadata('Doctrine\Tests\Models\Company\CompanyContract'); |
|
725
|
|
|
|
|
726
|
|
|
$metadata->initializeReflection(new RuntimeReflectionService()); |
|
727
|
|
|
$metadata->addEntityListener(\Doctrine\ORM\Events::prePersist, 'CompanyContractListener', 'prePersistHandler'); |
|
728
|
|
|
$metadata->addEntityListener(\Doctrine\ORM\Events::postPersist, 'CompanyContractListener', 'postPersistHandler'); |
|
729
|
|
|
|
|
730
|
|
|
$serialize = serialize($metadata); |
|
731
|
|
|
$unserialize = unserialize($serialize); |
|
732
|
|
|
|
|
733
|
|
|
$this->assertEquals($metadata->entityListeners, $unserialize->entityListeners); |
|
734
|
|
|
} |
|
735
|
|
|
|
|
736
|
|
|
/** |
|
737
|
|
|
* @expectedException \Doctrine\ORM\Mapping\MappingException |
|
738
|
|
|
* @expectedExceptionMessage Query named "userById" in "Doctrine\Tests\Models\CMS\CmsUser" was already declared, but it must be declared only once |
|
739
|
|
|
*/ |
|
740
|
|
|
public function testNamingCollisionNamedQueryShouldThrowException() |
|
741
|
|
|
{ |
|
742
|
|
|
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); |
|
743
|
|
|
$cm->initializeReflection(new RuntimeReflectionService()); |
|
744
|
|
|
|
|
745
|
|
|
$cm->addNamedQuery(array( |
|
746
|
|
|
'name' => 'userById', |
|
747
|
|
|
'query' => 'SELECT u FROM __CLASS__ u WHERE u.id = ?1' |
|
748
|
|
|
)); |
|
749
|
|
|
|
|
750
|
|
|
$cm->addNamedQuery(array( |
|
751
|
|
|
'name' => 'userById', |
|
752
|
|
|
'query' => 'SELECT u FROM __CLASS__ u WHERE u.id = ?1' |
|
753
|
|
|
)); |
|
754
|
|
|
} |
|
755
|
|
|
|
|
756
|
|
|
/** |
|
757
|
|
|
* @group DDC-1663 |
|
758
|
|
|
* |
|
759
|
|
|
* @expectedException \Doctrine\ORM\Mapping\MappingException |
|
760
|
|
|
* @expectedExceptionMessage Query named "find-all" in "Doctrine\Tests\Models\CMS\CmsUser" was already declared, but it must be declared only once |
|
761
|
|
|
*/ |
|
762
|
|
|
public function testNamingCollisionNamedNativeQueryShouldThrowException() |
|
763
|
|
|
{ |
|
764
|
|
|
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); |
|
765
|
|
|
$cm->initializeReflection(new RuntimeReflectionService()); |
|
766
|
|
|
|
|
767
|
|
|
$cm->addNamedNativeQuery(array( |
|
768
|
|
|
'name' => 'find-all', |
|
769
|
|
|
'query' => 'SELECT * FROM cms_users', |
|
770
|
|
|
'resultClass' => 'Doctrine\Tests\Models\CMS\CmsUser', |
|
771
|
|
|
'resultSetMapping' => 'result-mapping-name' |
|
772
|
|
|
)); |
|
773
|
|
|
|
|
774
|
|
|
$cm->addNamedNativeQuery(array( |
|
775
|
|
|
'name' => 'find-all', |
|
776
|
|
|
'query' => 'SELECT * FROM cms_users', |
|
777
|
|
|
'resultClass' => 'Doctrine\Tests\Models\CMS\CmsUser', |
|
778
|
|
|
'resultSetMapping' => 'result-mapping-name' |
|
779
|
|
|
)); |
|
780
|
|
|
} |
|
781
|
|
|
|
|
782
|
|
|
/** |
|
783
|
|
|
* @group DDC-1663 |
|
784
|
|
|
* |
|
785
|
|
|
* @expectedException \Doctrine\ORM\Mapping\MappingException |
|
786
|
|
|
* @expectedExceptionMessage Result set mapping named "find-all" in "Doctrine\Tests\Models\CMS\CmsUser" was already declared, but it must be declared only once |
|
787
|
|
|
*/ |
|
788
|
|
|
public function testNamingCollisionSqlResultSetMappingShouldThrowException() |
|
789
|
|
|
{ |
|
790
|
|
|
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); |
|
791
|
|
|
$cm->initializeReflection(new RuntimeReflectionService()); |
|
792
|
|
|
|
|
793
|
|
|
$cm->addSqlResultSetMapping(array( |
|
794
|
|
|
'name' => 'find-all', |
|
795
|
|
|
'entities' => array( |
|
796
|
|
|
array( |
|
797
|
|
|
'entityClass' => 'Doctrine\Tests\Models\CMS\CmsUser', |
|
798
|
|
|
), |
|
799
|
|
|
), |
|
800
|
|
|
)); |
|
801
|
|
|
|
|
802
|
|
|
$cm->addSqlResultSetMapping(array( |
|
803
|
|
|
'name' => 'find-all', |
|
804
|
|
|
'entities' => array( |
|
805
|
|
|
array( |
|
806
|
|
|
'entityClass' => 'Doctrine\Tests\Models\CMS\CmsUser', |
|
807
|
|
|
), |
|
808
|
|
|
), |
|
809
|
|
|
)); |
|
810
|
|
|
} |
|
811
|
|
|
|
|
812
|
|
|
/** |
|
813
|
|
|
* @group DDC-1068 |
|
814
|
|
|
*/ |
|
815
|
|
|
public function testClassCaseSensitivity() |
|
816
|
|
|
{ |
|
817
|
|
|
$user = new \Doctrine\Tests\Models\CMS\CmsUser(); |
|
|
|
|
|
|
818
|
|
|
$cm = new ClassMetadata('DOCTRINE\TESTS\MODELS\CMS\CMSUSER'); |
|
819
|
|
|
$cm->initializeReflection(new RuntimeReflectionService()); |
|
820
|
|
|
|
|
821
|
|
|
$this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $cm->name); |
|
822
|
|
|
} |
|
823
|
|
|
|
|
824
|
|
|
/** |
|
825
|
|
|
* @group DDC-659 |
|
826
|
|
|
*/ |
|
827
|
|
|
public function testLifecycleCallbackNotFound() |
|
828
|
|
|
{ |
|
829
|
|
|
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); |
|
830
|
|
|
$cm->initializeReflection(new RuntimeReflectionService()); |
|
831
|
|
|
$cm->addLifecycleCallback('notfound', 'postLoad'); |
|
832
|
|
|
|
|
833
|
|
|
$this->setExpectedException("Doctrine\ORM\Mapping\MappingException", "Entity 'Doctrine\Tests\Models\CMS\CmsUser' has no method 'notfound' to be registered as lifecycle callback."); |
|
834
|
|
|
$cm->validateLifecycleCallbacks(new RuntimeReflectionService()); |
|
835
|
|
|
} |
|
836
|
|
|
|
|
837
|
|
|
/** |
|
838
|
|
|
* @group ImproveErrorMessages |
|
839
|
|
|
*/ |
|
840
|
|
|
public function testTargetEntityNotFound() |
|
841
|
|
|
{ |
|
842
|
|
|
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); |
|
843
|
|
|
$cm->initializeReflection(new RuntimeReflectionService()); |
|
844
|
|
|
$cm->mapManyToOne(array('fieldName' => 'address', 'targetEntity' => 'UnknownClass')); |
|
845
|
|
|
|
|
846
|
|
|
$this->setExpectedException("Doctrine\ORM\Mapping\MappingException", "The target-entity Doctrine\Tests\Models\CMS\UnknownClass cannot be found in 'Doctrine\Tests\Models\CMS\CmsUser#address'."); |
|
847
|
|
|
$cm->validateAssociations(); |
|
848
|
|
|
} |
|
849
|
|
|
|
|
850
|
|
|
/** |
|
851
|
|
|
* @group DDC-1663 |
|
852
|
|
|
* |
|
853
|
|
|
* @expectedException \Doctrine\ORM\Mapping\MappingException |
|
854
|
|
|
* @expectedExceptionMessage Query name on entity class 'Doctrine\Tests\Models\CMS\CmsUser' is not defined. |
|
855
|
|
|
*/ |
|
856
|
|
|
public function testNameIsMandatoryForNamedQueryMappingException() |
|
857
|
|
|
{ |
|
858
|
|
|
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); |
|
859
|
|
|
$cm->initializeReflection(new RuntimeReflectionService()); |
|
860
|
|
|
$cm->addNamedQuery(array( |
|
861
|
|
|
'query' => 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u', |
|
862
|
|
|
)); |
|
863
|
|
|
} |
|
864
|
|
|
|
|
865
|
|
|
/** |
|
866
|
|
|
* @group DDC-1663 |
|
867
|
|
|
* |
|
868
|
|
|
* @expectedException \Doctrine\ORM\Mapping\MappingException |
|
869
|
|
|
* @expectedExceptionMessage Query name on entity class 'Doctrine\Tests\Models\CMS\CmsUser' is not defined. |
|
870
|
|
|
*/ |
|
871
|
|
|
public function testNameIsMandatoryForNameNativeQueryMappingException() |
|
872
|
|
|
{ |
|
873
|
|
|
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); |
|
874
|
|
|
$cm->initializeReflection(new RuntimeReflectionService()); |
|
875
|
|
|
$cm->addNamedQuery(array( |
|
876
|
|
|
'query' => 'SELECT * FROM cms_users', |
|
877
|
|
|
'resultClass' => 'Doctrine\Tests\Models\CMS\CmsUser', |
|
878
|
|
|
'resultSetMapping' => 'result-mapping-name' |
|
879
|
|
|
)); |
|
880
|
|
|
} |
|
881
|
|
|
|
|
882
|
|
|
/** |
|
883
|
|
|
* @group DDC-1663 |
|
884
|
|
|
* |
|
885
|
|
|
* @expectedException \Doctrine\ORM\Mapping\MappingException |
|
886
|
|
|
* @expectedExceptionMessage Result set mapping named "find-all" in "Doctrine\Tests\Models\CMS\CmsUser requires a entity class name. |
|
887
|
|
|
*/ |
|
888
|
|
|
public function testNameIsMandatoryForEntityNameSqlResultSetMappingException() |
|
889
|
|
|
{ |
|
890
|
|
|
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); |
|
891
|
|
|
$cm->initializeReflection(new RuntimeReflectionService()); |
|
892
|
|
|
$cm->addSqlResultSetMapping(array( |
|
893
|
|
|
'name' => 'find-all', |
|
894
|
|
|
'entities' => array( |
|
895
|
|
|
array( |
|
896
|
|
|
'fields' => array() |
|
897
|
|
|
) |
|
898
|
|
|
), |
|
899
|
|
|
)); |
|
900
|
|
|
} |
|
901
|
|
|
|
|
902
|
|
|
/** |
|
903
|
|
|
* @expectedException \Doctrine\ORM\Mapping\MappingException |
|
904
|
|
|
* @expectedExceptionMessage Discriminator column name on entity class 'Doctrine\Tests\Models\CMS\CmsUser' is not defined. |
|
905
|
|
|
*/ |
|
906
|
|
|
public function testNameIsMandatoryForDiscriminatorColumnsMappingException() |
|
907
|
|
|
{ |
|
908
|
|
|
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); |
|
909
|
|
|
$cm->initializeReflection(new RuntimeReflectionService()); |
|
910
|
|
|
$cm->setDiscriminatorColumn(array()); |
|
911
|
|
|
} |
|
912
|
|
|
|
|
913
|
|
|
/** |
|
914
|
|
|
* @group DDC-984 |
|
915
|
|
|
* @group DDC-559 |
|
916
|
|
|
* @group DDC-1575 |
|
917
|
|
|
*/ |
|
918
|
|
|
public function testFullyQualifiedClassNameShouldBeGivenToNamingStrategy() |
|
919
|
|
|
{ |
|
920
|
|
|
$namingStrategy = new MyNamespacedNamingStrategy(); |
|
921
|
|
|
$addressMetadata = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress', $namingStrategy); |
|
922
|
|
|
$articleMetadata = new ClassMetadata('DoctrineGlobal_Article', $namingStrategy); |
|
923
|
|
|
$routingMetadata = new ClassMetadata('Doctrine\Tests\Models\Routing\RoutingLeg',$namingStrategy); |
|
924
|
|
|
|
|
925
|
|
|
$addressMetadata->initializeReflection(new RuntimeReflectionService()); |
|
926
|
|
|
$articleMetadata->initializeReflection(new RuntimeReflectionService()); |
|
927
|
|
|
$routingMetadata->initializeReflection(new RuntimeReflectionService()); |
|
928
|
|
|
|
|
929
|
|
|
$addressMetadata->mapManyToMany(array( |
|
930
|
|
|
'fieldName' => 'user', |
|
931
|
|
|
'targetEntity' => 'CmsUser' |
|
932
|
|
|
)); |
|
933
|
|
|
|
|
934
|
|
|
$articleMetadata->mapManyToMany(array( |
|
935
|
|
|
'fieldName' => 'author', |
|
936
|
|
|
'targetEntity' => 'Doctrine\Tests\Models\CMS\CmsUser' |
|
937
|
|
|
)); |
|
938
|
|
|
|
|
939
|
|
|
$this->assertEquals('routing_routingleg', $routingMetadata->table['name']); |
|
940
|
|
|
$this->assertEquals('cms_cmsaddress_cms_cmsuser', $addressMetadata->associationMappings['user']['joinTable']['name']); |
|
941
|
|
|
$this->assertEquals('doctrineglobal_article_cms_cmsuser', $articleMetadata->associationMappings['author']['joinTable']['name']); |
|
942
|
|
|
} |
|
943
|
|
|
|
|
944
|
|
|
/** |
|
945
|
|
|
* @group DDC-984 |
|
946
|
|
|
* @group DDC-559 |
|
947
|
|
|
*/ |
|
948
|
|
|
public function testFullyQualifiedClassNameShouldBeGivenToNamingStrategyPropertyToColumnName() |
|
949
|
|
|
{ |
|
950
|
|
|
$namingStrategy = new MyPrefixNamingStrategy(); |
|
951
|
|
|
$metadata = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress', $namingStrategy); |
|
952
|
|
|
|
|
953
|
|
|
$metadata->initializeReflection(new RuntimeReflectionService()); |
|
954
|
|
|
|
|
955
|
|
|
$metadata->mapField(array('fieldName'=>'country')); |
|
956
|
|
|
$metadata->mapField(array('fieldName'=>'city')); |
|
957
|
|
|
|
|
958
|
|
|
$this->assertEquals($metadata->fieldNames, array( |
|
959
|
|
|
'cmsaddress_country' => 'country', |
|
960
|
|
|
'cmsaddress_city' => 'city' |
|
961
|
|
|
)); |
|
962
|
|
|
} |
|
963
|
|
|
|
|
964
|
|
|
/** |
|
965
|
|
|
* @group DDC-1746 |
|
966
|
|
|
*/ |
|
967
|
|
|
public function testInvalidCascade() |
|
968
|
|
|
{ |
|
969
|
|
|
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); |
|
970
|
|
|
$cm->initializeReflection(new RuntimeReflectionService()); |
|
971
|
|
|
|
|
972
|
|
|
$this->setExpectedException("Doctrine\ORM\Mapping\MappingException", "You have specified invalid cascade options for Doctrine\Tests\Models\CMS\CmsUser::\$address: 'invalid'; available options: 'remove', 'persist', 'refresh', 'merge', and 'detach'"); |
|
973
|
|
|
|
|
974
|
|
|
|
|
975
|
|
|
$cm->mapManyToOne(array('fieldName' => 'address', 'targetEntity' => 'UnknownClass', 'cascade' => array('invalid'))); |
|
976
|
|
|
} |
|
977
|
|
|
|
|
978
|
|
|
/** |
|
979
|
|
|
* @group DDC-964 |
|
980
|
|
|
* @expectedException Doctrine\ORM\Mapping\MappingException |
|
981
|
|
|
* @expectedExceptionMessage Invalid field override named 'invalidPropertyName' for class 'Doctrine\Tests\Models\DDC964\DDC964Admin |
|
982
|
|
|
*/ |
|
983
|
|
|
public function testInvalidPropertyAssociationOverrideNameException() |
|
984
|
|
|
{ |
|
985
|
|
|
$cm = new ClassMetadata('Doctrine\Tests\Models\DDC964\DDC964Admin'); |
|
986
|
|
|
$cm->initializeReflection(new RuntimeReflectionService()); |
|
987
|
|
|
$cm->mapManyToOne(array('fieldName' => 'address', 'targetEntity' => 'DDC964Address')); |
|
988
|
|
|
|
|
989
|
|
|
$cm->setAssociationOverride('invalidPropertyName', array()); |
|
990
|
|
|
} |
|
991
|
|
|
|
|
992
|
|
|
/** |
|
993
|
|
|
* @group DDC-964 |
|
994
|
|
|
* @expectedException Doctrine\ORM\Mapping\MappingException |
|
995
|
|
|
* @expectedExceptionMessage Invalid field override named 'invalidPropertyName' for class 'Doctrine\Tests\Models\DDC964\DDC964Guest'. |
|
996
|
|
|
*/ |
|
997
|
|
|
public function testInvalidPropertyAttributeOverrideNameException() |
|
998
|
|
|
{ |
|
999
|
|
|
$cm = new ClassMetadata('Doctrine\Tests\Models\DDC964\DDC964Guest'); |
|
1000
|
|
|
$cm->initializeReflection(new RuntimeReflectionService()); |
|
1001
|
|
|
$cm->mapField(array('fieldName' => 'name')); |
|
1002
|
|
|
|
|
1003
|
|
|
$cm->setAttributeOverride('invalidPropertyName', array()); |
|
1004
|
|
|
} |
|
1005
|
|
|
|
|
1006
|
|
|
/** |
|
1007
|
|
|
* @group DDC-964 |
|
1008
|
|
|
* @expectedException Doctrine\ORM\Mapping\MappingException |
|
1009
|
|
|
* @expectedExceptionMessage The column type of attribute 'name' on class 'Doctrine\Tests\Models\DDC964\DDC964Guest' could not be changed. |
|
1010
|
|
|
*/ |
|
1011
|
|
|
public function testInvalidOverrideAttributeFieldTypeException() |
|
1012
|
|
|
{ |
|
1013
|
|
|
$cm = new ClassMetadata('Doctrine\Tests\Models\DDC964\DDC964Guest'); |
|
1014
|
|
|
$cm->initializeReflection(new RuntimeReflectionService()); |
|
1015
|
|
|
$cm->mapField(array('fieldName' => 'name', 'type'=>'string')); |
|
1016
|
|
|
|
|
1017
|
|
|
$cm->setAttributeOverride('name', array('type'=>'date')); |
|
1018
|
|
|
} |
|
1019
|
|
|
|
|
1020
|
|
|
/** |
|
1021
|
|
|
* @group DDC-1955 |
|
1022
|
|
|
* |
|
1023
|
|
|
* @expectedException Doctrine\ORM\Mapping\MappingException |
|
1024
|
|
|
* @expectedExceptionMessage Entity Listener "\InvalidClassName" declared on "Doctrine\Tests\Models\CMS\CmsUser" not found. |
|
1025
|
|
|
*/ |
|
1026
|
|
|
public function testInvalidEntityListenerClassException() |
|
1027
|
|
|
{ |
|
1028
|
|
|
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); |
|
1029
|
|
|
$cm->initializeReflection(new RuntimeReflectionService()); |
|
1030
|
|
|
|
|
1031
|
|
|
$cm->addEntityListener(Events::postLoad, '\InvalidClassName', 'postLoadHandler'); |
|
1032
|
|
|
} |
|
1033
|
|
|
|
|
1034
|
|
|
/** |
|
1035
|
|
|
* @group DDC-1955 |
|
1036
|
|
|
* |
|
1037
|
|
|
* @expectedException Doctrine\ORM\Mapping\MappingException |
|
1038
|
|
|
* @expectedExceptionMessage Entity Listener "\Doctrine\Tests\Models\Company\CompanyContractListener" declared on "Doctrine\Tests\Models\CMS\CmsUser" has no method "invalidMethod". |
|
1039
|
|
|
*/ |
|
1040
|
|
|
public function testInvalidEntityListenerMethodException() |
|
1041
|
|
|
{ |
|
1042
|
|
|
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); |
|
1043
|
|
|
$cm->initializeReflection(new RuntimeReflectionService()); |
|
1044
|
|
|
|
|
1045
|
|
|
$cm->addEntityListener(Events::postLoad, '\Doctrine\Tests\Models\Company\CompanyContractListener', 'invalidMethod'); |
|
1046
|
|
|
} |
|
1047
|
|
|
|
|
1048
|
|
|
public function testManyToManySelfReferencingNamingStrategyDefaults() |
|
1049
|
|
|
{ |
|
1050
|
|
|
$cm = new ClassMetadata('Doctrine\Tests\Models\CustomType\CustomTypeParent'); |
|
1051
|
|
|
$cm->initializeReflection(new RuntimeReflectionService()); |
|
1052
|
|
|
$cm->mapManyToMany( |
|
1053
|
|
|
array( |
|
1054
|
|
|
'fieldName' => 'friendsWithMe', |
|
1055
|
|
|
'targetEntity' => 'CustomTypeParent' |
|
1056
|
|
|
) |
|
1057
|
|
|
); |
|
1058
|
|
|
|
|
1059
|
|
|
$this->assertEquals( |
|
1060
|
|
|
array( |
|
1061
|
|
|
'name' => 'customtypeparent_customtypeparent', |
|
1062
|
|
|
'joinColumns' => array(array('name' => 'customtypeparent_source', 'referencedColumnName' => 'id', 'onDelete' => 'CASCADE')), |
|
1063
|
|
|
'inverseJoinColumns' => array(array('name' => 'customtypeparent_target', 'referencedColumnName' => 'id', 'onDelete' => 'CASCADE')), |
|
1064
|
|
|
), |
|
1065
|
|
|
$cm->associationMappings['friendsWithMe']['joinTable'] |
|
1066
|
|
|
); |
|
1067
|
|
|
$this->assertEquals(array('customtypeparent_source', 'customtypeparent_target'), $cm->associationMappings['friendsWithMe']['joinTableColumns']); |
|
1068
|
|
|
$this->assertEquals(array('customtypeparent_source' => 'id'), $cm->associationMappings['friendsWithMe']['relationToSourceKeyColumns']); |
|
1069
|
|
|
$this->assertEquals(array('customtypeparent_target' => 'id'), $cm->associationMappings['friendsWithMe']['relationToTargetKeyColumns']); |
|
1070
|
|
|
} |
|
1071
|
|
|
|
|
1072
|
|
|
/** |
|
1073
|
|
|
* @group DDC-2608 |
|
1074
|
|
|
*/ |
|
1075
|
|
|
public function testSetSequenceGeneratorThrowsExceptionWhenSequenceNameIsMissing() |
|
1076
|
|
|
{ |
|
1077
|
|
|
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); |
|
1078
|
|
|
$cm->initializeReflection(new RuntimeReflectionService()); |
|
1079
|
|
|
|
|
1080
|
|
|
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); |
|
1081
|
|
|
$cm->setSequenceGeneratorDefinition(array()); |
|
1082
|
|
|
} |
|
1083
|
|
|
|
|
1084
|
|
|
/** |
|
1085
|
|
|
* @group DDC-2662 |
|
1086
|
|
|
*/ |
|
1087
|
|
|
public function testQuotedSequenceName() |
|
1088
|
|
|
{ |
|
1089
|
|
|
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); |
|
1090
|
|
|
$cm->initializeReflection(new RuntimeReflectionService()); |
|
1091
|
|
|
|
|
1092
|
|
|
$cm->setSequenceGeneratorDefinition(array('sequenceName' => '`foo`')); |
|
1093
|
|
|
|
|
1094
|
|
|
$this->assertEquals(array('sequenceName' => 'foo', 'quoted' => true), $cm->sequenceGeneratorDefinition); |
|
1095
|
|
|
} |
|
1096
|
|
|
|
|
1097
|
|
|
/** |
|
1098
|
|
|
* @group DDC-2700 |
|
1099
|
|
|
*/ |
|
1100
|
|
|
public function testIsIdentifierMappedSuperClass() |
|
1101
|
|
|
{ |
|
1102
|
|
|
$class = new ClassMetadata(__NAMESPACE__ . '\\DDC2700MappedSuperClass'); |
|
1103
|
|
|
|
|
1104
|
|
|
$this->assertFalse($class->isIdentifier('foo')); |
|
1105
|
|
|
} |
|
1106
|
|
|
|
|
1107
|
|
|
/** |
|
1108
|
|
|
* @group DDC-3120 |
|
1109
|
|
|
*/ |
|
1110
|
|
|
public function testCanInstantiateInternalPhpClassSubclass() |
|
1111
|
|
|
{ |
|
1112
|
|
|
$classMetadata = new ClassMetadata(__NAMESPACE__ . '\\MyArrayObjectEntity'); |
|
1113
|
|
|
|
|
1114
|
|
|
$this->assertInstanceOf(__NAMESPACE__ . '\\MyArrayObjectEntity', $classMetadata->newInstance()); |
|
1115
|
|
|
} |
|
1116
|
|
|
|
|
1117
|
|
|
/** |
|
1118
|
|
|
* @group DDC-3120 |
|
1119
|
|
|
*/ |
|
1120
|
|
|
public function testCanInstantiateInternalPhpClassSubclassFromUnserializedMetadata() |
|
1121
|
|
|
{ |
|
1122
|
|
|
/* @var $classMetadata ClassMetadata */ |
|
1123
|
|
|
$classMetadata = unserialize(serialize(new ClassMetadata(__NAMESPACE__ . '\\MyArrayObjectEntity'))); |
|
1124
|
|
|
|
|
1125
|
|
|
$classMetadata->wakeupReflection(new RuntimeReflectionService()); |
|
1126
|
|
|
|
|
1127
|
|
|
$this->assertInstanceOf(__NAMESPACE__ . '\\MyArrayObjectEntity', $classMetadata->newInstance()); |
|
1128
|
|
|
} |
|
1129
|
|
|
|
|
1130
|
|
|
public function testWakeupReflectionWithEmbeddableAndStaticReflectionService() |
|
1131
|
|
|
{ |
|
1132
|
|
|
$classMetadata = new ClassMetadata('Doctrine\Tests\ORM\Mapping\TestEntity1'); |
|
1133
|
|
|
|
|
1134
|
|
|
$classMetadata->mapEmbedded(array( |
|
1135
|
|
|
'fieldName' => 'test', |
|
1136
|
|
|
'class' => 'Doctrine\Tests\ORM\Mapping\TestEntity1', |
|
1137
|
|
|
'columnPrefix' => false, |
|
1138
|
|
|
)); |
|
1139
|
|
|
|
|
1140
|
|
|
$field = array( |
|
1141
|
|
|
'fieldName' => 'test.embeddedProperty', |
|
1142
|
|
|
'type' => 'string', |
|
1143
|
|
|
'originalClass' => 'Doctrine\Tests\ORM\Mapping\TestEntity1', |
|
1144
|
|
|
'declaredField' => 'test', |
|
1145
|
|
|
'originalField' => 'embeddedProperty' |
|
1146
|
|
|
); |
|
1147
|
|
|
|
|
1148
|
|
|
$classMetadata->mapField($field); |
|
1149
|
|
|
$classMetadata->wakeupReflection(new StaticReflectionService()); |
|
1150
|
|
|
|
|
1151
|
|
|
$this->assertEquals(array('test' => null, 'test.embeddedProperty' => null), $classMetadata->getReflectionProperties()); |
|
1152
|
|
|
} |
|
1153
|
|
|
|
|
1154
|
|
|
public function testGetColumnNamesWithGivenFieldNames() |
|
1155
|
|
|
{ |
|
1156
|
|
|
$metadata = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); |
|
1157
|
|
|
$metadata->initializeReflection(new RuntimeReflectionService()); |
|
1158
|
|
|
|
|
1159
|
|
|
$metadata->mapField(array('fieldName' => 'status', 'type' => 'string', 'columnName' => 'foo')); |
|
1160
|
|
|
$metadata->mapField(array('fieldName' => 'username', 'type' => 'string', 'columnName' => 'bar')); |
|
1161
|
|
|
$metadata->mapField(array('fieldName' => 'name', 'type' => 'string', 'columnName' => 'baz')); |
|
1162
|
|
|
|
|
1163
|
|
|
self::assertSame(['foo', 'baz'], $metadata->getColumnNames(['status', 'name'])); |
|
1164
|
|
|
} |
|
1165
|
|
|
} |
|
1166
|
|
|
|
|
1167
|
|
|
/** |
|
1168
|
|
|
* @MappedSuperclass |
|
1169
|
|
|
*/ |
|
1170
|
|
|
class DDC2700MappedSuperClass |
|
1171
|
|
|
{ |
|
1172
|
|
|
/** @Column */ |
|
1173
|
|
|
private $foo; |
|
1174
|
|
|
} |
|
1175
|
|
|
|
|
1176
|
|
|
class MyNamespacedNamingStrategy extends DefaultNamingStrategy |
|
1177
|
|
|
{ |
|
1178
|
|
|
/** |
|
1179
|
|
|
* {@inheritdoc} |
|
1180
|
|
|
*/ |
|
1181
|
|
|
public function classToTableName($className) |
|
1182
|
|
|
{ |
|
1183
|
|
|
if (strpos($className, '\\') !== false) { |
|
1184
|
|
|
$className = str_replace('\\', '_', str_replace('Doctrine\Tests\Models\\', '', $className)); |
|
1185
|
|
|
} |
|
1186
|
|
|
|
|
1187
|
|
|
return strtolower($className); |
|
1188
|
|
|
} |
|
1189
|
|
|
} |
|
1190
|
|
|
|
|
1191
|
|
|
class MyPrefixNamingStrategy extends DefaultNamingStrategy |
|
1192
|
|
|
{ |
|
1193
|
|
|
/** |
|
1194
|
|
|
* {@inheritdoc} |
|
1195
|
|
|
*/ |
|
1196
|
|
|
public function propertyToColumnName($propertyName, $className = null) |
|
1197
|
|
|
{ |
|
1198
|
|
|
return strtolower($this->classToTableName($className)) . '_' . $propertyName; |
|
1199
|
|
|
} |
|
1200
|
|
|
} |
|
1201
|
|
|
|
|
1202
|
|
|
class MyArrayObjectEntity extends \ArrayObject |
|
1203
|
|
|
{ |
|
1204
|
|
|
} |
|
1205
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.