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