| @@ 7-61 (lines=55) @@ | ||
| 4 | use League\Fractal\Pagination\PagerfantaPaginatorAdapter; |
|
| 5 | use Mockery; |
|
| 6 | ||
| 7 | class PagerfantaPaginatorAdapterTest 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('Pagerfanta\Adapter\ArrayAdapter', [$items])->makePartial(); |
|
| 20 | ||
| 21 | $total = 50; |
|
| 22 | $count = 5; |
|
| 23 | $perPage = 5; |
|
| 24 | $currentPage = 2; |
|
| 25 | $lastPage = 10; |
|
| 26 | ||
| 27 | $paginator = Mockery::mock('Pagerfanta\Pagerfanta', [$adapter])->makePartial(); |
|
| 28 | ||
| 29 | $paginator->shouldReceive('getCurrentPage')->andReturn($currentPage); |
|
| 30 | $paginator->shouldReceive('getLastPage')->andReturn($lastPage); |
|
| 31 | $paginator->shouldReceive('getMaxPerPage')->andReturn($perPage); |
|
| 32 | ||
| 33 | $adapter = new PagerfantaPaginatorAdapter($paginator, function ($page) { |
|
| 34 | return 'http://example.com/foo?page='.$page; |
|
| 35 | }); |
|
| 36 | ||
| 37 | $this->assertInstanceOf( |
|
| 38 | 'League\Fractal\Pagination\PaginatorInterface', |
|
| 39 | $adapter |
|
| 40 | ); |
|
| 41 | ||
| 42 | $this->assertSame($currentPage, $adapter->getCurrentPage()); |
|
| 43 | $this->assertSame($lastPage, $adapter->getLastPage()); |
|
| 44 | $this->assertSame($count, $adapter->getCount()); |
|
| 45 | $this->assertSame($total, $adapter->getTotal()); |
|
| 46 | $this->assertSame($perPage, $adapter->getPerPage()); |
|
| 47 | $this->assertSame( |
|
| 48 | 'http://example.com/foo?page=1', |
|
| 49 | $adapter->getUrl(1) |
|
| 50 | ); |
|
| 51 | $this->assertSame( |
|
| 52 | 'http://example.com/foo?page=3', |
|
| 53 | $adapter->getUrl(3) |
|
| 54 | ); |
|
| 55 | } |
|
| 56 | ||
| 57 | public function tearDown() |
|
| 58 | { |
|
| 59 | Mockery::close(); |
|
| 60 | } |
|
| 61 | } |
|
| 62 | ||
| @@ 7-52 (lines=46) @@ | ||
| 4 | use League\Fractal\Pagination\ZendFrameworkPaginatorAdapter; |
|
| 5 | use Mockery; |
|
| 6 | ||
| 7 | 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 | ||