Code Duplication    Length = 58-59 lines in 2 locations

test/JsonApiSerializerTest.php 2 locations

@@ 2459-2517 (lines=59) @@
2456
        $this->assertSame($expectedJson, $scope->toJson());
2457
    }
2458
2459
    public function testCustomLinkMerge()
2460
    {
2461
        $manager = new Manager();
2462
        $manager->setSerializer(new JsonApiSerializer('http://test.de'));
2463
2464
        $bookData = [
2465
            'id' => 1,
2466
            'title' => 'Foo',
2467
            'year' => '1991',
2468
            '_author' => [
2469
                'id' => 1,
2470
                'name' => 'Dave',
2471
            ],
2472
            'links' => [
2473
                'custom_link' => '/custom/link',
2474
            ],
2475
        ];
2476
2477
        $resource = new Item($bookData, new JsonApiBookTransformer(), 'books');
2478
2479
        $scope = new Scope($manager, $resource);
2480
2481
        $expected = [
2482
            'data' => [
2483
                'type' => 'books',
2484
                'id' => '1',
2485
                'attributes' => [
2486
                    'title' => 'Foo',
2487
                    'year' => 1991,
2488
                ],
2489
                'links' => [
2490
                    'self' => 'http://test.de/books/1',
2491
                    'custom_link' => '/custom/link',
2492
                ],
2493
                'relationships' => [
2494
                    'author' => [
2495
                        'links' => [
2496
                            'self' => 'http://test.de/books/1/relationships/author',
2497
                            'related' => 'http://test.de/books/1/author',
2498
                        ],
2499
                    ],
2500
                    'co-author' => [
2501
                        'links' => [
2502
                            'self' => 'http://test.de/books/1/relationships/co-author',
2503
                            'related' => 'http://test.de/books/1/co-author'
2504
                        ],
2505
                    ],
2506
                    'author-with-meta' => [
2507
                        'links' => [
2508
                            'self' => 'http://test.de/books/1/relationships/author-with-meta',
2509
                            'related' => 'http://test.de/books/1/author-with-meta'
2510
                        ],
2511
                    ],
2512
                ],
2513
            ],
2514
        ];
2515
2516
        $this->assertSame(json_encode($expected), $scope->toJson());
2517
    }
2518
2519
    public function testCustomLinkMergeNoLink()
2520
    {
@@ 2575-2632 (lines=58) @@
2572
        $this->assertSame(json_encode($expected), $scope->toJson());
2573
    }
2574
2575
    public function testCustomSelfLinkMerge()
2576
    {
2577
        $manager = new Manager();
2578
        $manager->setSerializer(new JsonApiSerializer('http://test.de'));
2579
2580
        $bookData = [
2581
            'id' => 1,
2582
            'title' => 'Foo',
2583
            'year' => '1991',
2584
            '_author' => [
2585
                'id' => 1,
2586
                'name' => 'Dave',
2587
            ],
2588
            'links' => [
2589
                'self' => '/custom/link',
2590
            ],
2591
        ];
2592
2593
        $resource = new Item($bookData, new JsonApiBookTransformer(), 'books');
2594
2595
        $scope = new Scope($manager, $resource);
2596
2597
        $expected = [
2598
            'data' => [
2599
                'type' => 'books',
2600
                'id' => '1',
2601
                'attributes' => [
2602
                    'title' => 'Foo',
2603
                    'year' => 1991,
2604
                ],
2605
                'links' => [
2606
                    'self' => '/custom/link',
2607
                ],
2608
                'relationships' => [
2609
                    'author' => [
2610
                        'links' => [
2611
                            'self' => 'http://test.de/books/1/relationships/author',
2612
                            'related' => 'http://test.de/books/1/author',
2613
                        ],
2614
                    ],
2615
                    'co-author' => [
2616
                        'links' => [
2617
                            'self' => 'http://test.de/books/1/relationships/co-author',
2618
                            'related' => 'http://test.de/books/1/co-author'
2619
                        ],
2620
                    ],
2621
                    'author-with-meta' => [
2622
                        'links' => [
2623
                            'self' => 'http://test.de/books/1/relationships/author-with-meta',
2624
                            'related' => 'http://test.de/books/1/author-with-meta'
2625
                        ],
2626
                    ],
2627
                ],
2628
            ],
2629
        ];
2630
2631
        $this->assertSame(json_encode($expected), $scope->toJson());
2632
    }
2633
2634
    public function testEmptyAttributesIsObject()
2635
    {