DoctrinePaginatorAdapterTest   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 1
lcom 1
cbo 2
dl 0
loc 35
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A testPaginationAdapter() 0 32 1
1
<?php
2
3
namespace League\Fractal\Test\Pagination;
4
5
use League\Fractal\Pagination\DoctrinePaginatorAdapter;
6
use League\Fractal\Test\TestCase;
7
use Mockery;
8
9
class DoctrinePaginatorAdapterTest extends TestCase
10
{
11
    public function testPaginationAdapter()
12
    {
13
        $total       = 50;
14
        $count       = 5;
15
        $perPage     = 5;
16
        $currentPage = 2;
17
        $lastPage    = 10;
18
//Mock the doctrine paginator
19
        $paginator = Mockery::mock('Doctrine\ORM\Tools\Pagination\Paginator')->makePartial();
20
        $paginator->shouldReceive('count')->andReturn($total);
21
//Mock the query that the paginator is acting on
22
        $query = Mockery::mock('Doctrine\ORM\AbstractQuery');
23
        $query->shouldReceive('getFirstResult')->andReturn(($currentPage - 1) * $perPage);
24
        $query->shouldReceive('getMaxResults')->andReturn($perPage);
25
        $paginator->shouldReceive('getQuery')->andReturn($query);
26
//Mock the iterator of the paginator
27
        $iterator = Mockery::mock('IteratorAggregate');
28
        $iterator->shouldReceive('count')->andReturn($count);
29
        $paginator->shouldReceive('getIterator')->andReturn($iterator);
30
        $adapter = new DoctrinePaginatorAdapter($paginator, function ($page) {
31
32
            return 'http://example.com/foo?page=' . $page;
33
        });
34
        $this->assertInstanceOf('League\Fractal\Pagination\PaginatorInterface', $adapter);
35
        $this->assertSame($currentPage, $adapter->getCurrentPage());
36
        $this->assertSame($lastPage, $adapter->getLastPage());
37
        $this->assertSame($count, $adapter->getCount());
38
        $this->assertSame($total, $adapter->getTotal());
39
        $this->assertSame($perPage, $adapter->getPerPage());
40
        $this->assertSame('http://example.com/foo?page=1', $adapter->getUrl(1));
41
        $this->assertSame('http://example.com/foo?page=3', $adapter->getUrl(3));
42
    }
43
}
44