Code Duplication    Length = 97-97 lines in 2 locations

test/Serializer/JsonApiSerializerTest.php 2 locations

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