Skip to content

Commit c4e4d37

Browse files
Adds laravel's simple paginator adapter
1 parent 82e97a1 commit c4e4d37

File tree

2 files changed

+52
-7
lines changed

2 files changed

+52
-7
lines changed

src/Pagination/IlluminateSimplePaginatorAdapter.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace PHPOpenSourceSaver\Fractal\Pagination;
1313

14-
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
14+
use Illuminate\Contracts\Pagination\Paginator;
1515

1616
/**
1717
* A paginator adapter for illuminate/pagination.
@@ -21,12 +21,12 @@
2121
*/
2222
class IlluminateSimplePaginatorAdapter implements PaginatorInterface
2323
{
24-
protected LengthAwarePaginator $paginator;
24+
protected Paginator $paginator;
2525

2626
/**
27-
* Create a new illuminate pagination adapter.
27+
* Create a new illuminate simple pagination adapter.
2828
*/
29-
public function __construct(LengthAwarePaginator $paginator)
29+
public function __construct(Paginator $paginator)
3030
{
3131
$this->paginator = $paginator;
3232
}
@@ -44,15 +44,15 @@ public function getCurrentPage(): int
4444
*/
4545
public function getLastPage(): int
4646
{
47-
return $this->paginator->lastPage();
47+
return 0;
4848
}
4949

5050
/**
5151
* {@inheritDoc}
5252
*/
5353
public function getTotal(): int
5454
{
55-
return $this->paginator->total();
55+
return 0;
5656
}
5757

5858
/**
@@ -82,7 +82,7 @@ public function getUrl(int $page): string
8282
/**
8383
* Get the paginator instance.
8484
*/
85-
public function getPaginator(): LengthAwarePaginator
85+
public function getPaginator(): Paginator
8686
{
8787
return $this->paginator;
8888
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
namespace PHPOpenSourceSaver\Fractal\Test\Pagination;
4+
5+
use PHPOpenSourceSaver\Fractal\Pagination\IlluminateSimplePaginatorAdapter;
6+
use Mockery;
7+
use PHPUnit\Framework\TestCase;
8+
9+
class IlluminateSimplePaginatorAdapterTest extends TestCase
10+
{
11+
public function testPaginationAdapter()
12+
{
13+
$total = 0;
14+
$count = 10;
15+
$perPage = 10;
16+
$currentPage = 2;
17+
$lastPage = 0;
18+
$url = 'http://example.com/foo?page=1';
19+
20+
$paginator = Mockery::mock('Illuminate\Contracts\Pagination\Paginator');
21+
$paginator->shouldReceive('currentPage')->andReturn($currentPage);
22+
$paginator->shouldReceive('lastPage')->andReturn($lastPage);
23+
$paginator->shouldReceive('count')->andReturn($count);
24+
$paginator->shouldReceive('total')->andReturn($total);
25+
$paginator->shouldReceive('perPage')->andReturn($perPage);
26+
$paginator->shouldReceive('url')->with(1)->andReturn($url);
27+
28+
$adapter = new IlluminateSimplePaginatorAdapter($paginator);
29+
30+
$this->assertInstanceOf('PHPOpenSourceSaver\Fractal\Pagination\PaginatorInterface', $adapter);
31+
$this->assertInstanceOf('Illuminate\Contracts\Pagination\Paginator', $adapter->getPaginator());
32+
33+
$this->assertSame($currentPage, $adapter->getCurrentPage());
34+
$this->assertSame($lastPage, $adapter->getLastPage());
35+
$this->assertSame($count, $adapter->getCount());
36+
$this->assertSame($total, $adapter->getTotal());
37+
$this->assertSame($perPage, $adapter->getPerPage());
38+
$this->assertSame('http://example.com/foo?page=1', $adapter->getUrl(1));
39+
}
40+
41+
public function tearDown(): void
42+
{
43+
Mockery::close();
44+
}
45+
}

0 commit comments

Comments
 (0)