Code Duplication    Length = 97-97 lines in 2 locations

test/Serializer/JsonApiSerializerTest.php 2 locations

@@ 1849-1945 (lines=97) @@
1846
        $this->assertSame($expectedJson, $scope->toJson());
1847
    }
1848
1849
    public function testSerializingCollectionResourceWithPaginatorWithOmittedUnavailablePreviousLink()
1850
    {
1851
        $baseUrl = 'http://example.com';
1852
1853
        $this->manager->setSerializer(new JsonApiSerializer($baseUrl));
1854
1855
        $total = 10;
1856
        $count = 2;
1857
        $perPage = 2;
1858
        $currentPage = 1;
1859
        $lastPage = 5;
1860
        $currentUrl = 'http://example.com/books/?page=1';
1861
        $nextUrl = 'http://example.com/books/?page=2';
1862
        $lastUrl = 'http://example.com/books/?page=5';
1863
1864
        $paginator = Mockery::mock('League\Fractal\Pagination\PaginatorInterface');
1865
        $paginator->shouldReceive('getCurrentPage')->andReturn($currentPage);
1866
        $paginator->shouldReceive('getLastPage')->andReturn($lastPage);
1867
        $paginator->shouldReceive('getTotal')->andReturn($total);
1868
        $paginator->shouldReceive('getCount')->andReturn($count);
1869
        $paginator->shouldReceive('getPerPage')->andReturn($perPage);
1870
        $paginator->shouldReceive('getUrl')->with(1)->andReturn($currentUrl);
1871
        $paginator->shouldReceive('getUrl')->with(2)->andReturn($nextUrl);
1872
        $paginator->shouldReceive('getUrl')->with(5)->andReturn($lastUrl);
1873
1874
        $booksData = [
1875
            [
1876
                'id' => 1,
1877
                'title' => 'Foo',
1878
                'year' => '1991',
1879
                '_author' => [
1880
                    'id' => 1,
1881
                    'name' => 'Dave',
1882
                ],
1883
            ],
1884
            [
1885
                'id' => 2,
1886
                'title' => 'Bar',
1887
                'year' => '1997',
1888
                '_author' => [
1889
                    'id' => 2,
1890
                    'name' => 'Bob',
1891
                ],
1892
            ],
1893
        ];
1894
1895
        $resource = new Collection($booksData, new JsonApiBookTransformer(), 'books');
1896
        $resource->setPaginator($paginator);
1897
        $scope = new Scope($this->manager, $resource);
1898
1899
        $expected = [
1900
            'data' => [
1901
                [
1902
                    'type' => 'books',
1903
                    'id' => '1',
1904
                    'attributes' => [
1905
                        'title' => 'Foo',
1906
                        'year' => 1991,
1907
                    ],
1908
                    'links' => [
1909
                        'self' => 'http://example.com/books/1',
1910
                    ],
1911
                ],
1912
                [
1913
                    'type' => 'books',
1914
                    'id' => '2',
1915
                    'attributes' => [
1916
                        'title' => 'Bar',
1917
                        'year' => 1997,
1918
                    ],
1919
                    'links' => [
1920
                        'self' => 'http://example.com/books/2',
1921
                    ],
1922
                ],
1923
            ],
1924
            'meta' => [
1925
                'pagination' => [
1926
                    'total' =>  10,
1927
                    'count' => 2,
1928
                    'per_page' => 2,
1929
                    'current_page' => 1,
1930
                    'total_pages' => 5
1931
                ]
1932
            ],
1933
            'links' => [
1934
                'self' => 'http://example.com/books/?page=1',
1935
                'first' => 'http://example.com/books/?page=1',
1936
                'next' => 'http://example.com/books/?page=2',
1937
                'last' => 'http://example.com/books/?page=5'
1938
            ]
1939
        ];
1940
1941
        $this->assertSame($expected, $scope->toArray());
1942
1943
        $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"}}';
1944
        $this->assertSame($expectedJson, $scope->toJson());
1945
    }
1946
1947
    public function testSerializingCollectionResourceWithPaginatorWithOmittedUnavailableNextLink()
1948
    {
@@ 1947-2043 (lines=97) @@
1944
        $this->assertSame($expectedJson, $scope->toJson());
1945
    }
1946
1947
    public function testSerializingCollectionResourceWithPaginatorWithOmittedUnavailableNextLink()
1948
    {
1949
        $baseUrl = 'http://example.com';
1950
1951
        $this->manager->setSerializer(new JsonApiSerializer($baseUrl));
1952
1953
        $total = 10;
1954
        $count = 2;
1955
        $perPage = 2;
1956
        $currentPage = 5;
1957
        $lastPage = 5;
1958
        $firstUrl = 'http://example.com/books/?page=1';
1959
        $previousUrl = 'http://example.com/books/?page=4';
1960
        $lastUrl = 'http://example.com/books/?page=5';
1961
1962
        $paginator = Mockery::mock('League\Fractal\Pagination\PaginatorInterface');
1963
        $paginator->shouldReceive('getCurrentPage')->andReturn($currentPage);
1964
        $paginator->shouldReceive('getLastPage')->andReturn($lastPage);
1965
        $paginator->shouldReceive('getTotal')->andReturn($total);
1966
        $paginator->shouldReceive('getCount')->andReturn($count);
1967
        $paginator->shouldReceive('getPerPage')->andReturn($perPage);
1968
        $paginator->shouldReceive('getUrl')->with(1)->andReturn($firstUrl);
1969
        $paginator->shouldReceive('getUrl')->with(4)->andReturn($previousUrl);
1970
        $paginator->shouldReceive('getUrl')->with(5)->andReturn($lastUrl);
1971
1972
        $booksData = [
1973
            [
1974
                'id' => 1,
1975
                'title' => 'Foo',
1976
                'year' => '1991',
1977
                '_author' => [
1978
                    'id' => 1,
1979
                    'name' => 'Dave',
1980
                ],
1981
            ],
1982
            [
1983
                'id' => 2,
1984
                'title' => 'Bar',
1985
                'year' => '1997',
1986
                '_author' => [
1987
                    'id' => 2,
1988
                    'name' => 'Bob',
1989
                ],
1990
            ],
1991
        ];
1992
1993
        $resource = new Collection($booksData, new JsonApiBookTransformer(), 'books');
1994
        $resource->setPaginator($paginator);
1995
        $scope = new Scope($this->manager, $resource);
1996
1997
        $expected = [
1998
            'data' => [
1999
                [
2000
                    'type' => 'books',
2001
                    'id' => '1',
2002
                    'attributes' => [
2003
                        'title' => 'Foo',
2004
                        'year' => 1991,
2005
                    ],
2006
                    'links' => [
2007
                        'self' => 'http://example.com/books/1',
2008
                    ],
2009
                ],
2010
                [
2011
                    'type' => 'books',
2012
                    'id' => '2',
2013
                    'attributes' => [
2014
                        'title' => 'Bar',
2015
                        'year' => 1997,
2016
                    ],
2017
                    'links' => [
2018
                        'self' => 'http://example.com/books/2',
2019
                    ],
2020
                ],
2021
            ],
2022
            'meta' => [
2023
                'pagination' => [
2024
                    'total' =>  10,
2025
                    'count' => 2,
2026
                    'per_page' => 2,
2027
                    'current_page' => 5,
2028
                    'total_pages' => 5
2029
                ]
2030
            ],
2031
            'links' => [
2032
                'self' => 'http://example.com/books/?page=5',
2033
                'first' => 'http://example.com/books/?page=1',
2034
                'prev' => 'http://example.com/books/?page=4',
2035
                'last' => 'http://example.com/books/?page=5'
2036
            ]
2037
        ];
2038
2039
        $this->assertSame($expected, $scope->toArray());
2040
2041
        $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"}}';
2042
        $this->assertSame($expectedJson, $scope->toJson());
2043
    }
2044
2045
    public function testCustomLinkMerge()
2046
    {