Code Duplication    Length = 45-45 lines in 4 locations

tests/MetadataManagerTest.php 4 locations

@@ 236-280 (lines=45) @@
233
        $this->assertEquals('*', $dependentEnd->getMultiplicity());
234
    }
235
236
    public function testAddOneToManyNavProperty()
237
    {
238
        list($msg, $metadataManager, $CategoryType, $CustomerType) = $this->setUpMetadataForNavTests();
239
240
        list($principal, $dependent) = $metadataManager->addNavigationPropertyToEntityType(
241
            $CategoryType,
242
            "*",
243
            "Customers",
244
            $CustomerType,
245
            "1",
246
            "Categories"
247
        );
248
        $this->assertEquals($principal->getFromRole(), $dependent->getToRole());
249
        $this->assertEquals($dependent->getFromRole(), $principal->getToRole());
250
        $this->assertEquals("Customers", $principal->getName());
251
        $this->assertEquals("Categories", $dependent->getName());
252
253
        $navProps = [$principal, $dependent];
254
        $assoc = $metadataManager->getEdmx()->getDataServiceType()->getSchema()[0]->getAssociation();
255
        $this->assertEquals(1, count($assoc));
256
        $assoc = $assoc[0];
257
        $this->assertTrue($assoc instanceof TAssociationType);
258
        $this->assertTrue($assoc->isOK($msg), $msg);
259
260
        $this->assertEquals('Data.'.$assoc->getName(), $principal->getRelationship());
261
        $ends = $assoc->getEnd();
262
263
        $this->assertEquals(2, count($ends));
264
        foreach ($navProps as $prop) {
265
            $fromMatch = $ends[0]->getRole() == $prop->getToRole()
266
                         || $ends[1]->getRole() == $prop->getToRole();
267
            $this->assertTrue($fromMatch, "toRole must match at least one end role");
268
            if ($ends[0]->getRole() == $prop->getToRole()) {
269
                $this->assertEquals($ends[1]->getRole(), $prop->getFromRole());
270
                $this->assertNotEquals($ends[0]->getRole(), $prop->getFromRole());
271
            } else {
272
                $this->assertEquals($ends[0]->getRole(), $prop->getFromRole());
273
                $this->assertNotEquals($ends[1]->getRole(), $prop->getFromRole());
274
            }
275
        }
276
        $principalEnd = ($ends[0]->getRole() == $principal->getToRole()) ? $ends[0] : $ends[1];
277
        $this->assertEquals('*', $principalEnd->getMultiplicity());
278
        $dependentEnd = ($ends[0]->getRole() == $dependent->getToRole()) ? $ends[0] : $ends[1];
279
        $this->assertEquals('1', $dependentEnd->getMultiplicity());
280
    }
281
282
    public function testAddManyToOneNavProperty()
283
    {
@@ 282-326 (lines=45) @@
279
        $this->assertEquals('1', $dependentEnd->getMultiplicity());
280
    }
281
282
    public function testAddManyToOneNavProperty()
283
    {
284
        list($msg, $metadataManager, $CategoryType, $CustomerType) = $this->setUpMetadataForNavTests();
285
286
        list($principal, $dependent) = $metadataManager->addNavigationPropertyToEntityType(
287
            $CategoryType,
288
            "1",
289
            "Customers",
290
            $CustomerType,
291
            "*",
292
            "Categories"
293
        );
294
        $this->assertEquals($principal->getFromRole(), $dependent->getToRole());
295
        $this->assertEquals($dependent->getFromRole(), $principal->getToRole());
296
        $this->assertEquals("Customers", $principal->getName());
297
        $this->assertEquals("Categories", $dependent->getName());
298
299
        $navProps = [$principal, $dependent];
300
        $assoc = $metadataManager->getEdmx()->getDataServiceType()->getSchema()[0]->getAssociation();
301
        $this->assertEquals(1, count($assoc));
302
        $assoc = $assoc[0];
303
        $this->assertTrue($assoc instanceof TAssociationType);
304
        $this->assertTrue($assoc->isOK($msg), $msg);
305
306
        $this->assertEquals('Data.'.$assoc->getName(), $principal->getRelationship());
307
        $ends = $assoc->getEnd();
308
309
        $this->assertEquals(2, count($ends));
310
        foreach ($navProps as $prop) {
311
            $fromMatch = $ends[0]->getRole() == $prop->getToRole()
312
                         || $ends[1]->getRole() == $prop->getToRole();
313
            $this->assertTrue($fromMatch, "toRole must match at least one end role");
314
            if ($ends[0]->getRole() == $prop->getToRole()) {
315
                $this->assertEquals($ends[1]->getRole(), $prop->getFromRole());
316
                $this->assertNotEquals($ends[0]->getRole(), $prop->getFromRole());
317
            } else {
318
                $this->assertEquals($ends[0]->getRole(), $prop->getFromRole());
319
                $this->assertNotEquals($ends[1]->getRole(), $prop->getFromRole());
320
            }
321
        }
322
        $principalEnd = ($ends[0]->getRole() == $principal->getToRole()) ? $ends[0] : $ends[1];
323
        $this->assertEquals('1', $principalEnd->getMultiplicity());
324
        $dependentEnd = ($ends[0]->getRole() == $dependent->getToRole()) ? $ends[0] : $ends[1];
325
        $this->assertEquals('*', $dependentEnd->getMultiplicity());
326
    }
327
328
    public function testAddOneToOneForwardNavProperty()
329
    {
@@ 328-372 (lines=45) @@
325
        $this->assertEquals('*', $dependentEnd->getMultiplicity());
326
    }
327
328
    public function testAddOneToOneForwardNavProperty()
329
    {
330
        list($msg, $metadataManager, $CategoryType, $CustomerType) = $this->setUpMetadataForNavTests();
331
332
        list($principal, $dependent) = $metadataManager->addNavigationPropertyToEntityType(
333
            $CategoryType,
334
            "0..1",
335
            "Customers",
336
            $CustomerType,
337
            "1",
338
            "Categories"
339
        );
340
        $this->assertEquals($principal->getFromRole(), $dependent->getToRole());
341
        $this->assertEquals($dependent->getFromRole(), $principal->getToRole());
342
        $this->assertEquals("Customers", $principal->getName());
343
        $this->assertEquals("Categories", $dependent->getName());
344
345
        $navProps = [$principal, $dependent];
346
        $assoc = $metadataManager->getEdmx()->getDataServiceType()->getSchema()[0]->getAssociation();
347
        $this->assertEquals(1, count($assoc));
348
        $assoc = $assoc[0];
349
        $this->assertTrue($assoc instanceof TAssociationType);
350
        $this->assertTrue($assoc->isOK($msg), $msg);
351
352
        $this->assertEquals('Data.'.$assoc->getName(), $principal->getRelationship());
353
        $ends = $assoc->getEnd();
354
355
        $this->assertEquals(2, count($ends));
356
        foreach ($navProps as $prop) {
357
            $fromMatch = $ends[0]->getRole() == $prop->getToRole()
358
                         || $ends[1]->getRole() == $prop->getToRole();
359
            $this->assertTrue($fromMatch, "toRole must match at least one end role");
360
            if ($ends[0]->getRole() == $prop->getToRole()) {
361
                $this->assertEquals($ends[1]->getRole(), $prop->getFromRole());
362
                $this->assertNotEquals($ends[0]->getRole(), $prop->getFromRole());
363
            } else {
364
                $this->assertEquals($ends[0]->getRole(), $prop->getFromRole());
365
                $this->assertNotEquals($ends[1]->getRole(), $prop->getFromRole());
366
            }
367
        }
368
        $principalEnd = ($ends[0]->getRole() == $principal->getToRole()) ? $ends[0] : $ends[1];
369
        $this->assertEquals('0..1', $principalEnd->getMultiplicity());
370
        $dependentEnd = ($ends[0]->getRole() == $dependent->getToRole()) ? $ends[0] : $ends[1];
371
        $this->assertEquals('1', $dependentEnd->getMultiplicity());
372
    }
373
374
    public function testAddOneToOneReverseNavProperty()
375
    {
@@ 374-418 (lines=45) @@
371
        $this->assertEquals('1', $dependentEnd->getMultiplicity());
372
    }
373
374
    public function testAddOneToOneReverseNavProperty()
375
    {
376
        list($msg, $metadataManager, $CategoryType, $CustomerType) = $this->setUpMetadataForNavTests();
377
378
        list($principal, $dependent) = $metadataManager->addNavigationPropertyToEntityType(
379
            $CategoryType,
380
            "1",
381
            "Customers",
382
            $CustomerType,
383
            "0..1",
384
            "Categories"
385
        );
386
        $this->assertEquals($principal->getFromRole(), $dependent->getToRole());
387
        $this->assertEquals($dependent->getFromRole(), $principal->getToRole());
388
        $this->assertEquals("Customers", $principal->getName());
389
        $this->assertEquals("Categories", $dependent->getName());
390
391
        $navProps = [$principal, $dependent];
392
        $assoc = $metadataManager->getEdmx()->getDataServiceType()->getSchema()[0]->getAssociation();
393
        $this->assertEquals(1, count($assoc));
394
        $assoc = $assoc[0];
395
        $this->assertTrue($assoc instanceof TAssociationType);
396
        $this->assertTrue($assoc->isOK($msg), $msg);
397
398
        $this->assertEquals('Data.'.$assoc->getName(), $principal->getRelationship());
399
        $ends = $assoc->getEnd();
400
401
        $this->assertEquals(2, count($ends));
402
        foreach ($navProps as $prop) {
403
            $fromMatch = $ends[0]->getRole() == $prop->getToRole()
404
                         || $ends[1]->getRole() == $prop->getToRole();
405
            $this->assertTrue($fromMatch, "toRole must match at least one end role");
406
            if ($ends[0]->getRole() == $prop->getToRole()) {
407
                $this->assertEquals($ends[1]->getRole(), $prop->getFromRole());
408
                $this->assertNotEquals($ends[0]->getRole(), $prop->getFromRole());
409
            } else {
410
                $this->assertEquals($ends[0]->getRole(), $prop->getFromRole());
411
                $this->assertNotEquals($ends[1]->getRole(), $prop->getFromRole());
412
            }
413
        }
414
        $principalEnd = ($ends[0]->getRole() == $principal->getToRole()) ? $ends[0] : $ends[1];
415
        $this->assertEquals('1', $principalEnd->getMultiplicity());
416
        $dependentEnd = ($ends[0]->getRole() == $dependent->getToRole()) ? $ends[0] : $ends[1];
417
        $this->assertEquals('0..1', $dependentEnd->getMultiplicity());
418
    }
419
420
    public function testMetadataSerialiseRoundTrip()
421
    {