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