Completed
Pull Request — master (#306)
by Benoît
03:13
created

ZendFrameworkPaginatorAdapterTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 46
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 4
Bugs 2 Features 1
Metric Value
wmc 2
c 4
b 2
f 1
lcom 0
cbo 4
dl 46
loc 46
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A tearDown() 4 4 1
B testPaginationAdapter() 38 38 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
namespace League\Fractal\Test\Pagination;
3
4
use League\Fractal\Pagination\ZendFrameworkPaginatorAdapter;
5
use Mockery;
6
7 View Code Duplication
class ZendFrameworkPaginatorAdapterTest extends \PHPUnit_Framework_TestCase
8
{
9
    public function testPaginationAdapter()
10
    {
11
        $items = [
12
            'Item 1', 'Item 2', 'Item 3', 'Item 4', 'Item 5', 'Item 6', 'Item 7', 'Item 8', 'Item 9', 'Item 10',
13
            'Item 11', 'Item 12', 'Item 13', 'Item 14', 'Item 15', 'Item 16', 'Item 17', 'Item 18', 'Item 19', 'Item 20',
14
            'Item 21', 'Item 22', 'Item 23', 'Item 24', 'Item 25', 'Item 26', 'Item 27', 'Item 28', 'Item 29', 'Item 30',
15
            'Item 31', 'Item 32', 'Item 33', 'Item 34', 'Item 35', 'Item 36', 'Item 37', 'Item 38', 'Item 39', 'Item 40',
16
            'Item 41', 'Item 42', 'Item 43', 'Item 44', 'Item 45', 'Item 46', 'Item 47', 'Item 48', 'Item 49', 'Item 50',
17
        ];
18
19
        $adapter = Mockery::mock('Zend\Paginator\Adapter\ArrayAdapter', [$items])->makePartial();
20
21
        $total = 50;
22
        $count = 10;
23
        $perPage = 10;
24
        $currentPage = 2;
25
        $lastPage = 5;
26
27
        $paginator = Mockery::mock('Zend\Paginator\Paginator', [$adapter])->makePartial();
28
29
        $paginator->shouldReceive('getCurrentPageNumber')->andReturn($currentPage);
30
        $paginator->shouldReceive('count')->andReturn($lastPage);
31
        $paginator->shouldReceive('getItemCountPerPage')->andReturn($perPage);
32
33
        $adapter = new ZendFrameworkPaginatorAdapter($paginator, function ($page) {
34
            return 'http://example.com/foo?page='.$page;
35
        });
36
37
        $this->assertInstanceOf('League\Fractal\Pagination\PaginatorInterface', $adapter);
38
39
        $this->assertSame($currentPage, $adapter->getCurrentPage());
40
        $this->assertSame($lastPage, $adapter->getLastPage());
41
        $this->assertSame($count, $adapter->getCount());
42
        $this->assertSame($total, $adapter->getTotal());
43
        $this->assertSame($perPage, $adapter->getPerPage());
44
        $this->assertSame('http://example.com/foo?page=1', $adapter->getUrl(1));
45
        $this->assertSame('http://example.com/foo?page=3', $adapter->getUrl(3));
46
    }
47
48
    public function tearDown()
49
    {
50
        Mockery::close();
51
    }
52
}
53