testPaginationAdapter()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 29
rs 9.456
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace League\Fractal\Test\Pagination;
4
5
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
6
use League\Fractal\Test\TestCase;
7
use Mockery;
8
9
class IlluminatePaginatorAdapterTest extends TestCase
10
{
11
    public function testPaginationAdapter()
12
    {
13
        $total = 50;
14
        $count = 10;
15
        $perPage = 10;
16
        $currentPage = 2;
17
        $lastPage = 5;
18
        $url = 'http://example.com/foo?page=1';
19
20
        $paginator = Mockery::mock('Illuminate\Contracts\Pagination\LengthAwarePaginator');
21
        $paginator->shouldReceive('currentPage')->andReturn($currentPage);
22
        $paginator->shouldReceive('lastPage')->andReturn($lastPage);
23
        $paginator->shouldReceive('items')->andReturn(array_fill(0, $count, ''));
24
        $paginator->shouldReceive('total')->andReturn($total);
25
        $paginator->shouldReceive('perPage')->andReturn($perPage);
26
        $paginator->shouldReceive('url')->with(1)->andReturn($url);
27
28
        $adapter = new IlluminatePaginatorAdapter($paginator);
29
30
        $this->assertInstanceOf('League\Fractal\Pagination\PaginatorInterface', $adapter);
31
        $this->assertInstanceOf('Illuminate\Contracts\Pagination\LengthAwarePaginator', $adapter->getPaginator());
32
33
        $this->assertSame($currentPage, $adapter->getCurrentPage());
34
        $this->assertSame($lastPage, $adapter->getLastPage());
35
        $this->assertSame($count, $adapter->getCount());
36
        $this->assertSame($total, $adapter->getTotal());
37
        $this->assertSame($perPage, $adapter->getPerPage());
38
        $this->assertSame('http://example.com/foo?page=1', $adapter->getUrl(1));
39
    }
40
}
41