Code Duplication    Length = 52-52 lines in 5 locations

tests/MetadataManagerTest.php 5 locations

@@ 181-232 (lines=52) @@
178
        $this->v3MetadataAgainstXSD($d);
179
    }
180
181
    public function testAddManyToManyNavProperty()
182
    {
183
        $msg = null;
184
        $metadataManager = new MetadataManager("Data", "Container");
185
        $result = null;
186
187
        list($CategoryType, $result) = $metadataManager->addEntityType("Category");
188
        list($CustomerType, $result) = $metadataManager->addEntityType("Customer");
189
        $this->assertTrue($CategoryType->isOK($msg), $msg);
190
        $this->assertTrue($CustomerType->isOK($msg), $msg);
191
192
        list($principal, $dependent) = $metadataManager->addNavigationPropertyToEntityType(
193
            $CategoryType,
194
            "*",
195
            "Customers",
196
            $CustomerType,
197
            "*",
198
            "Categories"
199
        );
200
        $this->assertEquals($principal->getFromRole(), $dependent->getToRole());
201
        $this->assertEquals($dependent->getFromRole(), $principal->getToRole());
202
        $this->assertEquals("Customers", $principal->getName());
203
        $this->assertEquals("Categories", $dependent->getName());
204
205
        $navProps = [$principal, $dependent];
206
        $assoc = $metadataManager->getEdmx()->getDataServiceType()->getSchema()[0]->getAssociation();
207
        $this->assertEquals(1, count($assoc));
208
        $assoc = $assoc[0];
209
        $this->assertTrue($assoc instanceof TAssociationType);
210
        $this->assertTrue($assoc->isOK($msg), $msg);
211
212
        $this->assertEquals('Data.'.$assoc->getName(), $principal->getRelationship());
213
        $ends = $assoc->getEnd();
214
215
        $this->assertEquals(2, count($ends));
216
        foreach ($navProps as $prop) {
217
            $fromMatch = $ends[0]->getRole() == $prop->getToRole()
218
                         || $ends[1]->getRole() == $prop->getToRole();
219
            $this->assertTrue($fromMatch, "toRole must match at least one end role");
220
            if ($ends[0]->getRole() == $prop->getToRole()) {
221
                $this->assertEquals($ends[1]->getRole(), $prop->getFromRole());
222
                $this->assertNotEquals($ends[0]->getRole(), $prop->getFromRole());
223
            } else {
224
                $this->assertEquals($ends[0]->getRole(), $prop->getFromRole());
225
                $this->assertNotEquals($ends[1]->getRole(), $prop->getFromRole());
226
            }
227
        }
228
        $principalEnd = ($ends[0]->getRole() == $principal->getToRole()) ? $ends[0] : $ends[1];
229
        $this->assertEquals('*', $principalEnd->getMultiplicity());
230
        $dependentEnd = ($ends[0]->getRole() == $dependent->getToRole()) ? $ends[0] : $ends[1];
231
        $this->assertEquals('*', $dependentEnd->getMultiplicity());
232
    }
233
234
    public function testAddOneToManyNavProperty()
235
    {
@@ 234-285 (lines=52) @@
231
        $this->assertEquals('*', $dependentEnd->getMultiplicity());
232
    }
233
234
    public function testAddOneToManyNavProperty()
235
    {
236
        $msg = null;
237
        $metadataManager = new MetadataManager("Data", "Container");
238
        $result = null;
239
240
        list($CategoryType, $result) = $metadataManager->addEntityType("Category");
241
        list($CustomerType, $result) = $metadataManager->addEntityType("Customer");
242
        $this->assertTrue($CategoryType->isOK($msg), $msg);
243
        $this->assertTrue($CustomerType->isOK($msg), $msg);
244
245
        list($principal, $dependent) = $metadataManager->addNavigationPropertyToEntityType(
246
            $CategoryType,
247
            "*",
248
            "Customers",
249
            $CustomerType,
250
            "1",
251
            "Categories"
252
        );
253
        $this->assertEquals($principal->getFromRole(), $dependent->getToRole());
254
        $this->assertEquals($dependent->getFromRole(), $principal->getToRole());
255
        $this->assertEquals("Customers", $principal->getName());
256
        $this->assertEquals("Categories", $dependent->getName());
257
258
        $navProps = [$principal, $dependent];
259
        $assoc = $metadataManager->getEdmx()->getDataServiceType()->getSchema()[0]->getAssociation();
260
        $this->assertEquals(1, count($assoc));
261
        $assoc = $assoc[0];
262
        $this->assertTrue($assoc instanceof TAssociationType);
263
        $this->assertTrue($assoc->isOK($msg), $msg);
264
265
        $this->assertEquals('Data.'.$assoc->getName(), $principal->getRelationship());
266
        $ends = $assoc->getEnd();
267
268
        $this->assertEquals(2, count($ends));
269
        foreach ($navProps as $prop) {
270
            $fromMatch = $ends[0]->getRole() == $prop->getToRole()
271
                         || $ends[1]->getRole() == $prop->getToRole();
272
            $this->assertTrue($fromMatch, "toRole must match at least one end role");
273
            if ($ends[0]->getRole() == $prop->getToRole()) {
274
                $this->assertEquals($ends[1]->getRole(), $prop->getFromRole());
275
                $this->assertNotEquals($ends[0]->getRole(), $prop->getFromRole());
276
            } else {
277
                $this->assertEquals($ends[0]->getRole(), $prop->getFromRole());
278
                $this->assertNotEquals($ends[1]->getRole(), $prop->getFromRole());
279
            }
280
        }
281
        $principalEnd = ($ends[0]->getRole() == $principal->getToRole()) ? $ends[0] : $ends[1];
282
        $this->assertEquals('*', $principalEnd->getMultiplicity());
283
        $dependentEnd = ($ends[0]->getRole() == $dependent->getToRole()) ? $ends[0] : $ends[1];
284
        $this->assertEquals('1', $dependentEnd->getMultiplicity());
285
    }
286
287
    public function testAddManyToOneNavProperty()
288
    {
@@ 287-338 (lines=52) @@
284
        $this->assertEquals('1', $dependentEnd->getMultiplicity());
285
    }
286
287
    public function testAddManyToOneNavProperty()
288
    {
289
        $msg = null;
290
        $metadataManager = new MetadataManager("Data", "Container");
291
        $result = null;
292
293
        list($CategoryType, $result) = $metadataManager->addEntityType("Category");
294
        list($CustomerType, $result) = $metadataManager->addEntityType("Customer");
295
        $this->assertTrue($CategoryType->isOK($msg), $msg);
296
        $this->assertTrue($CustomerType->isOK($msg), $msg);
297
298
        list($principal, $dependent) = $metadataManager->addNavigationPropertyToEntityType(
299
            $CategoryType,
300
            "1",
301
            "Customers",
302
            $CustomerType,
303
            "*",
304
            "Categories"
305
        );
306
        $this->assertEquals($principal->getFromRole(), $dependent->getToRole());
307
        $this->assertEquals($dependent->getFromRole(), $principal->getToRole());
308
        $this->assertEquals("Customers", $principal->getName());
309
        $this->assertEquals("Categories", $dependent->getName());
310
311
        $navProps = [$principal, $dependent];
312
        $assoc = $metadataManager->getEdmx()->getDataServiceType()->getSchema()[0]->getAssociation();
313
        $this->assertEquals(1, count($assoc));
314
        $assoc = $assoc[0];
315
        $this->assertTrue($assoc instanceof TAssociationType);
316
        $this->assertTrue($assoc->isOK($msg), $msg);
317
318
        $this->assertEquals('Data.'.$assoc->getName(), $principal->getRelationship());
319
        $ends = $assoc->getEnd();
320
321
        $this->assertEquals(2, count($ends));
322
        foreach ($navProps as $prop) {
323
            $fromMatch = $ends[0]->getRole() == $prop->getToRole()
324
                         || $ends[1]->getRole() == $prop->getToRole();
325
            $this->assertTrue($fromMatch, "toRole must match at least one end role");
326
            if ($ends[0]->getRole() == $prop->getToRole()) {
327
                $this->assertEquals($ends[1]->getRole(), $prop->getFromRole());
328
                $this->assertNotEquals($ends[0]->getRole(), $prop->getFromRole());
329
            } else {
330
                $this->assertEquals($ends[0]->getRole(), $prop->getFromRole());
331
                $this->assertNotEquals($ends[1]->getRole(), $prop->getFromRole());
332
            }
333
        }
334
        $principalEnd = ($ends[0]->getRole() == $principal->getToRole()) ? $ends[0] : $ends[1];
335
        $this->assertEquals('1', $principalEnd->getMultiplicity());
336
        $dependentEnd = ($ends[0]->getRole() == $dependent->getToRole()) ? $ends[0] : $ends[1];
337
        $this->assertEquals('*', $dependentEnd->getMultiplicity());
338
    }
339
340
    public function testAddOneToOneForwardNavProperty()
341
    {
@@ 340-391 (lines=52) @@
337
        $this->assertEquals('*', $dependentEnd->getMultiplicity());
338
    }
339
340
    public function testAddOneToOneForwardNavProperty()
341
    {
342
        $msg = null;
343
        $metadataManager = new MetadataManager("Data", "Container");
344
        $result = null;
345
346
        list($CategoryType, $result) = $metadataManager->addEntityType("Category");
347
        list($CustomerType, $result) = $metadataManager->addEntityType("Customer");
348
        $this->assertTrue($CategoryType->isOK($msg), $msg);
349
        $this->assertTrue($CustomerType->isOK($msg), $msg);
350
351
        list($principal, $dependent) = $metadataManager->addNavigationPropertyToEntityType(
352
            $CategoryType,
353
            "0..1",
354
            "Customers",
355
            $CustomerType,
356
            "1",
357
            "Categories"
358
        );
359
        $this->assertEquals($principal->getFromRole(), $dependent->getToRole());
360
        $this->assertEquals($dependent->getFromRole(), $principal->getToRole());
361
        $this->assertEquals("Customers", $principal->getName());
362
        $this->assertEquals("Categories", $dependent->getName());
363
364
        $navProps = [$principal, $dependent];
365
        $assoc = $metadataManager->getEdmx()->getDataServiceType()->getSchema()[0]->getAssociation();
366
        $this->assertEquals(1, count($assoc));
367
        $assoc = $assoc[0];
368
        $this->assertTrue($assoc instanceof TAssociationType);
369
        $this->assertTrue($assoc->isOK($msg), $msg);
370
371
        $this->assertEquals('Data.'.$assoc->getName(), $principal->getRelationship());
372
        $ends = $assoc->getEnd();
373
374
        $this->assertEquals(2, count($ends));
375
        foreach ($navProps as $prop) {
376
            $fromMatch = $ends[0]->getRole() == $prop->getToRole()
377
                         || $ends[1]->getRole() == $prop->getToRole();
378
            $this->assertTrue($fromMatch, "toRole must match at least one end role");
379
            if ($ends[0]->getRole() == $prop->getToRole()) {
380
                $this->assertEquals($ends[1]->getRole(), $prop->getFromRole());
381
                $this->assertNotEquals($ends[0]->getRole(), $prop->getFromRole());
382
            } else {
383
                $this->assertEquals($ends[0]->getRole(), $prop->getFromRole());
384
                $this->assertNotEquals($ends[1]->getRole(), $prop->getFromRole());
385
            }
386
        }
387
        $principalEnd = ($ends[0]->getRole() == $principal->getToRole()) ? $ends[0] : $ends[1];
388
        $this->assertEquals('0..1', $principalEnd->getMultiplicity());
389
        $dependentEnd = ($ends[0]->getRole() == $dependent->getToRole()) ? $ends[0] : $ends[1];
390
        $this->assertEquals('1', $dependentEnd->getMultiplicity());
391
    }
392
393
    public function testAddOneToOneReverseNavProperty()
394
    {
@@ 393-444 (lines=52) @@
390
        $this->assertEquals('1', $dependentEnd->getMultiplicity());
391
    }
392
393
    public function testAddOneToOneReverseNavProperty()
394
    {
395
        $msg = null;
396
        $metadataManager = new MetadataManager("Data", "Container");
397
        $result = null;
398
399
        list($CategoryType, $result) = $metadataManager->addEntityType("Category");
400
        list($CustomerType, $result) = $metadataManager->addEntityType("Customer");
401
        $this->assertTrue($CategoryType->isOK($msg), $msg);
402
        $this->assertTrue($CustomerType->isOK($msg), $msg);
403
404
        list($principal, $dependent) = $metadataManager->addNavigationPropertyToEntityType(
405
            $CategoryType,
406
            "1",
407
            "Customers",
408
            $CustomerType,
409
            "0..1",
410
            "Categories"
411
        );
412
        $this->assertEquals($principal->getFromRole(), $dependent->getToRole());
413
        $this->assertEquals($dependent->getFromRole(), $principal->getToRole());
414
        $this->assertEquals("Customers", $principal->getName());
415
        $this->assertEquals("Categories", $dependent->getName());
416
417
        $navProps = [$principal, $dependent];
418
        $assoc = $metadataManager->getEdmx()->getDataServiceType()->getSchema()[0]->getAssociation();
419
        $this->assertEquals(1, count($assoc));
420
        $assoc = $assoc[0];
421
        $this->assertTrue($assoc instanceof TAssociationType);
422
        $this->assertTrue($assoc->isOK($msg), $msg);
423
424
        $this->assertEquals('Data.'.$assoc->getName(), $principal->getRelationship());
425
        $ends = $assoc->getEnd();
426
427
        $this->assertEquals(2, count($ends));
428
        foreach ($navProps as $prop) {
429
            $fromMatch = $ends[0]->getRole() == $prop->getToRole()
430
                         || $ends[1]->getRole() == $prop->getToRole();
431
            $this->assertTrue($fromMatch, "toRole must match at least one end role");
432
            if ($ends[0]->getRole() == $prop->getToRole()) {
433
                $this->assertEquals($ends[1]->getRole(), $prop->getFromRole());
434
                $this->assertNotEquals($ends[0]->getRole(), $prop->getFromRole());
435
            } else {
436
                $this->assertEquals($ends[0]->getRole(), $prop->getFromRole());
437
                $this->assertNotEquals($ends[1]->getRole(), $prop->getFromRole());
438
            }
439
        }
440
        $principalEnd = ($ends[0]->getRole() == $principal->getToRole()) ? $ends[0] : $ends[1];
441
        $this->assertEquals('1', $principalEnd->getMultiplicity());
442
        $dependentEnd = ($ends[0]->getRole() == $dependent->getToRole()) ? $ends[0] : $ends[1];
443
        $this->assertEquals('0..1', $dependentEnd->getMultiplicity());
444
    }
445
446
    public function testMetadataSerialiseRoundTrip()
447
    {