Completed
Pull Request — master (#482)
by Bruno
05:15
created

testDrawOneToOneBiDirectionalAssociation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 9.3142
c 0
b 0
f 0
cc 1
eloc 17
nc 1
nop 0
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->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata');
88
        $class1->expects($this->any())->method('getName')->will($this->returnValue('A'));
89
        $class1->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array('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(array()));
94
95
        $class2 = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata');
96
        $class2->expects($this->any())->method('getName')->will($this->returnValue('B'));
97
        $class2->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array()));
98
        $class2->expects($this->any())->method('getFieldNames')->will($this->returnValue(array()));
99
100
        $this->assertSame('[A]-b 1>[B]', $this->grapher->generateFromMetadata(array($class1, $class2)));
101
    }
102
103
    /**
104
     * @covers \DoctrineORMModule\Yuml\MetadataGrapher
105
     */
106
    public function testDrawOneToOneBiDirectionalAssociation()
107
    {
108
        $class1 = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata');
109
        $class1->expects($this->any())->method('getName')->will($this->returnValue('A'));
110
        $class1->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array('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(array()));
115
116
        $class2 = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata');
117
        $class2->expects($this->any())->method('getName')->will($this->returnValue('B'));
118
        $class2->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array('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(array()));
124
125
        $this->assertSame('[A]<>a 1-b 1>[B]', $this->grapher->generateFromMetadata(array($class1, $class2)));
126
    }
127
128
    /**
129
     * @covers \DoctrineORMModule\Yuml\MetadataGrapher
130
     */
131
    public function testDrawOneToOneBiDirectionalInverseAssociation()
132
    {
133
        $class1 = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata');
134
        $class1->expects($this->any())->method('getName')->will($this->returnValue('A'));
135
        $class1->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array('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(array()));
141
142
        $class2 = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata');
143
        $class2->expects($this->any())->method('getName')->will($this->returnValue('B'));
144
        $class2->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array('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(array()));
149
150
        $this->assertSame('[A]<a 1-b 1<>[B]', $this->grapher->generateFromMetadata(array($class1, $class2)));
151
    }
152
153
    /**
154
     * @covers \DoctrineORMModule\Yuml\MetadataGrapher
155
     */
156
    public function testDrawOneToManyBiDirectionalAssociation()
157
    {
158
        $class1 = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata');
159
        $class1->expects($this->any())->method('getName')->will($this->returnValue('A'));
160
        $class1->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array('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(array()));
165
166
        $class2 = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata');
167
        $class2->expects($this->any())->method('getName')->will($this->returnValue('B'));
168
        $class2->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array('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(array()));
174
175
        $this->assertSame('[A]<>a 1-b *>[B]', $this->grapher->generateFromMetadata(array($class1, $class2)));
176
    }
177
178
    /**
179
     * @covers \DoctrineORMModule\Yuml\MetadataGrapher
180
     */
181
    public function testDrawOneToManyBiDirectionalInverseAssociation()
182
    {
183
        $class1 = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata');
184
        $class1->expects($this->any())->method('getName')->will($this->returnValue('A'));
185
        $class1->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array('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(array()));
190
191
        $class2 = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata');
192
        $class2->expects($this->any())->method('getName')->will($this->returnValue('B'));
193
        $class2->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array('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(array()));
199
200
        $this->assertSame('[A]<>a *-b 1>[B]', $this->grapher->generateFromMetadata(array($class1, $class2)));
201
    }
202
203
    /**
204
     * @covers \DoctrineORMModule\Yuml\MetadataGrapher
205
     */
206
    public function testDrawManyToManyUniDirectionalAssociation()
207
    {
208
        $class1 = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata');
209
        $class1->expects($this->any())->method('getName')->will($this->returnValue('A'));
210
        $class1->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array('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(array()));
215
216
        $class2 = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata');
217
        $class2->expects($this->any())->method('getName')->will($this->returnValue('B'));
218
        $class2->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array()));
219
        $class2->expects($this->any())->method('getFieldNames')->will($this->returnValue(array()));
220
221
        $this->assertSame('[A]-b *>[B]', $this->grapher->generateFromMetadata(array($class1, $class2)));
222
    }
223
224
    /**
225
     * @covers \DoctrineORMModule\Yuml\MetadataGrapher
226
     */
227
    public function testDrawManyToManyUniDirectionalInverseAssociation()
228
    {
229
        $class1 = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata');
230
        $class1->expects($this->any())->method('getName')->will($this->returnValue('A'));
231
        $class1->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array()));
232
        $class1->expects($this->any())->method('getFieldNames')->will($this->returnValue(array()));
233
234
        $class2 = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata');
235
        $class2->expects($this->any())->method('getName')->will($this->returnValue('B'));
236
        $class2->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array('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(array()));
241
242
        $this->assertSame('[A],[B]-a *>[A]', $this->grapher->generateFromMetadata(array($class1, $class2)));
243
    }
244
245
    /**
246
     * @covers \DoctrineORMModule\Yuml\MetadataGrapher
247
     */
248
    public function testDrawManyToManyBiDirectionalAssociation()
249
    {
250
        $class1 = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata');
251
        $class1->expects($this->any())->method('getName')->will($this->returnValue('A'));
252
        $class1->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array('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(array()));
257
258
        $class2 = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata');
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('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(array()));
266
267
        $this->assertSame('[A]<>a *-b *>[B]', $this->grapher->generateFromMetadata(array($class1, $class2)));
268
    }
269
270
    /**
271
     * @covers \DoctrineORMModule\Yuml\MetadataGrapher
272
     */
273
    public function testDrawManyToManyBiDirectionalInverseAssociation()
274
    {
275
        $class1 = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata');
276
        $class1->expects($this->any())->method('getName')->will($this->returnValue('A'));
277
        $class1->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array('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(array()));
283
284
        $class2 = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata');
285
        $class2->expects($this->any())->method('getName')->will($this->returnValue('B'));
286
        $class2->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array('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(array()));
291
292
        $this->assertSame('[A]<a *-b *<>[B]', $this->grapher->generateFromMetadata(array($class1, $class2)));
293
    }
294
295
    /**
296
     * @covers \DoctrineORMModule\Yuml\MetadataGrapher
297
     */
298
    public function testDrawManyToManyAssociationWithoutKnownInverseSide()
299
    {
300
        $class1 = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata');
301
        $class1->expects($this->any())->method('getName')->will($this->returnValue('A'));
302
        $class1->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array('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(array()));
307
308
        $this->assertSame('[A]<>-b *>[B]', $this->grapher->generateFromMetadata(array($class1)));
309
    }
310
311
    /**
312
     * @covers \DoctrineORMModule\Yuml\MetadataGrapher
313
     */
314
    public function testDrawInheritance()
315
    {
316
        $class1 = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata');
317
        $class2 = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata');
318
        $child  = get_class($this->getMock('stdClass'));
319
        $class1->expects($this->any())->method('getName')->will($this->returnValue('stdClass'));
320
        $class1->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array()));
321
        $class1->expects($this->any())->method('getFieldNames')->will($this->returnValue(array()));
322
        $class2->expects($this->any())->method('getName')->will($this->returnValue($child));
323
        $class2->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array()));
324
        $class2->expects($this->any())->method('getFieldNames')->will($this->returnValue(array()));
325
326
        $this->assertSame(
327
            '[stdClass]^[' . str_replace('\\', '.', $child) . ']',
328
            $this->grapher->generateFromMetadata(array($class2, $class1))
329
        );
330
    }
331
332
    /**
333
     * @covers \DoctrineORMModule\Yuml\MetadataGrapher
334
     */
335
    public function testDrawInheritedFields()
336
    {
337
        $class1 = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata');
338
        $class2 = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata');
339
        $child  = get_class($this->getMock('stdClass'));
340
341
        $class1->expects($this->any())->method('getName')->will($this->returnValue('stdClass'));
342
        $class1->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array()));
343
        $class1->expects($this->any())->method('getFieldNames')->will($this->returnValue(array('inherited')));
344
345
        $class2->expects($this->any())->method('getName')->will($this->returnValue($child));
346
        $class2->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array()));
347
        $class2->expects($this->any())->method('getFieldNames')->will($this->returnValue(array('inherited', 'field2')));
348
349
        $this->assertSame(
350
            '[stdClass|inherited]^[' . str_replace('\\', '.', $child) . '|field2]',
351
            $this->grapher->generateFromMetadata(array($class2, $class1))
352
        );
353
    }
354
355
    /**
356
     * @covers \DoctrineORMModule\Yuml\MetadataGrapher
357
     */
358
    public function testDrawInheritedAssociations()
359
    {
360
        $class1 = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata');
361
        $class2 = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata');
362
        $class3 = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata');
363
        $class4 = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata');
364
        $child  = get_class($this->getMock('stdClass'));
365
366
        $class1->expects($this->any())->method('getName')->will($this->returnValue('stdClass'));
367
        $class1->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array('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(array()));
372
373
        $class2->expects($this->any())->method('getName')->will($this->returnValue($child));
374
        $class2->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array('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(array()));
388
389
        $class3->expects($this->any())->method('getName')->will($this->returnValue('A'));
390
        $class3->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array()));
391
        $class3->expects($this->any())->method('getFieldNames')->will($this->returnValue(array()));
392
393
        $class4->expects($this->any())->method('getName')->will($this->returnValue('B'));
394
        $class4->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array()));
395
        $class4->expects($this->any())->method('getFieldNames')->will($this->returnValue(array()));
396
397
        $childName = str_replace('\\', '.', $child);
398
        $this->assertSame(
399
            '[stdClass]<>-a *>[A],[stdClass]^[' . $childName . '],[' . $childName . ']<>-b *>[B]',
400
            $this->grapher->generateFromMetadata(array($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(array($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->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata');
425
        $class1->expects($this->any())->method('getName')->will($this->returnValue('A'));
426
        $class1->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array('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(array()));
431
432
        $class2 = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata');
433
        $class2->expects($this->any())->method('getName')->will($this->returnValue('B'));
434
        $class2->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array('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(array()));
439
440
        $class3 = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata');
441
        $class3->expects($this->any())->method('getName')->will($this->returnValue('C'));
442
        $class3->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array('b')));
443
        $class3
444
            ->expects($this->any())
445
            ->method('getAssociationTargetClass')
446
            ->with($this->logicalOr($this->equalTo('b'), $this->equalTo('c')))
447
            ->will($this->returnCallback(array($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(array()));
451
452
        return array(
453
            array($class1, $class2, $class3, '[A]-c 1>[C],[B]<>b *-c 1>[C]'),
454
            array($class1, $class3, $class2, '[A]-c 1>[C],[C]<c 1-b *<>[B]'),
455
            array($class2, $class1, $class3, '[B]<>b *-c 1>[C],[A]-c 1>[C]'),
456
            array($class2, $class3, $class1, '[B]<>b *-c 1>[C],[A]-c 1>[C]'),
457
            array($class3, $class1, $class2, '[C]<c 1-b *<>[B],[A]-c 1>[C]'),
458
            array($class3, $class2, $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
    /**
474
     * @return array
475
     */
476
    public function injectTwoClassesWithTwoDifferentRelationsOneToManyBidirectionnal()
477
    {
478
        $classAB = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata');
479
        $classAB->expects($this->any())->method('getName')->will($this->returnValue('AB'));
480
        $classAB->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array('c','d')));
481
        $classAB
482
            ->expects($this->any())
483
            ->method('getAssociationTargetClass')
484
            ->with($this->logicalOr($this->equalTo('c'), $this->equalTo('d')))
485
            ->will($this->returnCallback(array($this,'getAssociationClassMock')));
486
487
        $classAB->expects($this->any())->method('isAssociationInverseSide')->will($this->returnValue(true));
488
        $classAB->expects($this->any())->method('isCollectionValuedAssociation')->will($this->returnValue(true));
489
        $classAB->expects($this->any())->method('getFieldNames')->will($this->returnValue(array()));
490
491
        $classCD = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata');
492
        $classCD->expects($this->any())->method('getName')->will($this->returnValue('CD'));
493
        $classCD->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array('a','b')));
494
        $classCD
495
            ->expects($this->any())
496
            ->method('getAssociationTargetClass')
497
            ->with($this->logicalOr($this->equalTo('a'), $this->equalTo('b')))
498
            ->will($this->returnCallback(array($this,'getAssociationClassMock')));
499
500
        $classCD->expects($this->any())->method('isAssociationInverseSide')->will($this->returnValue(false));
501
        $classCD->expects($this->any())->method('isCollectionValuedAssociation')->will($this->returnValue(false));
502
        $classCD->expects($this->any())->method('getFieldNames')->will($this->returnValue(array()));
503
504
        return array(
505
            array($classAB, $classCD, "[AB]<a 1-c *<>[CD],[AB]<b 1-d *<>[CD]"),
506
            array($classCD, $classAB, "[CD]<>c *-a 1>[AB],[CD]<>d *-b 1>[AB]"),
507
        );
508
    }
509
510
    /**
511
     * @dataProvider injectTwoClassesWithTwoDifferentRelationsOneToManyBidirectionnal
512
     */
513
    public function testMultipleRelationsManyToOneBeetweenTwoSameClasses($class1,$class2,$expected)
0 ignored issues
show
Coding Style introduced by
Expected 1 space between comma and argument "$class2"; 0 found
Loading history...
Coding Style introduced by
Expected 1 space between comma and argument "$expected"; 0 found
Loading history...
514
    {
515
        $this->assertSame(
516
            $expected,
517
            $this->grapher->generateFromMetadata(array($class1, $class2))
518
        );
519
    }
520
521
    public function getAssociationClassMock($a){
522
        switch ($a) {
523
            case 'a':
524
            case 'b':
525
                return 'AB';
526
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

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.

Loading history...
527
            case 'c':
528
            case 'd':
529
                return 'CD';
530
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

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.

Loading history...
531
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
532
        }
533
    }
534
}
535