Completed
Push — master ( ebc071...9dcd83 )
by Tobias
29:49 queued 29:28
created

Pagination/ZendFrameworkPaginatorAdapterTest.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
namespace League\Fractal\Test\Pagination;
3
4
use League\Fractal\Pagination\ZendFrameworkPaginatorAdapter;
5
use Mockery;
6
use PHPUnit\Framework\TestCase;
7
8 View Code Duplication
class ZendFrameworkPaginatorAdapterTest extends TestCase
0 ignored issues
show
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
9
{
10
    public function testPaginationAdapter()
11
    {
12
        $items = [
13
            'Item 1', 'Item 2', 'Item 3', 'Item 4', 'Item 5', 'Item 6', 'Item 7', 'Item 8', 'Item 9', 'Item 10',
14
            'Item 11', 'Item 12', 'Item 13', 'Item 14', 'Item 15', 'Item 16', 'Item 17', 'Item 18', 'Item 19', 'Item 20',
15
            'Item 21', 'Item 22', 'Item 23', 'Item 24', 'Item 25', 'Item 26', 'Item 27', 'Item 28', 'Item 29', 'Item 30',
16
            'Item 31', 'Item 32', 'Item 33', 'Item 34', 'Item 35', 'Item 36', 'Item 37', 'Item 38', 'Item 39', 'Item 40',
17
            'Item 41', 'Item 42', 'Item 43', 'Item 44', 'Item 45', 'Item 46', 'Item 47', 'Item 48', 'Item 49', 'Item 50',
18
        ];
19
20
        $adapter = Mockery::mock('Zend\Paginator\Adapter\ArrayAdapter', [$items])->makePartial();
21
22
        $total = 50;
23
        $count = 10;
24
        $perPage = 10;
25
        $currentPage = 2;
26
        $lastPage = 5;
27
28
        $paginator = Mockery::mock('Zend\Paginator\Paginator', [$adapter])->makePartial();
29
30
        $paginator->shouldReceive('getCurrentPageNumber')->andReturn($currentPage);
31
        $paginator->shouldReceive('count')->andReturn($lastPage);
32
        $paginator->shouldReceive('getItemCountPerPage')->andReturn($perPage);
33
34
        $adapter = new ZendFrameworkPaginatorAdapter($paginator, function ($page) {
0 ignored issues
show
$paginator is of type object<Mockery\Mock>, but the function expects a object<Zend\Paginator\Paginator>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
35
            return 'http://example.com/foo?page='.$page;
36
        });
37
38
        $this->assertInstanceOf('League\Fractal\Pagination\PaginatorInterface', $adapter);
39
40
        $this->assertSame($currentPage, $adapter->getCurrentPage());
41
        $this->assertSame($lastPage, $adapter->getLastPage());
42
        $this->assertSame($count, $adapter->getCount());
43
        $this->assertSame($total, $adapter->getTotal());
44
        $this->assertSame($perPage, $adapter->getPerPage());
45
        $this->assertSame('http://example.com/foo?page=1', $adapter->getUrl(1));
46
        $this->assertSame('http://example.com/foo?page=3', $adapter->getUrl(3));
47
    }
48
49
    public function tearDown()
50
    {
51
        Mockery::close();
52
    }
53
}
54