Code Duplication    Length = 97-97 lines in 2 locations

test/Serializer/JsonApiSerializerTest.php 2 locations

@@ 1783-1879 (lines=97) @@
1780
        $this->assertSame($expectedJson, $scope->toJson());
1781
    }
1782
1783
    public function testSerializingCollectionResourceWithPaginatorWithOmittedUnavailablePreviousLink()
1784
    {
1785
        $baseUrl = 'http://example.com';
1786
1787
        $this->manager->setSerializer(new JsonApiSerializer($baseUrl));
1788
1789
        $total = 10;
1790
        $count = 2;
1791
        $perPage = 2;
1792
        $currentPage = 1;
1793
        $lastPage = 5;
1794
        $currentUrl = 'http://example.com/books/?page=1';
1795
        $nextUrl = 'http://example.com/books/?page=2';
1796
        $lastUrl = 'http://example.com/books/?page=5';
1797
1798
        $paginator = Mockery::mock('League\Fractal\Pagination\PaginatorInterface');
1799
        $paginator->shouldReceive('getCurrentPage')->andReturn($currentPage);
1800
        $paginator->shouldReceive('getLastPage')->andReturn($lastPage);
1801
        $paginator->shouldReceive('getTotal')->andReturn($total);
1802
        $paginator->shouldReceive('getCount')->andReturn($count);
1803
        $paginator->shouldReceive('getPerPage')->andReturn($perPage);
1804
        $paginator->shouldReceive('getUrl')->with(1)->andReturn($currentUrl);
1805
        $paginator->shouldReceive('getUrl')->with(2)->andReturn($nextUrl);
1806
        $paginator->shouldReceive('getUrl')->with(5)->andReturn($lastUrl);
1807
1808
        $booksData = [
1809
            [
1810
                'id' => 1,
1811
                'title' => 'Foo',
1812
                'year' => '1991',
1813
                '_author' => [
1814
                    'id' => 1,
1815
                    'name' => 'Dave',
1816
                ],
1817
            ],
1818
            [
1819
                'id' => 2,
1820
                'title' => 'Bar',
1821
                'year' => '1997',
1822
                '_author' => [
1823
                    'id' => 2,
1824
                    'name' => 'Bob',
1825
                ],
1826
            ],
1827
        ];
1828
1829
        $resource = new Collection($booksData, new JsonApiBookTransformer(), 'books');
1830
        $resource->setPaginator($paginator);
1831
        $scope = new Scope($this->manager, $resource);
1832
1833
        $expected = [
1834
            'data' => [
1835
                [
1836
                    'type' => 'books',
1837
                    'id' => '1',
1838
                    'attributes' => [
1839
                        'title' => 'Foo',
1840
                        'year' => 1991,
1841
                    ],
1842
                    'links' => [
1843
                        'self' => 'http://example.com/books/1',
1844
                    ],
1845
                ],
1846
                [
1847
                    'type' => 'books',
1848
                    'id' => '2',
1849
                    'attributes' => [
1850
                        'title' => 'Bar',
1851
                        'year' => 1997,
1852
                    ],
1853
                    'links' => [
1854
                        'self' => 'http://example.com/books/2',
1855
                    ],
1856
                ],
1857
            ],
1858
            'meta' => [
1859
                'pagination' => [
1860
                    'total' =>  10,
1861
                    'count' => 2,
1862
                    'per_page' => 2,
1863
                    'current_page' => 1,
1864
                    'total_pages' => 5
1865
                ]
1866
            ],
1867
            'links' => [
1868
                'self' => 'http://example.com/books/?page=1',
1869
                'first' => 'http://example.com/books/?page=1',
1870
                'next' => 'http://example.com/books/?page=2',
1871
                'last' => 'http://example.com/books/?page=5'
1872
            ]
1873
        ];
1874
1875
        $this->assertSame($expected, $scope->toArray());
1876
1877
        $expectedJson = '{"data":[{"type":"books","id":"1","attributes":{"title":"Foo","year":1991},"links":{"self":"http:\/\/example.com\/books\/1"}},{"type":"books","id":"2","attributes":{"title":"Bar","year":1997},"links":{"self":"http:\/\/example.com\/books\/2"}}],"meta":{"pagination":{"total":10,"count":2,"per_page":2,"current_page":1,"total_pages":5}},"links":{"self":"http:\/\/example.com\/books\/?page=1","first":"http:\/\/example.com\/books\/?page=1","next":"http:\/\/example.com\/books\/?page=2","last":"http:\/\/example.com\/books\/?page=5"}}';
1878
        $this->assertSame($expectedJson, $scope->toJson());
1879
    }
1880
1881
    public function testSerializingCollectionResourceWithPaginatorWithOmittedUnavailableNextLink()
1882
    {
@@ 1881-1977 (lines=97) @@
1878
        $this->assertSame($expectedJson, $scope->toJson());
1879
    }
1880
1881
    public function testSerializingCollectionResourceWithPaginatorWithOmittedUnavailableNextLink()
1882
    {
1883
        $baseUrl = 'http://example.com';
1884
1885
        $this->manager->setSerializer(new JsonApiSerializer($baseUrl));
1886
1887
        $total = 10;
1888
        $count = 2;
1889
        $perPage = 2;
1890
        $currentPage = 5;
1891
        $lastPage = 5;
1892
        $firstUrl = 'http://example.com/books/?page=1';
1893
        $previousUrl = 'http://example.com/books/?page=4';
1894
        $lastUrl = 'http://example.com/books/?page=5';
1895
1896
        $paginator = Mockery::mock('League\Fractal\Pagination\PaginatorInterface');
1897
        $paginator->shouldReceive('getCurrentPage')->andReturn($currentPage);
1898
        $paginator->shouldReceive('getLastPage')->andReturn($lastPage);
1899
        $paginator->shouldReceive('getTotal')->andReturn($total);
1900
        $paginator->shouldReceive('getCount')->andReturn($count);
1901
        $paginator->shouldReceive('getPerPage')->andReturn($perPage);
1902
        $paginator->shouldReceive('getUrl')->with(1)->andReturn($firstUrl);
1903
        $paginator->shouldReceive('getUrl')->with(4)->andReturn($previousUrl);
1904
        $paginator->shouldReceive('getUrl')->with(5)->andReturn($lastUrl);
1905
1906
        $booksData = [
1907
            [
1908
                'id' => 1,
1909
                'title' => 'Foo',
1910
                'year' => '1991',
1911
                '_author' => [
1912
                    'id' => 1,
1913
                    'name' => 'Dave',
1914
                ],
1915
            ],
1916
            [
1917
                'id' => 2,
1918
                'title' => 'Bar',
1919
                'year' => '1997',
1920
                '_author' => [
1921
                    'id' => 2,
1922
                    'name' => 'Bob',
1923
                ],
1924
            ],
1925
        ];
1926
1927
        $resource = new Collection($booksData, new JsonApiBookTransformer(), 'books');
1928
        $resource->setPaginator($paginator);
1929
        $scope = new Scope($this->manager, $resource);
1930
1931
        $expected = [
1932
            'data' => [
1933
                [
1934
                    'type' => 'books',
1935
                    'id' => '1',
1936
                    'attributes' => [
1937
                        'title' => 'Foo',
1938
                        'year' => 1991,
1939
                    ],
1940
                    'links' => [
1941
                        'self' => 'http://example.com/books/1',
1942
                    ],
1943
                ],
1944
                [
1945
                    'type' => 'books',
1946
                    'id' => '2',
1947
                    'attributes' => [
1948
                        'title' => 'Bar',
1949
                        'year' => 1997,
1950
                    ],
1951
                    'links' => [
1952
                        'self' => 'http://example.com/books/2',
1953
                    ],
1954
                ],
1955
            ],
1956
            'meta' => [
1957
                'pagination' => [
1958
                    'total' =>  10,
1959
                    'count' => 2,
1960
                    'per_page' => 2,
1961
                    'current_page' => 5,
1962
                    'total_pages' => 5
1963
                ]
1964
            ],
1965
            'links' => [
1966
                'self' => 'http://example.com/books/?page=5',
1967
                'first' => 'http://example.com/books/?page=1',
1968
                'prev' => 'http://example.com/books/?page=4',
1969
                'last' => 'http://example.com/books/?page=5'
1970
            ]
1971
        ];
1972
1973
        $this->assertSame($expected, $scope->toArray());
1974
1975
        $expectedJson = '{"data":[{"type":"books","id":"1","attributes":{"title":"Foo","year":1991},"links":{"self":"http:\/\/example.com\/books\/1"}},{"type":"books","id":"2","attributes":{"title":"Bar","year":1997},"links":{"self":"http:\/\/example.com\/books\/2"}}],"meta":{"pagination":{"total":10,"count":2,"per_page":2,"current_page":5,"total_pages":5}},"links":{"self":"http:\/\/example.com\/books\/?page=5","first":"http:\/\/example.com\/books\/?page=1","prev":"http:\/\/example.com\/books\/?page=4","last":"http:\/\/example.com\/books\/?page=5"}}';
1976
        $this->assertSame($expectedJson, $scope->toJson());
1977
    }
1978
1979
    public function testCustomLinkMerge()
1980
    {