IlluminatePaginatorAdapterTest.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace League\Fractal\Test\Pagination;
  3. use League\Fractal\Pagination\IlluminatePaginatorAdapter;
  4. use Mockery;
  5. use PHPUnit\Framework\TestCase;
  6. class IlluminatePaginatorAdapterTest extends TestCase
  7. {
  8. public function testPaginationAdapter()
  9. {
  10. $total = 50;
  11. $count = 10;
  12. $perPage = 10;
  13. $currentPage = 2;
  14. $lastPage = 5;
  15. $url = 'http://example.com/foo?page=1';
  16. $paginator = Mockery::mock('Illuminate\Contracts\Pagination\LengthAwarePaginator');
  17. $paginator->shouldReceive('currentPage')->andReturn($currentPage);
  18. $paginator->shouldReceive('lastPage')->andReturn($lastPage);
  19. $paginator->shouldReceive('count')->andReturn($count);
  20. $paginator->shouldReceive('total')->andReturn($total);
  21. $paginator->shouldReceive('perPage')->andReturn($perPage);
  22. $paginator->shouldReceive('url')->with(1)->andReturn($url);
  23. $adapter = new IlluminatePaginatorAdapter($paginator);
  24. $this->assertInstanceOf('League\Fractal\Pagination\PaginatorInterface', $adapter);
  25. $this->assertInstanceOf('Illuminate\Contracts\Pagination\LengthAwarePaginator', $adapter->getPaginator());
  26. $this->assertSame($currentPage, $adapter->getCurrentPage());
  27. $this->assertSame($lastPage, $adapter->getLastPage());
  28. $this->assertSame($count, $adapter->getCount());
  29. $this->assertSame($total, $adapter->getTotal());
  30. $this->assertSame($perPage, $adapter->getPerPage());
  31. $this->assertSame('http://example.com/foo?page=1', $adapter->getUrl(1));
  32. }
  33. public function tearDown()
  34. {
  35. Mockery::close();
  36. }
  37. }