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->getMockBuilder('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata') |
55
|
|
|
->getMock(); |
56
|
|
|
$class->expects($this->any())->method('getName')->will($this->returnValue('Simple\\Entity')); |
57
|
|
|
$class->expects($this->any())->method('getFieldNames')->will($this->returnValue([])); |
58
|
|
|
$class->expects($this->any())->method('getAssociationNames')->will($this->returnValue([])); |
59
|
|
|
|
60
|
|
|
$this->assertSame('[Simple.Entity]', $this->grapher->generateFromMetadata([$class])); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @covers \DoctrineORMModule\Yuml\MetadataGrapher |
65
|
|
|
*/ |
66
|
|
|
public function testDrawSimpleEntityWithFields() |
67
|
|
|
{ |
68
|
|
|
$class = $this->getMockBuilder('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata') |
69
|
|
|
->getMock(); |
70
|
|
|
$class->expects($this->any())->method('getName')->will($this->returnValue('Simple\\Entity')); |
71
|
|
|
$class->expects($this->any())->method('getFieldNames')->will($this->returnValue(['a', 'b', 'c'])); |
72
|
|
|
$class->expects($this->any())->method('getAssociationNames')->will($this->returnValue([])); |
73
|
|
|
$class->expects($this->any())->method('isIdentifier')->will( |
74
|
|
|
$this->returnCallback( |
75
|
|
|
function ($field) { |
76
|
|
|
return $field === 'a'; |
77
|
|
|
} |
78
|
|
|
) |
79
|
|
|
); |
80
|
|
|
|
81
|
|
|
$this->assertSame('[Simple.Entity|+a;b;c]', $this->grapher->generateFromMetadata([$class])); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @covers \DoctrineORMModule\Yuml\MetadataGrapher |
86
|
|
|
*/ |
87
|
|
|
public function testDrawOneToOneUniDirectionalAssociation() |
88
|
|
|
{ |
89
|
|
|
$class1 = $this->getMockBuilder('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata') |
90
|
|
|
->getMock(); |
91
|
|
|
$class1->expects($this->any())->method('getName')->will($this->returnValue('A')); |
92
|
|
|
$class1->expects($this->any())->method('getAssociationNames')->will($this->returnValue(['b'])); |
93
|
|
|
$class1->expects($this->any())->method('getAssociationTargetClass')->will($this->returnValue('B')); |
94
|
|
|
$class1->expects($this->any())->method('isAssociationInverseSide')->will($this->returnValue(false)); |
95
|
|
|
$class1->expects($this->any())->method('isCollectionValuedAssociation')->will($this->returnValue(false)); |
96
|
|
|
$class1->expects($this->any())->method('getFieldNames')->will($this->returnValue([])); |
97
|
|
|
|
98
|
|
|
$class2 = $this->getMockBuilder('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata') |
99
|
|
|
->getMock(); |
100
|
|
|
$class2->expects($this->any())->method('getName')->will($this->returnValue('B')); |
101
|
|
|
$class2->expects($this->any())->method('getAssociationNames')->will($this->returnValue([])); |
102
|
|
|
$class2->expects($this->any())->method('getFieldNames')->will($this->returnValue([])); |
103
|
|
|
|
104
|
|
|
$this->assertSame('[A]-b 1>[B]', $this->grapher->generateFromMetadata([$class1, $class2])); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @covers \DoctrineORMModule\Yuml\MetadataGrapher |
109
|
|
|
*/ |
110
|
|
|
public function testDrawOneToOneBiDirectionalAssociation() |
111
|
|
|
{ |
112
|
|
|
$class1 = $this->getMockBuilder('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata') |
113
|
|
|
->getMock(); |
114
|
|
|
$class1->expects($this->any())->method('getName')->will($this->returnValue('A')); |
115
|
|
|
$class1->expects($this->any())->method('getAssociationNames')->will($this->returnValue(['b'])); |
116
|
|
|
$class1->expects($this->any())->method('getAssociationTargetClass')->will($this->returnValue('B')); |
117
|
|
|
$class1->expects($this->any())->method('isAssociationInverseSide')->will($this->returnValue(false)); |
118
|
|
|
$class1->expects($this->any())->method('isCollectionValuedAssociation')->will($this->returnValue(false)); |
119
|
|
|
$class1->expects($this->any())->method('getFieldNames')->will($this->returnValue([])); |
120
|
|
|
|
121
|
|
|
$class2 = $this->getMockBuilder('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata') |
122
|
|
|
->getMock(); |
123
|
|
|
$class2->expects($this->any())->method('getName')->will($this->returnValue('B')); |
124
|
|
|
$class2->expects($this->any())->method('getAssociationNames')->will($this->returnValue(['a'])); |
125
|
|
|
$class2->expects($this->any())->method('getAssociationTargetClass')->will($this->returnValue('A')); |
126
|
|
|
$class2->expects($this->any())->method('isAssociationInverseSide')->will($this->returnValue(true)); |
127
|
|
|
$class2->expects($this->any())->method('isCollectionValuedAssociation')->will($this->returnValue(false)); |
128
|
|
|
$class2->expects($this->any())->method('getAssociationMappedByTargetField')->will($this->returnValue('b')); |
129
|
|
|
$class2->expects($this->any())->method('getFieldNames')->will($this->returnValue([])); |
130
|
|
|
|
131
|
|
|
$this->assertSame('[A]<>a 1-b 1>[B]', $this->grapher->generateFromMetadata([$class1, $class2])); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @covers \DoctrineORMModule\Yuml\MetadataGrapher |
136
|
|
|
*/ |
137
|
|
|
public function testDrawOneToOneBiDirectionalInverseAssociation() |
138
|
|
|
{ |
139
|
|
|
$class1 = $this->getMockBuilder('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata') |
140
|
|
|
->getMock(); |
141
|
|
|
$class1->expects($this->any())->method('getName')->will($this->returnValue('A')); |
142
|
|
|
$class1->expects($this->any())->method('getAssociationNames')->will($this->returnValue(['b'])); |
143
|
|
|
$class1->expects($this->any())->method('getAssociationTargetClass')->will($this->returnValue('B')); |
144
|
|
|
$class1->expects($this->any())->method('isAssociationInverseSide')->will($this->returnValue(true)); |
145
|
|
|
$class1->expects($this->any())->method('isCollectionValuedAssociation')->will($this->returnValue(false)); |
146
|
|
|
$class1->expects($this->any())->method('getAssociationMappedByTargetField')->will($this->returnValue('a')); |
147
|
|
|
$class1->expects($this->any())->method('getFieldNames')->will($this->returnValue([])); |
148
|
|
|
|
149
|
|
|
$class2 = $this->getMockBuilder('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata') |
150
|
|
|
->getMock(); |
151
|
|
|
$class2->expects($this->any())->method('getName')->will($this->returnValue('B')); |
152
|
|
|
$class2->expects($this->any())->method('getAssociationNames')->will($this->returnValue(['a'])); |
153
|
|
|
$class2->expects($this->any())->method('getAssociationTargetClass')->will($this->returnValue('A')); |
154
|
|
|
$class2->expects($this->any())->method('isAssociationInverseSide')->will($this->returnValue(false)); |
155
|
|
|
$class2->expects($this->any())->method('isCollectionValuedAssociation')->will($this->returnValue(false)); |
156
|
|
|
$class2->expects($this->any())->method('getFieldNames')->will($this->returnValue([])); |
157
|
|
|
|
158
|
|
|
$this->assertSame('[A]<a 1-b 1<>[B]', $this->grapher->generateFromMetadata([$class1, $class2])); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* @covers \DoctrineORMModule\Yuml\MetadataGrapher |
163
|
|
|
*/ |
164
|
|
|
public function testDrawOneToManyBiDirectionalAssociation() |
165
|
|
|
{ |
166
|
|
|
$class1 = $this->getMockBuilder('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata') |
167
|
|
|
->getMock(); |
168
|
|
|
$class1->expects($this->any())->method('getName')->will($this->returnValue('A')); |
169
|
|
|
$class1->expects($this->any())->method('getAssociationNames')->will($this->returnValue(['b'])); |
170
|
|
|
$class1->expects($this->any())->method('getAssociationTargetClass')->will($this->returnValue('B')); |
171
|
|
|
$class1->expects($this->any())->method('isAssociationInverseSide')->will($this->returnValue(false)); |
172
|
|
|
$class1->expects($this->any())->method('isCollectionValuedAssociation')->will($this->returnValue(true)); |
173
|
|
|
$class1->expects($this->any())->method('getFieldNames')->will($this->returnValue([])); |
174
|
|
|
|
175
|
|
|
$class2 = $this->getMockBuilder('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata') |
176
|
|
|
->getMock(); |
177
|
|
|
$class2->expects($this->any())->method('getName')->will($this->returnValue('B')); |
178
|
|
|
$class2->expects($this->any())->method('getAssociationNames')->will($this->returnValue(['a'])); |
179
|
|
|
$class2->expects($this->any())->method('getAssociationTargetClass')->will($this->returnValue('A')); |
180
|
|
|
$class2->expects($this->any())->method('isAssociationInverseSide')->will($this->returnValue(true)); |
181
|
|
|
$class2->expects($this->any())->method('isCollectionValuedAssociation')->will($this->returnValue(false)); |
182
|
|
|
$class2->expects($this->any())->method('getAssociationMappedByTargetField')->will($this->returnValue('b')); |
183
|
|
|
$class2->expects($this->any())->method('getFieldNames')->will($this->returnValue([])); |
184
|
|
|
|
185
|
|
|
$this->assertSame('[A]<>a 1-b *>[B]', $this->grapher->generateFromMetadata([$class1, $class2])); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* @covers \DoctrineORMModule\Yuml\MetadataGrapher |
190
|
|
|
*/ |
191
|
|
|
public function testDrawOneToManyBiDirectionalInverseAssociation() |
192
|
|
|
{ |
193
|
|
|
$class1 = $this->getMockBuilder('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata') |
194
|
|
|
->getMock(); |
195
|
|
|
$class1->expects($this->any())->method('getName')->will($this->returnValue('A')); |
196
|
|
|
$class1->expects($this->any())->method('getAssociationNames')->will($this->returnValue(['b'])); |
197
|
|
|
$class1->expects($this->any())->method('getAssociationTargetClass')->will($this->returnValue('B')); |
198
|
|
|
$class1->expects($this->any())->method('isAssociationInverseSide')->will($this->returnValue(false)); |
199
|
|
|
$class1->expects($this->any())->method('isCollectionValuedAssociation')->will($this->returnValue(false)); |
200
|
|
|
$class1->expects($this->any())->method('getFieldNames')->will($this->returnValue([])); |
201
|
|
|
|
202
|
|
|
$class2 = $this->getMockBuilder('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata') |
203
|
|
|
->getMock(); |
204
|
|
|
$class2->expects($this->any())->method('getName')->will($this->returnValue('B')); |
205
|
|
|
$class2->expects($this->any())->method('getAssociationNames')->will($this->returnValue(['a'])); |
206
|
|
|
$class2->expects($this->any())->method('getAssociationTargetClass')->will($this->returnValue('A')); |
207
|
|
|
$class2->expects($this->any())->method('isAssociationInverseSide')->will($this->returnValue(true)); |
208
|
|
|
$class2->expects($this->any())->method('isCollectionValuedAssociation')->will($this->returnValue(true)); |
209
|
|
|
$class2->expects($this->any())->method('getAssociationMappedByTargetField')->will($this->returnValue('b')); |
210
|
|
|
$class2->expects($this->any())->method('getFieldNames')->will($this->returnValue([])); |
211
|
|
|
|
212
|
|
|
$this->assertSame('[A]<>a *-b 1>[B]', $this->grapher->generateFromMetadata([$class1, $class2])); |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* @covers \DoctrineORMModule\Yuml\MetadataGrapher |
217
|
|
|
*/ |
218
|
|
|
public function testDrawManyToManyUniDirectionalAssociation() |
219
|
|
|
{ |
220
|
|
|
$class1 = $this->getMockBuilder('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata') |
221
|
|
|
->getMock(); |
222
|
|
|
$class1->expects($this->any())->method('getName')->will($this->returnValue('A')); |
223
|
|
|
$class1->expects($this->any())->method('getAssociationNames')->will($this->returnValue(['b'])); |
224
|
|
|
$class1->expects($this->any())->method('getAssociationTargetClass')->will($this->returnValue('B')); |
225
|
|
|
$class1->expects($this->any())->method('isAssociationInverseSide')->will($this->returnValue(false)); |
226
|
|
|
$class1->expects($this->any())->method('isCollectionValuedAssociation')->will($this->returnValue(true)); |
227
|
|
|
$class1->expects($this->any())->method('getFieldNames')->will($this->returnValue([])); |
228
|
|
|
|
229
|
|
|
$class2 = $this->getMockBuilder('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata') |
230
|
|
|
->getMock(); |
231
|
|
|
$class2->expects($this->any())->method('getName')->will($this->returnValue('B')); |
232
|
|
|
$class2->expects($this->any())->method('getAssociationNames')->will($this->returnValue([])); |
233
|
|
|
$class2->expects($this->any())->method('getFieldNames')->will($this->returnValue([])); |
234
|
|
|
|
235
|
|
|
$this->assertSame('[A]-b *>[B]', $this->grapher->generateFromMetadata([$class1, $class2])); |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* @covers \DoctrineORMModule\Yuml\MetadataGrapher |
240
|
|
|
*/ |
241
|
|
|
public function testDrawManyToManyUniDirectionalInverseAssociation() |
242
|
|
|
{ |
243
|
|
|
$class1 = $this->getMockBuilder('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata') |
244
|
|
|
->getMock(); |
245
|
|
|
$class1->expects($this->any())->method('getName')->will($this->returnValue('A')); |
246
|
|
|
$class1->expects($this->any())->method('getAssociationNames')->will($this->returnValue([])); |
247
|
|
|
$class1->expects($this->any())->method('getFieldNames')->will($this->returnValue([])); |
248
|
|
|
|
249
|
|
|
$class2 = $this->getMockBuilder('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata') |
250
|
|
|
->getMock(); |
251
|
|
|
$class2->expects($this->any())->method('getName')->will($this->returnValue('B')); |
252
|
|
|
$class2->expects($this->any())->method('getAssociationNames')->will($this->returnValue(['a'])); |
253
|
|
|
$class2->expects($this->any())->method('getAssociationTargetClass')->will($this->returnValue('A')); |
254
|
|
|
$class2->expects($this->any())->method('isAssociationInverseSide')->will($this->returnValue(false)); |
255
|
|
|
$class2->expects($this->any())->method('isCollectionValuedAssociation')->will($this->returnValue(true)); |
256
|
|
|
$class2->expects($this->any())->method('getFieldNames')->will($this->returnValue([])); |
257
|
|
|
|
258
|
|
|
$this->assertSame('[A],[B]-a *>[A]', $this->grapher->generateFromMetadata([$class1, $class2])); |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
/** |
262
|
|
|
* @covers \DoctrineORMModule\Yuml\MetadataGrapher |
263
|
|
|
*/ |
264
|
|
|
public function testDrawManyToManyBiDirectionalAssociation() |
265
|
|
|
{ |
266
|
|
|
$class1 = $this->getMockBuilder('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata') |
267
|
|
|
->getMock(); |
268
|
|
|
$class1->expects($this->any())->method('getName')->will($this->returnValue('A')); |
269
|
|
|
$class1->expects($this->any())->method('getAssociationNames')->will($this->returnValue(['b'])); |
270
|
|
|
$class1->expects($this->any())->method('getAssociationTargetClass')->will($this->returnValue('B')); |
271
|
|
|
$class1->expects($this->any())->method('isAssociationInverseSide')->will($this->returnValue(false)); |
272
|
|
|
$class1->expects($this->any())->method('isCollectionValuedAssociation')->will($this->returnValue(true)); |
273
|
|
|
$class1->expects($this->any())->method('getFieldNames')->will($this->returnValue([])); |
274
|
|
|
|
275
|
|
|
$class2 = $this->getMockBuilder('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata') |
276
|
|
|
->getMock(); |
277
|
|
|
$class2->expects($this->any())->method('getName')->will($this->returnValue('B')); |
278
|
|
|
$class2->expects($this->any())->method('getAssociationNames')->will($this->returnValue(['a'])); |
279
|
|
|
$class2->expects($this->any())->method('getAssociationTargetClass')->will($this->returnValue('A')); |
280
|
|
|
$class2->expects($this->any())->method('isAssociationInverseSide')->will($this->returnValue(true)); |
281
|
|
|
$class2->expects($this->any())->method('isCollectionValuedAssociation')->will($this->returnValue(true)); |
282
|
|
|
$class2->expects($this->any())->method('getAssociationMappedByTargetField')->will($this->returnValue('b')); |
283
|
|
|
$class2->expects($this->any())->method('getFieldNames')->will($this->returnValue([])); |
284
|
|
|
|
285
|
|
|
$this->assertSame('[A]<>a *-b *>[B]', $this->grapher->generateFromMetadata([$class1, $class2])); |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
/** |
289
|
|
|
* @covers \DoctrineORMModule\Yuml\MetadataGrapher |
290
|
|
|
*/ |
291
|
|
|
public function testDrawManyToManyBiDirectionalInverseAssociation() |
292
|
|
|
{ |
293
|
|
|
$class1 = $this->getMockBuilder('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata') |
294
|
|
|
->getMock(); |
295
|
|
|
$class1->expects($this->any())->method('getName')->will($this->returnValue('A')); |
296
|
|
|
$class1->expects($this->any())->method('getAssociationNames')->will($this->returnValue(['b'])); |
297
|
|
|
$class1->expects($this->any())->method('getAssociationTargetClass')->will($this->returnValue('B')); |
298
|
|
|
$class1->expects($this->any())->method('isAssociationInverseSide')->will($this->returnValue(true)); |
299
|
|
|
$class1->expects($this->any())->method('isCollectionValuedAssociation')->will($this->returnValue(true)); |
300
|
|
|
$class1->expects($this->any())->method('getAssociationMappedByTargetField')->will($this->returnValue('a')); |
301
|
|
|
$class1->expects($this->any())->method('getFieldNames')->will($this->returnValue([])); |
302
|
|
|
|
303
|
|
|
$class2 = $this->getMockBuilder('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata') |
304
|
|
|
->getMock(); |
305
|
|
|
$class2->expects($this->any())->method('getName')->will($this->returnValue('B')); |
306
|
|
|
$class2->expects($this->any())->method('getAssociationNames')->will($this->returnValue(['a'])); |
307
|
|
|
$class2->expects($this->any())->method('getAssociationTargetClass')->will($this->returnValue('A')); |
308
|
|
|
$class2->expects($this->any())->method('isAssociationInverseSide')->will($this->returnValue(false)); |
309
|
|
|
$class2->expects($this->any())->method('isCollectionValuedAssociation')->will($this->returnValue(true)); |
310
|
|
|
$class2->expects($this->any())->method('getFieldNames')->will($this->returnValue([])); |
311
|
|
|
|
312
|
|
|
$this->assertSame('[A]<a *-b *<>[B]', $this->grapher->generateFromMetadata([$class1, $class2])); |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
/** |
316
|
|
|
* @covers \DoctrineORMModule\Yuml\MetadataGrapher |
317
|
|
|
*/ |
318
|
|
|
public function testDrawManyToManyAssociationWithoutKnownInverseSide() |
319
|
|
|
{ |
320
|
|
|
$class1 = $this->getMockBuilder('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata') |
321
|
|
|
->getMock(); |
322
|
|
|
$class1->expects($this->any())->method('getName')->will($this->returnValue('A')); |
323
|
|
|
$class1->expects($this->any())->method('getAssociationNames')->will($this->returnValue(['b'])); |
324
|
|
|
$class1->expects($this->any())->method('getAssociationTargetClass')->will($this->returnValue('B')); |
325
|
|
|
$class1->expects($this->any())->method('isAssociationInverseSide')->will($this->returnValue(false)); |
326
|
|
|
$class1->expects($this->any())->method('isCollectionValuedAssociation')->will($this->returnValue(true)); |
327
|
|
|
$class1->expects($this->any())->method('getFieldNames')->will($this->returnValue([])); |
328
|
|
|
|
329
|
|
|
$this->assertSame('[A]<>-b *>[B]', $this->grapher->generateFromMetadata([$class1])); |
330
|
|
|
} |
331
|
|
|
|
332
|
|
|
/** |
333
|
|
|
* @covers \DoctrineORMModule\Yuml\MetadataGrapher |
334
|
|
|
*/ |
335
|
|
|
public function testDrawInheritance() |
336
|
|
|
{ |
337
|
|
|
$class1 = $this->getMockBuilder('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata') |
338
|
|
|
->getMock(); |
339
|
|
|
$class2 = $this->getMockBuilder('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata') |
340
|
|
|
->getMock(); |
341
|
|
|
$child = get_class($this->getMockBuilder('stdClass')->getMock()); |
342
|
|
|
$class1->expects($this->any())->method('getName')->will($this->returnValue('stdClass')); |
343
|
|
|
$class1->expects($this->any())->method('getAssociationNames')->will($this->returnValue([])); |
344
|
|
|
$class1->expects($this->any())->method('getFieldNames')->will($this->returnValue([])); |
345
|
|
|
$class2->expects($this->any())->method('getName')->will($this->returnValue($child)); |
346
|
|
|
$class2->expects($this->any())->method('getAssociationNames')->will($this->returnValue([])); |
347
|
|
|
$class2->expects($this->any())->method('getFieldNames')->will($this->returnValue([])); |
348
|
|
|
|
349
|
|
|
$this->assertSame( |
350
|
|
|
'[stdClass]^[' . str_replace('\\', '.', $child) . ']', |
351
|
|
|
$this->grapher->generateFromMetadata([$class2, $class1]) |
352
|
|
|
); |
353
|
|
|
} |
354
|
|
|
|
355
|
|
|
/** |
356
|
|
|
* @covers \DoctrineORMModule\Yuml\MetadataGrapher |
357
|
|
|
*/ |
358
|
|
|
public function testDrawInheritedFields() |
359
|
|
|
{ |
360
|
|
|
$class1 = $this->getMockBuilder('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata') |
361
|
|
|
->getMock(); |
362
|
|
|
$class2 = $this->getMockBuilder('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata') |
363
|
|
|
->getMock(); |
364
|
|
|
$child = get_class($this->getMockBuilder('stdClass')->getMock()); |
365
|
|
|
|
366
|
|
|
$class1->expects($this->any())->method('getName')->will($this->returnValue('stdClass')); |
367
|
|
|
$class1->expects($this->any())->method('getAssociationNames')->will($this->returnValue([])); |
368
|
|
|
$class1->expects($this->any())->method('getFieldNames')->will($this->returnValue(['inherited'])); |
369
|
|
|
|
370
|
|
|
$class2->expects($this->any())->method('getName')->will($this->returnValue($child)); |
371
|
|
|
$class2->expects($this->any())->method('getAssociationNames')->will($this->returnValue([])); |
372
|
|
|
$class2->expects($this->any())->method('getFieldNames')->will($this->returnValue(['inherited', 'field2'])); |
373
|
|
|
|
374
|
|
|
$this->assertSame( |
375
|
|
|
'[stdClass|inherited]^[' . str_replace('\\', '.', $child) . '|field2]', |
376
|
|
|
$this->grapher->generateFromMetadata([$class2, $class1]) |
377
|
|
|
); |
378
|
|
|
} |
379
|
|
|
|
380
|
|
|
/** |
381
|
|
|
* @covers \DoctrineORMModule\Yuml\MetadataGrapher |
382
|
|
|
*/ |
383
|
|
|
public function testDrawInheritedAssociations() |
384
|
|
|
{ |
385
|
|
|
$class1 = $this->getMockBuilder('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata') |
386
|
|
|
->getMock(); |
387
|
|
|
$class2 = $this->getMockBuilder('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata') |
388
|
|
|
->getMock(); |
389
|
|
|
$class3 = $this->getMockBuilder('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata') |
390
|
|
|
->getMock(); |
391
|
|
|
$class4 = $this->getMockBuilder('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata') |
392
|
|
|
->getMock(); |
393
|
|
|
$child = get_class($this->getMockBuilder('stdClass')->getMock()); |
394
|
|
|
|
395
|
|
|
$class1->expects($this->any())->method('getName')->will($this->returnValue('stdClass')); |
396
|
|
|
$class1->expects($this->any())->method('getAssociationNames')->will($this->returnValue(['a'])); |
397
|
|
|
$class1->expects($this->any())->method('getAssociationTargetClass')->will($this->returnValue('A')); |
398
|
|
|
$class1->expects($this->any())->method('isAssociationInverseSide')->will($this->returnValue(false)); |
399
|
|
|
$class1->expects($this->any())->method('isCollectionValuedAssociation')->will($this->returnValue(true)); |
400
|
|
|
$class1->expects($this->any())->method('getFieldNames')->will($this->returnValue([])); |
401
|
|
|
|
402
|
|
|
$class2->expects($this->any())->method('getName')->will($this->returnValue($child)); |
403
|
|
|
$class2->expects($this->any())->method('getAssociationNames')->will($this->returnValue(['a', 'b'])); |
404
|
|
|
$class2 |
405
|
|
|
->expects($this->any()) |
406
|
|
|
->method('getAssociationTargetClass') |
407
|
|
|
->will( |
408
|
|
|
$this->returnCallback( |
409
|
|
|
function ($assoc) { |
410
|
|
|
return strtoupper($assoc); |
411
|
|
|
} |
412
|
|
|
) |
413
|
|
|
); |
414
|
|
|
$class2->expects($this->any())->method('isAssociationInverseSide')->will($this->returnValue(false)); |
415
|
|
|
$class2->expects($this->any())->method('isCollectionValuedAssociation')->will($this->returnValue(true)); |
416
|
|
|
$class2->expects($this->any())->method('getFieldNames')->will($this->returnValue([])); |
417
|
|
|
|
418
|
|
|
$class3->expects($this->any())->method('getName')->will($this->returnValue('A')); |
419
|
|
|
$class3->expects($this->any())->method('getAssociationNames')->will($this->returnValue([])); |
420
|
|
|
$class3->expects($this->any())->method('getFieldNames')->will($this->returnValue([])); |
421
|
|
|
|
422
|
|
|
$class4->expects($this->any())->method('getName')->will($this->returnValue('B')); |
423
|
|
|
$class4->expects($this->any())->method('getAssociationNames')->will($this->returnValue([])); |
424
|
|
|
$class4->expects($this->any())->method('getFieldNames')->will($this->returnValue([])); |
425
|
|
|
|
426
|
|
|
$childName = str_replace('\\', '.', $child); |
427
|
|
|
$this->assertSame( |
428
|
|
|
'[stdClass]<>-a *>[A],[stdClass]^[' . $childName . '],[' . $childName . ']<>-b *>[B]', |
429
|
|
|
$this->grapher->generateFromMetadata([$class1, $class2]) |
430
|
|
|
); |
431
|
|
|
} |
432
|
|
|
|
433
|
|
|
/** |
434
|
|
|
* @covers \DoctrineORMModule\Yuml\MetadataGrapher |
435
|
|
|
* @dataProvider injectMultipleRelationsWithBothBiAndMonoDirectional |
436
|
|
|
*/ |
437
|
|
|
public function testDrawMultipleClassRelatedBothBiAndMonoDirectional($class1, $class2, $class3, $expected) |
438
|
|
|
{ |
439
|
|
|
$this->assertSame( |
440
|
|
|
$expected, |
441
|
|
|
$this->grapher->generateFromMetadata([$class1, $class2,$class3]) |
442
|
|
|
); |
443
|
|
|
} |
444
|
|
|
|
445
|
|
|
/** |
446
|
|
|
* dataProvider to inject classes in every order possible into the test |
447
|
|
|
* testDrawMultipleClassRelatedBothBiAndMonoDirectional |
448
|
|
|
* |
449
|
|
|
* @return array |
450
|
|
|
*/ |
451
|
|
|
public function injectMultipleRelationsWithBothBiAndMonoDirectional() |
452
|
|
|
{ |
453
|
|
|
$class1 = $this->getMockBuilder('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata') |
454
|
|
|
->getMock(); |
455
|
|
|
$class1->expects($this->any())->method('getName')->will($this->returnValue('A')); |
456
|
|
|
$class1->expects($this->any())->method('getAssociationNames')->will($this->returnValue(['c'])); |
457
|
|
|
$class1->expects($this->any())->method('getAssociationTargetClass')->will($this->returnValue('C')); |
458
|
|
|
$class1->expects($this->any())->method('isAssociationInverseSide')->will($this->returnValue(false)); |
459
|
|
|
$class1->expects($this->any())->method('isCollectionValuedAssociation')->will($this->returnValue(false)); |
460
|
|
|
$class1->expects($this->any())->method('getFieldNames')->will($this->returnValue([])); |
461
|
|
|
|
462
|
|
|
$class2 = $this->getMockBuilder('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata') |
463
|
|
|
->getMock(); |
464
|
|
|
$class2->expects($this->any())->method('getName')->will($this->returnValue('B')); |
465
|
|
|
$class2->expects($this->any())->method('getAssociationNames')->will($this->returnValue(['c'])); |
466
|
|
|
$class2->expects($this->any())->method('getAssociationTargetClass')->will($this->returnValue('C')); |
467
|
|
|
$class2->expects($this->any())->method('isAssociationInverseSide')->will($this->returnValue(false)); |
468
|
|
|
$class2->expects($this->any())->method('isCollectionValuedAssociation')->will($this->returnValue(false)); |
469
|
|
|
$class2->expects($this->any())->method('getFieldNames')->will($this->returnValue([])); |
470
|
|
|
|
471
|
|
|
$class3 = $this->getMockBuilder('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata') |
472
|
|
|
->getMock(); |
473
|
|
|
$class3->expects($this->any())->method('getName')->will($this->returnValue('C')); |
474
|
|
|
$class3->expects($this->any())->method('getAssociationNames')->will($this->returnValue(['b'])); |
475
|
|
|
$class3 |
476
|
|
|
->expects($this->any()) |
477
|
|
|
->method('getAssociationTargetClass') |
478
|
|
|
->with($this->logicalOr($this->equalTo('b'), $this->equalTo('c'))) |
479
|
|
|
->will($this->returnCallback([$this,'getAssociationTargetClassMock'])); |
480
|
|
|
$class3->expects($this->any())->method('isAssociationInverseSide')->will($this->returnValue(true)); |
481
|
|
|
$class3->expects($this->any())->method('isCollectionValuedAssociation')->will($this->returnValue(true)); |
482
|
|
|
$class3->expects($this->any())->method('getFieldNames')->will($this->returnValue([])); |
483
|
|
|
|
484
|
|
|
return [ |
485
|
|
|
[$class1, $class2, $class3, '[A]-c 1>[C],[B]<>b *-c 1>[C]'], |
486
|
|
|
[clone $class1, clone $class3, clone $class2, '[A]-c 1>[C],[C]<c 1-b *<>[B]'], |
487
|
|
|
[clone $class2, clone $class1, clone $class3, '[B]<>b *-c 1>[C],[A]-c 1>[C]'], |
488
|
|
|
[clone $class2, clone $class3, clone $class1, '[B]<>b *-c 1>[C],[A]-c 1>[C]'], |
489
|
|
|
[clone $class3, clone $class1, clone $class2, '[C]<c 1-b *<>[B],[A]-c 1>[C]'], |
490
|
|
|
[clone $class3, clone $class2, clone $class1, '[C]<c 1-b *<>[B],[A]-c 1>[C]'] |
491
|
|
|
]; |
492
|
|
|
} |
493
|
|
|
|
494
|
|
|
/** |
495
|
|
|
* To mock getAssociationTargetClass method with args |
496
|
|
|
* |
497
|
|
|
* @param string $a |
498
|
|
|
* @return string |
499
|
|
|
*/ |
500
|
|
|
public function getAssociationTargetClassMock($a) |
501
|
|
|
{ |
502
|
|
|
return strtoupper($a); |
503
|
|
|
} |
504
|
|
|
} |
505
|
|
|
|