1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
14
|
|
|
* |
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
16
|
|
|
* and is licensed under the MIT license. For more information, see |
17
|
|
|
* <http://www.doctrine-project.org>. |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
namespace DoctrineORMModuleTest\Yuml; |
21
|
|
|
|
22
|
|
|
use DoctrineORMModule\Yuml\MetadataGrapher; |
23
|
|
|
use PHPUnit_Framework_TestCase; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Tests for the metadata to string converter |
27
|
|
|
* |
28
|
|
|
* @license MIT |
29
|
|
|
* @link http://www.doctrine-project.org/ |
30
|
|
|
* @author Marco Pivetta <[email protected]> |
31
|
|
|
*/ |
32
|
|
|
class MetadataGrapherTest extends PHPUnit_Framework_TestCase |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* @var MetadataGrapher |
36
|
|
|
*/ |
37
|
|
|
protected $grapher; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* {@inheritDoc} |
41
|
|
|
*/ |
42
|
|
|
public function setUp() |
43
|
|
|
{ |
44
|
|
|
parent::setUp(); |
45
|
|
|
|
46
|
|
|
$this->grapher = new MetadataGrapher(); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @covers \DoctrineORMModule\Yuml\MetadataGrapher |
51
|
|
|
*/ |
52
|
|
|
public function testDrawSimpleEntity() |
53
|
|
|
{ |
54
|
|
|
$class = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata'); |
55
|
|
|
$class->expects($this->any())->method('getName')->will($this->returnValue('Simple\\Entity')); |
56
|
|
|
$class->expects($this->any())->method('getFieldNames')->will($this->returnValue(array())); |
57
|
|
|
$class->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array())); |
58
|
|
|
|
59
|
|
|
$this->assertSame('[Simple.Entity]', $this->grapher->generateFromMetadata(array($class))); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @covers \DoctrineORMModule\Yuml\MetadataGrapher |
64
|
|
|
*/ |
65
|
|
|
public function testDrawSimpleEntityWithFields() |
66
|
|
|
{ |
67
|
|
|
$class = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata'); |
68
|
|
|
$class->expects($this->any())->method('getName')->will($this->returnValue('Simple\\Entity')); |
69
|
|
|
$class->expects($this->any())->method('getFieldNames')->will($this->returnValue(array('a', 'b', 'c'))); |
70
|
|
|
$class->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array())); |
71
|
|
|
$class->expects($this->any())->method('isIdentifier')->will( |
72
|
|
|
$this->returnCallback( |
73
|
|
|
function ($field) { |
74
|
|
|
return $field === 'a'; |
75
|
|
|
} |
76
|
|
|
) |
77
|
|
|
); |
78
|
|
|
|
79
|
|
|
$this->assertSame('[Simple.Entity|+a;b;c]', $this->grapher->generateFromMetadata(array($class))); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @covers \DoctrineORMModule\Yuml\MetadataGrapher |
84
|
|
|
*/ |
85
|
|
|
public function testDrawOneToOneUniDirectionalAssociation() |
86
|
|
|
{ |
87
|
|
|
$class1 = $this->getMockBuilder('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata') |
88
|
|
|
->setMethods(array( |
89
|
|
|
'getName', |
90
|
|
|
'getIdentifier', |
91
|
|
|
'getReflectionClass', |
92
|
|
|
'isIdentifier', |
93
|
|
|
'hasField', |
94
|
|
|
'hasAssociation', |
95
|
|
|
'isSingleValuedAssociation', |
96
|
|
|
'isCollectionValuedAssociation', |
97
|
|
|
'getFieldNames', |
98
|
|
|
'getIdentifierFieldNames', |
99
|
|
|
'getAssociationNames', |
100
|
|
|
'getTypeOfField', |
101
|
|
|
'getAssociationTargetClass', |
102
|
|
|
'isAssociationInverseSide', |
103
|
|
|
'getAssociationMappedByTargetField', |
104
|
|
|
'getIdentifierValues', |
105
|
|
|
'getAssociationMapping', |
106
|
|
|
))->getMock(); |
107
|
|
|
$class1->expects($this->any())->method('getName')->will($this->returnValue('A')); |
108
|
|
|
$class1->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array('b'))); |
109
|
|
|
$class1->expects($this->any())->method('getAssociationTargetClass')->will($this->returnValue('B')); |
110
|
|
|
$class1->expects($this->any())->method('getAssociationMapping')->will($this->returnValue(array( |
111
|
|
|
'isOwningSide' => true, |
112
|
|
|
'mappedBy' => null, |
113
|
|
|
'inversedBy' =>null |
114
|
|
|
))); |
115
|
|
|
|
116
|
|
|
$class1->expects($this->any())->method('isAssociationInverseSide')->will($this->returnValue(false)); |
117
|
|
|
$class1->expects($this->any())->method('isCollectionValuedAssociation')->will($this->returnValue(false)); |
118
|
|
|
$class1->expects($this->any())->method('getFieldNames')->will($this->returnValue(array())); |
119
|
|
|
|
120
|
|
|
$class2 = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata'); |
121
|
|
|
$class2->expects($this->any())->method('getName')->will($this->returnValue('B')); |
122
|
|
|
$class2->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array())); |
123
|
|
|
$class2->expects($this->any())->method('getFieldNames')->will($this->returnValue(array())); |
124
|
|
|
|
125
|
|
|
$this->assertSame('[A]-b 1>[B]', $this->grapher->generateFromMetadata(array($class1, $class2))); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @covers \DoctrineORMModule\Yuml\MetadataGrapher |
130
|
|
|
*/ |
131
|
|
|
public function testDrawOneToOneBiDirectionalAssociation() |
132
|
|
|
{ |
133
|
|
|
$class1 = $this->getMockBuilder('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata') |
134
|
|
|
->setMethods(array( |
135
|
|
|
'getName', |
136
|
|
|
'getIdentifier', |
137
|
|
|
'getReflectionClass', |
138
|
|
|
'isIdentifier', |
139
|
|
|
'hasField', |
140
|
|
|
'hasAssociation', |
141
|
|
|
'isSingleValuedAssociation', |
142
|
|
|
'isCollectionValuedAssociation', |
143
|
|
|
'getFieldNames', |
144
|
|
|
'getIdentifierFieldNames', |
145
|
|
|
'getAssociationNames', |
146
|
|
|
'getTypeOfField', |
147
|
|
|
'getAssociationTargetClass', |
148
|
|
|
'isAssociationInverseSide', |
149
|
|
|
'getAssociationMappedByTargetField', |
150
|
|
|
'getIdentifierValues', |
151
|
|
|
'getAssociationMapping', |
152
|
|
|
))->getMock(); |
153
|
|
|
$class1->expects($this->any())->method('getName')->will($this->returnValue('A')); |
154
|
|
|
$class1->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array('b'))); |
155
|
|
|
$class1->expects($this->any())->method('getAssociationTargetClass')->will($this->returnValue('B')); |
156
|
|
|
$class1->expects($this->any())->method('getAssociationMapping')->will($this->returnValue(array( |
157
|
|
|
'isOwningSide' => true, |
158
|
|
|
'mappedBy' => null, |
159
|
|
|
'inversedBy' =>'a' |
160
|
|
|
))); |
161
|
|
|
$class1->expects($this->any())->method('isAssociationInverseSide')->will($this->returnValue(false)); |
162
|
|
|
$class1->expects($this->any())->method('isCollectionValuedAssociation')->will($this->returnValue(false)); |
163
|
|
|
$class1->expects($this->any())->method('getFieldNames')->will($this->returnValue(array())); |
164
|
|
|
|
165
|
|
|
$class2 = $this->getMockBuilder('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata') |
166
|
|
|
->setMethods(array( |
167
|
|
|
'getName', |
168
|
|
|
'getIdentifier', |
169
|
|
|
'getReflectionClass', |
170
|
|
|
'isIdentifier', |
171
|
|
|
'hasField', |
172
|
|
|
'hasAssociation', |
173
|
|
|
'isSingleValuedAssociation', |
174
|
|
|
'isCollectionValuedAssociation', |
175
|
|
|
'getFieldNames', |
176
|
|
|
'getIdentifierFieldNames', |
177
|
|
|
'getAssociationNames', |
178
|
|
|
'getTypeOfField', |
179
|
|
|
'getAssociationTargetClass', |
180
|
|
|
'isAssociationInverseSide', |
181
|
|
|
'getAssociationMappedByTargetField', |
182
|
|
|
'getIdentifierValues', |
183
|
|
|
'getAssociationMapping', |
184
|
|
|
))->getMock(); |
185
|
|
|
$class2->expects($this->any())->method('getName')->will($this->returnValue('B')); |
186
|
|
|
$class2->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array('a'))); |
187
|
|
|
$class2->expects($this->any())->method('getAssociationTargetClass')->will($this->returnValue('A')); |
188
|
|
|
$class2->expects($this->any())->method('getAssociationMapping')->will($this->returnValue(array( |
189
|
|
|
'isOwningSide' => false, |
190
|
|
|
'mappedBy' => 'b', |
191
|
|
|
'inversedBy' => null |
192
|
|
|
))); |
193
|
|
|
$class2->expects($this->any())->method('isAssociationInverseSide')->will($this->returnValue(true)); |
194
|
|
|
$class2->expects($this->any())->method('isCollectionValuedAssociation')->will($this->returnValue(false)); |
195
|
|
|
$class2->expects($this->any())->method('getAssociationMappedByTargetField')->will($this->returnValue('b')); |
196
|
|
|
$class2->expects($this->any())->method('getFieldNames')->will($this->returnValue(array())); |
197
|
|
|
|
198
|
|
|
$this->assertSame('[A]<>a 1-b 1>[B]', $this->grapher->generateFromMetadata(array($class1, $class2))); |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* @covers \DoctrineORMModule\Yuml\MetadataGrapher |
203
|
|
|
*/ |
204
|
|
|
public function testDrawOneToOneBiDirectionalInverseAssociation() |
205
|
|
|
{ |
206
|
|
|
$class1 = $this->getMockBuilder('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata') |
207
|
|
|
->setMethods(array( |
208
|
|
|
'getName', |
209
|
|
|
'getIdentifier', |
210
|
|
|
'getReflectionClass', |
211
|
|
|
'isIdentifier', |
212
|
|
|
'hasField', |
213
|
|
|
'hasAssociation', |
214
|
|
|
'isSingleValuedAssociation', |
215
|
|
|
'isCollectionValuedAssociation', |
216
|
|
|
'getFieldNames', |
217
|
|
|
'getIdentifierFieldNames', |
218
|
|
|
'getAssociationNames', |
219
|
|
|
'getTypeOfField', |
220
|
|
|
'getAssociationTargetClass', |
221
|
|
|
'isAssociationInverseSide', |
222
|
|
|
'getAssociationMappedByTargetField', |
223
|
|
|
'getIdentifierValues', |
224
|
|
|
'getAssociationMapping', |
225
|
|
|
))->getMock(); |
226
|
|
|
$class1->expects($this->any())->method('getName')->will($this->returnValue('A')); |
227
|
|
|
$class1->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array('b'))); |
228
|
|
|
$class1->expects($this->any())->method('getAssociationTargetClass')->will($this->returnValue('B')); |
229
|
|
|
$class1->expects($this->any())->method('getAssociationMapping')->will($this->returnValue(array( |
230
|
|
|
'isOwningSide' => false, |
231
|
|
|
'mappedBy' => 'a', |
232
|
|
|
'inversedBy' => null |
233
|
|
|
))); |
234
|
|
|
$class1->expects($this->any())->method('isAssociationInverseSide')->will($this->returnValue(true)); |
235
|
|
|
$class1->expects($this->any())->method('isCollectionValuedAssociation')->will($this->returnValue(false)); |
236
|
|
|
$class1->expects($this->any())->method('getAssociationMappedByTargetField')->will($this->returnValue('a')); |
237
|
|
|
$class1->expects($this->any())->method('getFieldNames')->will($this->returnValue(array())); |
238
|
|
|
|
239
|
|
|
$class2 = $this->getMockBuilder('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata') |
240
|
|
|
->setMethods(array( |
241
|
|
|
'getName', |
242
|
|
|
'getIdentifier', |
243
|
|
|
'getReflectionClass', |
244
|
|
|
'isIdentifier', |
245
|
|
|
'hasField', |
246
|
|
|
'hasAssociation', |
247
|
|
|
'isSingleValuedAssociation', |
248
|
|
|
'isCollectionValuedAssociation', |
249
|
|
|
'getFieldNames', |
250
|
|
|
'getIdentifierFieldNames', |
251
|
|
|
'getAssociationNames', |
252
|
|
|
'getTypeOfField', |
253
|
|
|
'getAssociationTargetClass', |
254
|
|
|
'isAssociationInverseSide', |
255
|
|
|
'getAssociationMappedByTargetField', |
256
|
|
|
'getIdentifierValues', |
257
|
|
|
'getAssociationMapping', |
258
|
|
|
))->getMock(); |
259
|
|
|
$class2->expects($this->any())->method('getName')->will($this->returnValue('B')); |
260
|
|
|
$class2->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array('a'))); |
261
|
|
|
$class2->expects($this->any())->method('getAssociationTargetClass')->will($this->returnValue('A')); |
262
|
|
|
$class2->expects($this->any())->method('getAssociationMapping')->will($this->returnValue(array( |
263
|
|
|
'isOwningSide' => true, |
264
|
|
|
'mappedBy' => null, |
265
|
|
|
'inversedBy' => 'a' |
266
|
|
|
))); |
267
|
|
|
$class2->expects($this->any())->method('isAssociationInverseSide')->will($this->returnValue(false)); |
268
|
|
|
$class2->expects($this->any())->method('isCollectionValuedAssociation')->will($this->returnValue(false)); |
269
|
|
|
$class2->expects($this->any())->method('getFieldNames')->will($this->returnValue(array())); |
270
|
|
|
$expected = "[A]<a 1-b 1<>[B]"; |
271
|
|
|
$this->assertSame($expected, $this->grapher->generateFromMetadata(array($class1, $class2))); |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
/** |
275
|
|
|
* @covers \DoctrineORMModule\Yuml\MetadataGrapher |
276
|
|
|
*/ |
277
|
|
|
public function testDrawOneToManyBiDirectionalAssociation() |
278
|
|
|
{ |
279
|
|
|
$class1 = $this->getMockBuilder('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata') |
280
|
|
|
->setMethods(array( |
281
|
|
|
'getName', |
282
|
|
|
'getIdentifier', |
283
|
|
|
'getReflectionClass', |
284
|
|
|
'isIdentifier', |
285
|
|
|
'hasField', |
286
|
|
|
'hasAssociation', |
287
|
|
|
'isSingleValuedAssociation', |
288
|
|
|
'isCollectionValuedAssociation', |
289
|
|
|
'getFieldNames', |
290
|
|
|
'getIdentifierFieldNames', |
291
|
|
|
'getAssociationNames', |
292
|
|
|
'getTypeOfField', |
293
|
|
|
'getAssociationTargetClass', |
294
|
|
|
'isAssociationInverseSide', |
295
|
|
|
'getAssociationMappedByTargetField', |
296
|
|
|
'getIdentifierValues', |
297
|
|
|
'getAssociationMapping', |
298
|
|
|
))->getMock(); |
299
|
|
|
$class1->expects($this->any())->method('getName')->will($this->returnValue('A')); |
300
|
|
|
$class1->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array('b'))); |
301
|
|
|
$class1->expects($this->any())->method('getAssociationTargetClass')->will($this->returnValue('B')); |
302
|
|
|
$class1->expects($this->any())->method('getAssociationMapping')->will($this->returnValue(array( |
303
|
|
|
'isOwningSide' => true, |
304
|
|
|
'mappedBy' => null, |
305
|
|
|
'inversedBy' => 'a' |
306
|
|
|
))); |
307
|
|
|
$class1->expects($this->any())->method('isAssociationInverseSide')->will($this->returnValue(false)); |
308
|
|
|
$class1->expects($this->any())->method('isCollectionValuedAssociation')->will($this->returnValue(true)); |
309
|
|
|
$class1->expects($this->any())->method('getFieldNames')->will($this->returnValue(array())); |
310
|
|
|
|
311
|
|
|
$class2 = $this->getMockBuilder('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata') |
312
|
|
|
->setMethods(array( |
313
|
|
|
'getName', |
314
|
|
|
'getIdentifier', |
315
|
|
|
'getReflectionClass', |
316
|
|
|
'isIdentifier', |
317
|
|
|
'hasField', |
318
|
|
|
'hasAssociation', |
319
|
|
|
'isSingleValuedAssociation', |
320
|
|
|
'isCollectionValuedAssociation', |
321
|
|
|
'getFieldNames', |
322
|
|
|
'getIdentifierFieldNames', |
323
|
|
|
'getAssociationNames', |
324
|
|
|
'getTypeOfField', |
325
|
|
|
'getAssociationTargetClass', |
326
|
|
|
'isAssociationInverseSide', |
327
|
|
|
'getAssociationMappedByTargetField', |
328
|
|
|
'getIdentifierValues', |
329
|
|
|
'getAssociationMapping', |
330
|
|
|
))->getMock(); |
331
|
|
|
$class2->expects($this->any())->method('getName')->will($this->returnValue('B')); |
332
|
|
|
$class2->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array('a'))); |
333
|
|
|
$class2->expects($this->any())->method('getAssociationTargetClass')->will($this->returnValue('A')); |
334
|
|
|
$class2->expects($this->any())->method('getAssociationMapping')->will($this->returnValue(array( |
335
|
|
|
'isOwningSide' => false, |
336
|
|
|
'mappedBy' => 'b', |
337
|
|
|
'inversedBy' => null |
338
|
|
|
))); |
339
|
|
|
$class2->expects($this->any())->method('isAssociationInverseSide')->will($this->returnValue(true)); |
340
|
|
|
$class2->expects($this->any())->method('isCollectionValuedAssociation')->will($this->returnValue(false)); |
341
|
|
|
$class2->expects($this->any())->method('getAssociationMappedByTargetField')->will($this->returnValue('b')); |
342
|
|
|
$class2->expects($this->any())->method('getFieldNames')->will($this->returnValue(array())); |
343
|
|
|
|
344
|
|
|
$this->assertSame('[A]<>a 1-b *>[B]', $this->grapher->generateFromMetadata(array($class1, $class2))); |
345
|
|
|
} |
346
|
|
|
|
347
|
|
|
/** |
348
|
|
|
* @covers \DoctrineORMModule\Yuml\MetadataGrapher |
349
|
|
|
*/ |
350
|
|
|
public function testDrawOneToManyBiDirectionalInverseAssociation() |
351
|
|
|
{ |
352
|
|
|
$class1 = $this->getMockBuilder('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata') |
353
|
|
|
->setMethods(array( |
354
|
|
|
'getName', |
355
|
|
|
'getIdentifier', |
356
|
|
|
'getReflectionClass', |
357
|
|
|
'isIdentifier', |
358
|
|
|
'hasField', |
359
|
|
|
'hasAssociation', |
360
|
|
|
'isSingleValuedAssociation', |
361
|
|
|
'isCollectionValuedAssociation', |
362
|
|
|
'getFieldNames', |
363
|
|
|
'getIdentifierFieldNames', |
364
|
|
|
'getAssociationNames', |
365
|
|
|
'getTypeOfField', |
366
|
|
|
'getAssociationTargetClass', |
367
|
|
|
'isAssociationInverseSide', |
368
|
|
|
'getAssociationMappedByTargetField', |
369
|
|
|
'getIdentifierValues', |
370
|
|
|
'getAssociationMapping', |
371
|
|
|
))->getMock(); |
372
|
|
|
$class1->expects($this->any())->method('getName')->will($this->returnValue('A')); |
373
|
|
|
$class1->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array('b'))); |
374
|
|
|
$class1->expects($this->any())->method('getAssociationTargetClass')->will($this->returnValue('B')); |
375
|
|
|
$class1->expects($this->any())->method('getAssociationMapping')->will($this->returnValue(array( |
376
|
|
|
'isOwningSide' => true, |
377
|
|
|
'mappedBy' => null, |
378
|
|
|
'inversedBy' => 'a' |
379
|
|
|
))); |
380
|
|
|
$class1->expects($this->any())->method('isAssociationInverseSide')->will($this->returnValue(false)); |
381
|
|
|
$class1->expects($this->any())->method('isCollectionValuedAssociation')->will($this->returnValue(false)); |
382
|
|
|
$class1->expects($this->any())->method('getFieldNames')->will($this->returnValue(array())); |
383
|
|
|
|
384
|
|
|
$class2 = $this->getMockBuilder('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata') |
385
|
|
|
->setMethods(array( |
386
|
|
|
'getName', |
387
|
|
|
'getIdentifier', |
388
|
|
|
'getReflectionClass', |
389
|
|
|
'isIdentifier', |
390
|
|
|
'hasField', |
391
|
|
|
'hasAssociation', |
392
|
|
|
'isSingleValuedAssociation', |
393
|
|
|
'isCollectionValuedAssociation', |
394
|
|
|
'getFieldNames', |
395
|
|
|
'getIdentifierFieldNames', |
396
|
|
|
'getAssociationNames', |
397
|
|
|
'getTypeOfField', |
398
|
|
|
'getAssociationTargetClass', |
399
|
|
|
'isAssociationInverseSide', |
400
|
|
|
'getAssociationMappedByTargetField', |
401
|
|
|
'getIdentifierValues', |
402
|
|
|
'getAssociationMapping', |
403
|
|
|
))->getMock(); |
404
|
|
|
$class2->expects($this->any())->method('getName')->will($this->returnValue('B')); |
405
|
|
|
$class2->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array('a'))); |
406
|
|
|
$class2->expects($this->any())->method('getAssociationTargetClass')->will($this->returnValue('A')); |
407
|
|
|
$class2->expects($this->any())->method('getAssociationMapping')->will($this->returnValue(array( |
408
|
|
|
'isOwningSide' => false, |
409
|
|
|
'mappedBy' => 'b', |
410
|
|
|
'inversedBy' => null |
411
|
|
|
))); |
412
|
|
|
$class2->expects($this->any())->method('isAssociationInverseSide')->will($this->returnValue(true)); |
413
|
|
|
$class2->expects($this->any())->method('isCollectionValuedAssociation')->will($this->returnValue(true)); |
414
|
|
|
$class2->expects($this->any())->method('getAssociationMappedByTargetField')->will($this->returnValue('b')); |
415
|
|
|
$class2->expects($this->any())->method('getFieldNames')->will($this->returnValue(array())); |
416
|
|
|
|
417
|
|
|
$this->assertSame('[A]<>a *-b 1>[B]', $this->grapher->generateFromMetadata(array($class1, $class2))); |
418
|
|
|
} |
419
|
|
|
|
420
|
|
|
/** |
421
|
|
|
* @covers \DoctrineORMModule\Yuml\MetadataGrapher |
422
|
|
|
*/ |
423
|
|
|
public function testDrawManyToManyUniDirectionalAssociation() |
424
|
|
|
{ |
425
|
|
|
$class1 = $this->getMockBuilder('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata') |
426
|
|
|
->setMethods(array( |
427
|
|
|
'getName', |
428
|
|
|
'getIdentifier', |
429
|
|
|
'getReflectionClass', |
430
|
|
|
'isIdentifier', |
431
|
|
|
'hasField', |
432
|
|
|
'hasAssociation', |
433
|
|
|
'isSingleValuedAssociation', |
434
|
|
|
'isCollectionValuedAssociation', |
435
|
|
|
'getFieldNames', |
436
|
|
|
'getIdentifierFieldNames', |
437
|
|
|
'getAssociationNames', |
438
|
|
|
'getTypeOfField', |
439
|
|
|
'getAssociationTargetClass', |
440
|
|
|
'isAssociationInverseSide', |
441
|
|
|
'getAssociationMappedByTargetField', |
442
|
|
|
'getIdentifierValues', |
443
|
|
|
'getAssociationMapping', |
444
|
|
|
))->getMock(); |
445
|
|
|
$class1->expects($this->any())->method('getName')->will($this->returnValue('A')); |
446
|
|
|
$class1->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array('b'))); |
447
|
|
|
$class1->expects($this->any())->method('getAssociationTargetClass')->will($this->returnValue('B')); |
448
|
|
|
$class1->expects($this->any())->method('getAssociationMapping')->will($this->returnValue(array( |
449
|
|
|
'isOwningSide' => true, |
450
|
|
|
'mappedBy' => null, |
451
|
|
|
'inversedBy' => null |
452
|
|
|
))); |
453
|
|
|
$class1->expects($this->any())->method('isAssociationInverseSide')->will($this->returnValue(false)); |
454
|
|
|
$class1->expects($this->any())->method('isCollectionValuedAssociation')->will($this->returnValue(true)); |
455
|
|
|
$class1->expects($this->any())->method('getFieldNames')->will($this->returnValue(array())); |
456
|
|
|
|
457
|
|
|
$class2 = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata'); |
458
|
|
|
$class2->expects($this->any())->method('getName')->will($this->returnValue('B')); |
459
|
|
|
$class2->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array())); |
460
|
|
|
$class2->expects($this->any())->method('getFieldNames')->will($this->returnValue(array())); |
461
|
|
|
|
462
|
|
|
$this->assertSame('[A]-b *>[B]', $this->grapher->generateFromMetadata(array($class1, $class2))); |
463
|
|
|
} |
464
|
|
|
|
465
|
|
|
/** |
466
|
|
|
* @covers \DoctrineORMModule\Yuml\MetadataGrapher |
467
|
|
|
*/ |
468
|
|
|
public function testDrawManyToManyUniDirectionalInverseAssociation() |
469
|
|
|
{ |
470
|
|
|
$class1 = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata'); |
471
|
|
|
$class1->expects($this->any())->method('getName')->will($this->returnValue('A')); |
472
|
|
|
$class1->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array())); |
473
|
|
|
$class1->expects($this->any())->method('getFieldNames')->will($this->returnValue(array())); |
474
|
|
|
|
475
|
|
|
$class2 = $this->getMockBuilder('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata') |
476
|
|
|
->setMethods(array( |
477
|
|
|
'getName', |
478
|
|
|
'getIdentifier', |
479
|
|
|
'getReflectionClass', |
480
|
|
|
'isIdentifier', |
481
|
|
|
'hasField', |
482
|
|
|
'hasAssociation', |
483
|
|
|
'isSingleValuedAssociation', |
484
|
|
|
'isCollectionValuedAssociation', |
485
|
|
|
'getFieldNames', |
486
|
|
|
'getIdentifierFieldNames', |
487
|
|
|
'getAssociationNames', |
488
|
|
|
'getTypeOfField', |
489
|
|
|
'getAssociationTargetClass', |
490
|
|
|
'isAssociationInverseSide', |
491
|
|
|
'getAssociationMappedByTargetField', |
492
|
|
|
'getIdentifierValues', |
493
|
|
|
'getAssociationMapping', |
494
|
|
|
))->getMock(); |
495
|
|
|
$class2->expects($this->any())->method('getName')->will($this->returnValue('B')); |
496
|
|
|
$class2->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array('a'))); |
497
|
|
|
$class2->expects($this->any())->method('getAssociationTargetClass')->will($this->returnValue('A')); |
498
|
|
|
$class2->expects($this->any())->method('getAssociationMapping')->will($this->returnValue(null)); |
499
|
|
|
$class2->expects($this->any())->method('getAssociationMapping')->will($this->returnValue(array( |
500
|
|
|
'isOwningSide' => true, |
501
|
|
|
'mappedBy' => null, |
502
|
|
|
'inversedBy' => null |
503
|
|
|
))); |
504
|
|
|
$class2->expects($this->any())->method('isAssociationInverseSide')->will($this->returnValue(false)); |
505
|
|
|
$class2->expects($this->any())->method('isCollectionValuedAssociation')->will($this->returnValue(true)); |
506
|
|
|
$class2->expects($this->any())->method('getFieldNames')->will($this->returnValue(array())); |
507
|
|
|
|
508
|
|
|
$this->assertSame('[A],[B]-a *>[A]', $this->grapher->generateFromMetadata(array($class1, $class2))); |
509
|
|
|
} |
510
|
|
|
|
511
|
|
|
/** |
512
|
|
|
* @covers \DoctrineORMModule\Yuml\MetadataGrapher |
513
|
|
|
*/ |
514
|
|
|
public function testDrawManyToManyBiDirectionalAssociation() |
515
|
|
|
{ |
516
|
|
|
$class1 = $this->getMockBuilder('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata') |
517
|
|
|
->setMethods(array( |
518
|
|
|
'getName', |
519
|
|
|
'getIdentifier', |
520
|
|
|
'getReflectionClass', |
521
|
|
|
'isIdentifier', |
522
|
|
|
'hasField', |
523
|
|
|
'hasAssociation', |
524
|
|
|
'isSingleValuedAssociation', |
525
|
|
|
'isCollectionValuedAssociation', |
526
|
|
|
'getFieldNames', |
527
|
|
|
'getIdentifierFieldNames', |
528
|
|
|
'getAssociationNames', |
529
|
|
|
'getTypeOfField', |
530
|
|
|
'getAssociationTargetClass', |
531
|
|
|
'isAssociationInverseSide', |
532
|
|
|
'getAssociationMappedByTargetField', |
533
|
|
|
'getIdentifierValues', |
534
|
|
|
'getAssociationMapping', |
535
|
|
|
))->getMock(); |
536
|
|
|
$class1->expects($this->any())->method('getName')->will($this->returnValue('A')); |
537
|
|
|
$class1->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array('b'))); |
538
|
|
|
$class1->expects($this->any())->method('getAssociationTargetClass')->will($this->returnValue('B')); |
539
|
|
|
$class1->expects($this->any())->method('getAssociationMapping')->will($this->returnValue(array( |
540
|
|
|
'isOwningSide' => true, |
541
|
|
|
'mappedBy' => null, |
542
|
|
|
'inversedBy' => 'a' |
543
|
|
|
))); |
544
|
|
|
$class1->expects($this->any())->method('isAssociationInverseSide')->will($this->returnValue(false)); |
545
|
|
|
$class1->expects($this->any())->method('isCollectionValuedAssociation')->will($this->returnValue(true)); |
546
|
|
|
$class1->expects($this->any())->method('getFieldNames')->will($this->returnValue(array())); |
547
|
|
|
|
548
|
|
|
$class2 = $this->getMockBuilder('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata') |
549
|
|
|
->setMethods(array( |
550
|
|
|
'getName', |
551
|
|
|
'getIdentifier', |
552
|
|
|
'getReflectionClass', |
553
|
|
|
'isIdentifier', |
554
|
|
|
'hasField', |
555
|
|
|
'hasAssociation', |
556
|
|
|
'isSingleValuedAssociation', |
557
|
|
|
'isCollectionValuedAssociation', |
558
|
|
|
'getFieldNames', |
559
|
|
|
'getIdentifierFieldNames', |
560
|
|
|
'getAssociationNames', |
561
|
|
|
'getTypeOfField', |
562
|
|
|
'getAssociationTargetClass', |
563
|
|
|
'isAssociationInverseSide', |
564
|
|
|
'getAssociationMappedByTargetField', |
565
|
|
|
'getIdentifierValues', |
566
|
|
|
'getAssociationMapping', |
567
|
|
|
))->getMock(); |
568
|
|
|
$class2->expects($this->any())->method('getName')->will($this->returnValue('B')); |
569
|
|
|
$class2->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array('a'))); |
570
|
|
|
$class2->expects($this->any())->method('getAssociationTargetClass')->will($this->returnValue('A')); |
571
|
|
|
$class1->expects($this->any())->method('getAssociationMapping')->will($this->returnValue(array( |
572
|
|
|
'isOwningSide' => false, |
573
|
|
|
'mappedBy' => 'a', |
574
|
|
|
'inversedBy' => null |
575
|
|
|
))); |
576
|
|
|
$class2->expects($this->any())->method('isAssociationInverseSide')->will($this->returnValue(true)); |
577
|
|
|
$class2->expects($this->any())->method('isCollectionValuedAssociation')->will($this->returnValue(true)); |
578
|
|
|
$class2->expects($this->any())->method('getAssociationMappedByTargetField')->will($this->returnValue('b')); |
579
|
|
|
$class2->expects($this->any())->method('getFieldNames')->will($this->returnValue(array())); |
580
|
|
|
|
581
|
|
|
$this->assertSame('[A]<>a *-b *>[B]', $this->grapher->generateFromMetadata(array($class1, $class2))); |
582
|
|
|
} |
583
|
|
|
|
584
|
|
|
/** |
585
|
|
|
* @covers \DoctrineORMModule\Yuml\MetadataGrapher |
586
|
|
|
*/ |
587
|
|
|
public function testDrawManyToManyBiDirectionalInverseAssociation() |
588
|
|
|
{ |
589
|
|
|
$class1 = $this->getMockBuilder('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata') |
590
|
|
|
->setMethods(array( |
591
|
|
|
'getName', |
592
|
|
|
'getIdentifier', |
593
|
|
|
'getReflectionClass', |
594
|
|
|
'isIdentifier', |
595
|
|
|
'hasField', |
596
|
|
|
'hasAssociation', |
597
|
|
|
'isSingleValuedAssociation', |
598
|
|
|
'isCollectionValuedAssociation', |
599
|
|
|
'getFieldNames', |
600
|
|
|
'getIdentifierFieldNames', |
601
|
|
|
'getAssociationNames', |
602
|
|
|
'getTypeOfField', |
603
|
|
|
'getAssociationTargetClass', |
604
|
|
|
'isAssociationInverseSide', |
605
|
|
|
'getAssociationMappedByTargetField', |
606
|
|
|
'getIdentifierValues', |
607
|
|
|
'getAssociationMapping', |
608
|
|
|
))->getMock(); |
609
|
|
|
$class1->expects($this->any())->method('getName')->will($this->returnValue('A')); |
610
|
|
|
$class1->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array('b'))); |
611
|
|
|
$class1->expects($this->any())->method('getAssociationTargetClass')->will($this->returnValue('B')); |
612
|
|
|
$class1->expects($this->any())->method('getAssociationMapping')->will($this->returnValue(array( |
613
|
|
|
'isOwningSide' => false, |
614
|
|
|
'mappedBy' => 'a', |
615
|
|
|
'inversedBy' => null |
616
|
|
|
))); |
617
|
|
|
$class1->expects($this->any())->method('isAssociationInverseSide')->will($this->returnValue(true)); |
618
|
|
|
$class1->expects($this->any())->method('isCollectionValuedAssociation')->will($this->returnValue(true)); |
619
|
|
|
$class1->expects($this->any())->method('getAssociationMappedByTargetField')->will($this->returnValue('a')); |
620
|
|
|
$class1->expects($this->any())->method('getFieldNames')->will($this->returnValue(array())); |
621
|
|
|
|
622
|
|
|
$class2 = $this->getMockBuilder('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata') |
623
|
|
|
->setMethods(array( |
624
|
|
|
'getName', |
625
|
|
|
'getIdentifier', |
626
|
|
|
'getReflectionClass', |
627
|
|
|
'isIdentifier', |
628
|
|
|
'hasField', |
629
|
|
|
'hasAssociation', |
630
|
|
|
'isSingleValuedAssociation', |
631
|
|
|
'isCollectionValuedAssociation', |
632
|
|
|
'getFieldNames', |
633
|
|
|
'getIdentifierFieldNames', |
634
|
|
|
'getAssociationNames', |
635
|
|
|
'getTypeOfField', |
636
|
|
|
'getAssociationTargetClass', |
637
|
|
|
'isAssociationInverseSide', |
638
|
|
|
'getAssociationMappedByTargetField', |
639
|
|
|
'getIdentifierValues', |
640
|
|
|
'getAssociationMapping', |
641
|
|
|
))->getMock(); |
642
|
|
|
$class2->expects($this->any())->method('getName')->will($this->returnValue('B')); |
643
|
|
|
$class2->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array('a'))); |
644
|
|
|
$class2->expects($this->any())->method('getAssociationTargetClass')->will($this->returnValue('A')); |
645
|
|
|
$class2->expects($this->any())->method('getAssociationMapping')->will($this->returnValue(array( |
646
|
|
|
'isOwningSide' => true, |
647
|
|
|
'mappedBy' => null, |
648
|
|
|
'inversedBy' => 'b' |
649
|
|
|
))); |
650
|
|
|
$class2->expects($this->any())->method('isAssociationInverseSide')->will($this->returnValue(false)); |
651
|
|
|
$class2->expects($this->any())->method('isCollectionValuedAssociation')->will($this->returnValue(true)); |
652
|
|
|
$class2->expects($this->any())->method('getFieldNames')->will($this->returnValue(array())); |
653
|
|
|
|
654
|
|
|
$this->assertSame('[A]<a *-b *<>[B]', $this->grapher->generateFromMetadata(array($class1, $class2))); |
655
|
|
|
} |
656
|
|
|
|
657
|
|
|
/** |
658
|
|
|
* @covers \DoctrineORMModule\Yuml\MetadataGrapher |
659
|
|
|
*/ |
660
|
|
|
public function testDrawManyToManyAssociationWithoutKnownInverseSide() |
661
|
|
|
{ |
662
|
|
|
$class1 = $this->getMockBuilder('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata') |
663
|
|
|
->setMethods(array( |
664
|
|
|
'getName', |
665
|
|
|
'getIdentifier', |
666
|
|
|
'getReflectionClass', |
667
|
|
|
'isIdentifier', |
668
|
|
|
'hasField', |
669
|
|
|
'hasAssociation', |
670
|
|
|
'isSingleValuedAssociation', |
671
|
|
|
'isCollectionValuedAssociation', |
672
|
|
|
'getFieldNames', |
673
|
|
|
'getIdentifierFieldNames', |
674
|
|
|
'getAssociationNames', |
675
|
|
|
'getTypeOfField', |
676
|
|
|
'getAssociationTargetClass', |
677
|
|
|
'isAssociationInverseSide', |
678
|
|
|
'getAssociationMappedByTargetField', |
679
|
|
|
'getIdentifierValues', |
680
|
|
|
'getAssociationMapping', |
681
|
|
|
))->getMock(); |
682
|
|
|
$class1->expects($this->any())->method('getName')->will($this->returnValue('A')); |
683
|
|
|
$class1->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array('b'))); |
684
|
|
|
$class1->expects($this->any())->method('getAssociationTargetClass')->will($this->returnValue('B')); |
685
|
|
|
$class1->expects($this->any())->method('getAssociationMapping')->will($this->returnValue(array( |
686
|
|
|
'isOwningSide' => true, |
687
|
|
|
'mappedBy' => null, |
688
|
|
|
'inversedBy' => null |
689
|
|
|
))); |
690
|
|
|
$class1->expects($this->any())->method('isAssociationInverseSide')->will($this->returnValue(false)); |
691
|
|
|
$class1->expects($this->any())->method('isCollectionValuedAssociation')->will($this->returnValue(true)); |
692
|
|
|
$class1->expects($this->any())->method('getFieldNames')->will($this->returnValue(array())); |
693
|
|
|
|
694
|
|
|
$this->assertSame('[A]<>-b *>[B]', $this->grapher->generateFromMetadata(array($class1))); |
695
|
|
|
} |
696
|
|
|
|
697
|
|
|
/** |
698
|
|
|
* @covers \DoctrineORMModule\Yuml\MetadataGrapher |
699
|
|
|
*/ |
700
|
|
|
public function testDrawInheritance() |
701
|
|
|
{ |
702
|
|
|
$class1 = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata'); |
703
|
|
|
$class2 = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata'); |
704
|
|
|
$child = get_class($this->getMock('stdClass')); |
705
|
|
|
$class1->expects($this->any())->method('getName')->will($this->returnValue('stdClass')); |
706
|
|
|
$class1->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array())); |
707
|
|
|
$class1->expects($this->any())->method('getFieldNames')->will($this->returnValue(array())); |
708
|
|
|
$class2->expects($this->any())->method('getName')->will($this->returnValue($child)); |
709
|
|
|
$class2->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array())); |
710
|
|
|
$class2->expects($this->any())->method('getFieldNames')->will($this->returnValue(array())); |
711
|
|
|
|
712
|
|
|
$this->assertSame( |
713
|
|
|
'[stdClass]^[' . str_replace('\\', '.', $child) . ']', |
714
|
|
|
$this->grapher->generateFromMetadata(array($class2, $class1)) |
715
|
|
|
); |
716
|
|
|
} |
717
|
|
|
|
718
|
|
|
/** |
719
|
|
|
* @covers \DoctrineORMModule\Yuml\MetadataGrapher |
720
|
|
|
*/ |
721
|
|
|
public function testDrawInheritedFields() |
722
|
|
|
{ |
723
|
|
|
$class1 = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata'); |
724
|
|
|
$class2 = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata'); |
725
|
|
|
$child = get_class($this->getMock('stdClass')); |
726
|
|
|
|
727
|
|
|
$class1->expects($this->any())->method('getName')->will($this->returnValue('stdClass')); |
728
|
|
|
$class1->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array())); |
729
|
|
|
$class1->expects($this->any())->method('getFieldNames')->will($this->returnValue(array('inherited'))); |
730
|
|
|
|
731
|
|
|
$class2->expects($this->any())->method('getName')->will($this->returnValue($child)); |
732
|
|
|
$class2->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array())); |
733
|
|
|
$class2->expects($this->any())->method('getFieldNames')->will($this->returnValue(array('inherited', 'field2'))); |
734
|
|
|
|
735
|
|
|
$this->assertSame( |
736
|
|
|
'[stdClass|inherited]^[' . str_replace('\\', '.', $child) . '|field2]', |
737
|
|
|
$this->grapher->generateFromMetadata(array($class2, $class1)) |
738
|
|
|
); |
739
|
|
|
} |
740
|
|
|
|
741
|
|
|
/** |
742
|
|
|
* @covers \DoctrineORMModule\Yuml\MetadataGrapher |
743
|
|
|
*/ |
744
|
|
|
public function testDrawInheritedAssociations() |
745
|
|
|
{ |
746
|
|
|
$class1 = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata'); |
747
|
|
|
$class2 = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata'); |
748
|
|
|
$class3 = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata'); |
749
|
|
|
$class4 = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata'); |
750
|
|
|
$child = get_class($this->getMock('stdClass')); |
751
|
|
|
|
752
|
|
|
$class1->expects($this->any())->method('getName')->will($this->returnValue('stdClass')); |
753
|
|
|
$class1->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array('a'))); |
754
|
|
|
$class1->expects($this->any())->method('getAssociationTargetClass')->will($this->returnValue('A')); |
755
|
|
|
|
756
|
|
|
$class1->expects($this->any())->method('isAssociationInverseSide')->will($this->returnValue(false)); |
757
|
|
|
$class1->expects($this->any())->method('isCollectionValuedAssociation')->will($this->returnValue(true)); |
758
|
|
|
$class1->expects($this->any())->method('getFieldNames')->will($this->returnValue(array())); |
759
|
|
|
|
760
|
|
|
$class2->expects($this->any())->method('getName')->will($this->returnValue($child)); |
761
|
|
|
$class2->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array('a', 'b'))); |
762
|
|
|
$class2 |
763
|
|
|
->expects($this->any()) |
764
|
|
|
->method('getAssociationTargetClass') |
765
|
|
|
->will( |
766
|
|
|
$this->returnCallback( |
767
|
|
|
function ($assoc) { |
768
|
|
|
return strtoupper($assoc); |
769
|
|
|
} |
770
|
|
|
) |
771
|
|
|
); |
772
|
|
|
$class2->expects($this->any())->method('isAssociationInverseSide')->will($this->returnValue(false)); |
773
|
|
|
$class2->expects($this->any())->method('isCollectionValuedAssociation')->will($this->returnValue(true)); |
774
|
|
|
$class2->expects($this->any())->method('getFieldNames')->will($this->returnValue(array())); |
775
|
|
|
|
776
|
|
|
$class3->expects($this->any())->method('getName')->will($this->returnValue('A')); |
777
|
|
|
$class3->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array())); |
778
|
|
|
$class3->expects($this->any())->method('getFieldNames')->will($this->returnValue(array())); |
779
|
|
|
|
780
|
|
|
$class4->expects($this->any())->method('getName')->will($this->returnValue('B')); |
781
|
|
|
$class4->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array())); |
782
|
|
|
$class4->expects($this->any())->method('getFieldNames')->will($this->returnValue(array())); |
783
|
|
|
|
784
|
|
|
$childName = str_replace('\\', '.', $child); |
785
|
|
|
$this->assertSame( |
786
|
|
|
'[stdClass]<>-a *>[A],[stdClass]^[' . $childName . '],[' . $childName . ']<>-b *>[B]', |
787
|
|
|
$this->grapher->generateFromMetadata(array($class1, $class2)) |
788
|
|
|
); |
789
|
|
|
} |
790
|
|
|
|
791
|
|
|
/** |
792
|
|
|
* @covers \DoctrineORMModule\Yuml\MetadataGrapher |
793
|
|
|
* @dataProvider injectMultipleRelationsWithBothBiAndMonoDirectional |
794
|
|
|
*/ |
795
|
|
|
public function testDrawMultipleClassRelatedBothBiAndMonoDirectional($class1, $class2, $class3, $expected) |
796
|
|
|
{ |
797
|
|
|
$this->assertSame( |
798
|
|
|
$expected, |
799
|
|
|
$this->grapher->generateFromMetadata(array($class1, $class2,$class3)) |
800
|
|
|
); |
801
|
|
|
} |
802
|
|
|
|
803
|
|
|
/** |
804
|
|
|
* dataProvider to inject classes in every possible order into the test |
805
|
|
|
* testDrawMultipleClassRelatedBothBiAndMonoDirectional |
806
|
|
|
* |
807
|
|
|
* @return array |
808
|
|
|
*/ |
809
|
|
|
public function injectMultipleRelationsWithBothBiAndMonoDirectional() |
810
|
|
|
{ |
811
|
|
|
$class1 = $this->getMockBuilder('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata') |
812
|
|
|
->setMethods(array( |
813
|
|
|
'getName', |
814
|
|
|
'getIdentifier', |
815
|
|
|
'getReflectionClass', |
816
|
|
|
'isIdentifier', |
817
|
|
|
'hasField', |
818
|
|
|
'hasAssociation', |
819
|
|
|
'isSingleValuedAssociation', |
820
|
|
|
'isCollectionValuedAssociation', |
821
|
|
|
'getFieldNames', |
822
|
|
|
'getIdentifierFieldNames', |
823
|
|
|
'getAssociationNames', |
824
|
|
|
'getTypeOfField', |
825
|
|
|
'getAssociationTargetClass', |
826
|
|
|
'isAssociationInverseSide', |
827
|
|
|
'getAssociationMappedByTargetField', |
828
|
|
|
'getIdentifierValues', |
829
|
|
|
'getAssociationMapping', |
830
|
|
|
))->getMock(); |
831
|
|
|
$class1->expects($this->any())->method('getName')->will($this->returnValue('A')); |
832
|
|
|
$class1->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array('c'))); |
833
|
|
|
$class1->expects($this->any())->method('getAssociationTargetClass')->will($this->returnValue('C')); |
834
|
|
|
$class1->expects($this->any())->method('getAssociationMapping')->will($this->returnValue(array( |
835
|
|
|
'isOwningSide' => true, |
836
|
|
|
'mappedBy' => null, |
837
|
|
|
'inversedBy' => null |
838
|
|
|
))); |
839
|
|
|
$class1->expects($this->any())->method('isAssociationInverseSide')->will($this->returnValue(false)); |
840
|
|
|
$class1->expects($this->any())->method('isCollectionValuedAssociation')->will($this->returnValue(false)); |
841
|
|
|
$class1->expects($this->any())->method('getFieldNames')->will($this->returnValue(array())); |
842
|
|
|
|
843
|
|
|
|
844
|
|
|
$class2 = $this->getMockBuilder('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata') |
845
|
|
|
->setMethods(array( |
846
|
|
|
'getName', |
847
|
|
|
'getIdentifier', |
848
|
|
|
'getReflectionClass', |
849
|
|
|
'isIdentifier', |
850
|
|
|
'hasField', |
851
|
|
|
'hasAssociation', |
852
|
|
|
'isSingleValuedAssociation', |
853
|
|
|
'isCollectionValuedAssociation', |
854
|
|
|
'getFieldNames', |
855
|
|
|
'getIdentifierFieldNames', |
856
|
|
|
'getAssociationNames', |
857
|
|
|
'getTypeOfField', |
858
|
|
|
'getAssociationTargetClass', |
859
|
|
|
'isAssociationInverseSide', |
860
|
|
|
'getAssociationMappedByTargetField', |
861
|
|
|
'getIdentifierValues', |
862
|
|
|
'getAssociationMapping', |
863
|
|
|
))->getMock(); |
864
|
|
|
$class2->expects($this->any())->method('getName')->will($this->returnValue('B')); |
865
|
|
|
$class2->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array('c'))); |
866
|
|
|
$class2->expects($this->any())->method('getAssociationTargetClass')->will($this->returnValue('C')); |
867
|
|
|
$class2->expects($this->any())->method('getAssociationMapping')->will($this->returnValue(array( |
868
|
|
|
'isOwningSide' => true, |
869
|
|
|
'mappedBy' => null, |
870
|
|
|
'inversedBy' => 'b' |
871
|
|
|
))); |
872
|
|
|
$class2->expects($this->any())->method('isAssociationInverseSide')->will($this->returnValue(false)); |
873
|
|
|
$class2->expects($this->any())->method('isCollectionValuedAssociation')->will($this->returnValue(false)); |
874
|
|
|
$class2->expects($this->any())->method('getFieldNames')->will($this->returnValue(array())); |
875
|
|
|
|
876
|
|
|
|
877
|
|
|
$class3 = $this->getMockBuilder('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata') |
878
|
|
|
->setMethods(array( |
879
|
|
|
'getName', |
880
|
|
|
'getIdentifier', |
881
|
|
|
'getReflectionClass', |
882
|
|
|
'isIdentifier', |
883
|
|
|
'hasField', |
884
|
|
|
'hasAssociation', |
885
|
|
|
'isSingleValuedAssociation', |
886
|
|
|
'isCollectionValuedAssociation', |
887
|
|
|
'getFieldNames', |
888
|
|
|
'getIdentifierFieldNames', |
889
|
|
|
'getAssociationNames', |
890
|
|
|
'getTypeOfField', |
891
|
|
|
'getAssociationTargetClass', |
892
|
|
|
'isAssociationInverseSide', |
893
|
|
|
'getAssociationMappedByTargetField', |
894
|
|
|
'getIdentifierValues', |
895
|
|
|
'getAssociationMapping', |
896
|
|
|
))->getMock(); |
897
|
|
|
$class3->expects($this->any())->method('getName')->will($this->returnValue('C')); |
898
|
|
|
$class3->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array('b'))); |
899
|
|
|
$class3->expects($this->any())->method('getAssociationTargetClass')->will($this->returnValue('B')); |
900
|
|
|
$class3->expects($this->any())->method('getAssociationMapping')->will($this->returnValue(array( |
901
|
|
|
'isOwningSide' => false, |
902
|
|
|
'mappedBy' => 'c', |
903
|
|
|
'inversedBy' => null |
904
|
|
|
))); |
905
|
|
|
|
906
|
|
|
|
907
|
|
|
$class3->expects($this->any())->method('isAssociationInverseSide')->will($this->returnValue(true)); |
908
|
|
|
$class3->expects($this->any())->method('isCollectionValuedAssociation')->will($this->returnValue(true)); |
909
|
|
|
$class3->expects($this->any())->method('getFieldNames')->will($this->returnValue(array())); |
910
|
|
|
|
911
|
|
|
return array( |
912
|
|
|
array($class1, $class2, $class3, '[A]-c 1>[C],[B]<>b *-c 1>[C]'), |
913
|
|
|
array($class1, $class3, $class2, '[A]-c 1>[C],[C]<c 1-b *<>[B]'), |
914
|
|
|
array($class2, $class1, $class3, '[B]<>b *-c 1>[C],[A]-c 1>[C]'), |
915
|
|
|
array($class2, $class3, $class1, '[B]<>b *-c 1>[C],[A]-c 1>[C]'), |
916
|
|
|
array($class3, $class1, $class2, '[C]<c 1-b *<>[B],[A]-c 1>[C]'), |
917
|
|
|
array($class3, $class2, $class1, '[C]<c 1-b *<>[B],[A]-c 1>[C]') |
918
|
|
|
); |
919
|
|
|
} |
920
|
|
|
|
921
|
|
|
/** |
922
|
|
|
* To mock getAssociationTargetClass method with args |
923
|
|
|
* |
924
|
|
|
* @param string $a |
925
|
|
|
* @return string |
926
|
|
|
*/ |
927
|
|
|
public function getAssociationTargetClassMock($a) |
928
|
|
|
{ |
929
|
|
|
return strtoupper($a); |
930
|
|
|
} |
931
|
|
|
|
932
|
|
|
/** |
933
|
|
|
* @return array |
934
|
|
|
*/ |
935
|
|
|
public function injectTwoClassesWithTwoDifferentRelationsOneToManyBidirectionnal() |
936
|
|
|
{ |
937
|
|
|
$classAB = $this->getMockBuilder('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata') |
938
|
|
|
->setMethods(array( |
939
|
|
|
'getName', |
940
|
|
|
'getIdentifier', |
941
|
|
|
'getReflectionClass', |
942
|
|
|
'isIdentifier', |
943
|
|
|
'hasField', |
944
|
|
|
'hasAssociation', |
945
|
|
|
'isSingleValuedAssociation', |
946
|
|
|
'isCollectionValuedAssociation', |
947
|
|
|
'getFieldNames', |
948
|
|
|
'getIdentifierFieldNames', |
949
|
|
|
'getAssociationNames', |
950
|
|
|
'getTypeOfField', |
951
|
|
|
'getAssociationTargetClass', |
952
|
|
|
'isAssociationInverseSide', |
953
|
|
|
'getAssociationMappedByTargetField', |
954
|
|
|
'getIdentifierValues', |
955
|
|
|
'getAssociationMapping', |
956
|
|
|
))->getMock(); |
957
|
|
|
$classAB->expects($this->any())->method('getName')->will($this->returnValue('AB')); |
958
|
|
|
$classAB->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array('c','d'))); |
959
|
|
|
$classAB |
960
|
|
|
->expects($this->any()) |
961
|
|
|
->method('getAssociationTargetClass') |
962
|
|
|
->with($this->logicalOr($this->equalTo('c'), $this->equalTo('d'))) |
963
|
|
|
->will($this->returnCallback(array($this, 'getAssociationClassMock'))); |
964
|
|
|
|
965
|
|
|
$classAB |
966
|
|
|
->expects($this->any()) |
967
|
|
|
->method('getAssociationMapping') |
968
|
|
|
->with($this->logicalOr( |
969
|
|
|
$this->equalTo('c'), |
970
|
|
|
$this->equalTo('d') |
971
|
|
|
)) |
972
|
|
|
->will($this->returnCallback(array($this, 'getAssociationMappingMock'))); |
973
|
|
|
|
974
|
|
|
|
975
|
|
|
$classAB->expects($this->any())->method('isAssociationInverseSide')->will($this->returnValue(true)); |
976
|
|
|
$classAB->expects($this->any())->method('isCollectionValuedAssociation')->will($this->returnValue(true)); |
977
|
|
|
$classAB->expects($this->any())->method('getFieldNames')->will($this->returnValue(array())); |
978
|
|
|
|
979
|
|
|
$classCD = $this->getMockBuilder('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata') |
980
|
|
|
->setMethods(array( |
981
|
|
|
'getName', |
982
|
|
|
'getIdentifier', |
983
|
|
|
'getReflectionClass', |
984
|
|
|
'isIdentifier', |
985
|
|
|
'hasField', |
986
|
|
|
'hasAssociation', |
987
|
|
|
'isSingleValuedAssociation', |
988
|
|
|
'isCollectionValuedAssociation', |
989
|
|
|
'getFieldNames', |
990
|
|
|
'getIdentifierFieldNames', |
991
|
|
|
'getAssociationNames', |
992
|
|
|
'getTypeOfField', |
993
|
|
|
'getAssociationTargetClass', |
994
|
|
|
'isAssociationInverseSide', |
995
|
|
|
'getAssociationMappedByTargetField', |
996
|
|
|
'getIdentifierValues', |
997
|
|
|
'getAssociationMapping', |
998
|
|
|
))->getMock(); |
999
|
|
|
$classCD->expects($this->any())->method('getName')->will($this->returnValue('CD')); |
1000
|
|
|
$classCD->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array('a','b'))); |
1001
|
|
|
$classCD |
1002
|
|
|
->expects($this->any()) |
1003
|
|
|
->method('getAssociationTargetClass') |
1004
|
|
|
->with($this->logicalOr($this->equalTo('a'), $this->equalTo('b'))) |
1005
|
|
|
->will($this->returnCallback(array($this, 'getAssociationClassMock'))); |
1006
|
|
|
$classCD |
1007
|
|
|
->expects($this->any()) |
1008
|
|
|
->method('getAssociationMapping') |
1009
|
|
|
->with($this->logicalOr( |
1010
|
|
|
$this->equalTo('a'), |
1011
|
|
|
$this->equalTo('b') |
1012
|
|
|
)) |
1013
|
|
|
->will($this->returnCallback(array($this, 'getAssociationMappingMock'))); |
1014
|
|
|
$classCD->expects($this->any())->method('isAssociationInverseSide')->will($this->returnValue(false)); |
1015
|
|
|
$classCD->expects($this->any())->method('isCollectionValuedAssociation')->will($this->returnValue(false)); |
1016
|
|
|
$classCD->expects($this->any())->method('getFieldNames')->will($this->returnValue(array())); |
1017
|
|
|
|
1018
|
|
|
return array( |
1019
|
|
|
array($classAB, $classCD, "[AB]<a 1-c *<>[CD],[AB]<b 1-d *<>[CD]"), |
1020
|
|
|
array($classCD, $classAB, "[CD]<>c *-a 1>[AB],[CD]<>d *-b 1>[AB]"), |
1021
|
|
|
); |
1022
|
|
|
} |
1023
|
|
|
|
1024
|
|
|
/** |
1025
|
|
|
* @covers \DoctrineORMModule\Yuml\MetadataGrapher |
1026
|
|
|
* @dataProvider injectTwoClassesWithTwoDifferentRelationsOneToManyBidirectionnal |
1027
|
|
|
*/ |
1028
|
|
|
public function testMultipleRelationsManyToOneBeetweenTwoSameClasses($class1, $class2, $expected) |
1029
|
|
|
{ |
1030
|
|
|
$this->assertSame( |
1031
|
|
|
$expected, |
1032
|
|
|
$this->grapher->generateFromMetadata(array($class1, $class2)) |
1033
|
|
|
); |
1034
|
|
|
} |
1035
|
|
|
|
1036
|
|
|
public function getAssociationClassMock($a) |
1037
|
|
|
{ |
1038
|
|
|
switch ($a) { |
1039
|
|
|
case 'a': |
1040
|
|
|
case 'b': |
1041
|
|
|
return 'AB'; |
1042
|
|
|
break; |
|
|
|
|
1043
|
|
|
case 'c': |
1044
|
|
|
case 'd': |
1045
|
|
|
return 'CD'; |
1046
|
|
|
break; |
|
|
|
|
1047
|
|
|
} |
1048
|
|
|
return false; |
1049
|
|
|
} |
1050
|
|
|
|
1051
|
|
|
public function getAssociationMappingMock($a) |
1052
|
|
|
{ |
1053
|
|
|
switch ($a) { |
1054
|
|
|
case 'a': |
1055
|
|
|
$return = array( |
1056
|
|
|
'isOwningSide' => true, |
1057
|
|
|
'mappedBy' => null, |
1058
|
|
|
'inversedBy' => 'c' |
1059
|
|
|
); |
1060
|
|
|
break; |
1061
|
|
|
case 'b': |
1062
|
|
|
$return = array( |
1063
|
|
|
'isOwningSide' => true, |
1064
|
|
|
'mappedBy' => null, |
1065
|
|
|
'inversedBy' => 'd' |
1066
|
|
|
); |
1067
|
|
|
break; |
1068
|
|
|
case 'c': |
1069
|
|
|
$return = array( |
1070
|
|
|
'isOwningSide' => false, |
1071
|
|
|
'mappedBy' => 'a', |
1072
|
|
|
'inversedBy' => null |
1073
|
|
|
); |
1074
|
|
|
break; |
1075
|
|
|
case 'd': |
1076
|
|
|
$return = array( |
1077
|
|
|
'isOwningSide' => false, |
1078
|
|
|
'mappedBy' => 'b', |
1079
|
|
|
'inversedBy' => null |
1080
|
|
|
); |
1081
|
|
|
break; |
1082
|
|
|
default: |
1083
|
|
|
$return = false; |
1084
|
|
|
} |
1085
|
|
|
return $return; |
1086
|
|
|
} |
1087
|
|
|
} |
1088
|
|
|
|
The break statement is not necessary if it is preceded for example by a return statement:
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.