-
-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unlike the NullAdapter, this adapter is always empty instead of allowing it to paginate an array of null values. Thanks to that, its generic type can fullfil types like `AdapterInterface<Foo>` with a non-nullable `Foo` type.
- Loading branch information
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Pagerfanta\Adapter; | ||
|
||
/** | ||
* An adapter that is always empty. | ||
* | ||
* @template-implements AdapterInterface<never> | ||
*/ | ||
class EmptyAdapter implements AdapterInterface | ||
{ | ||
public function getNbResults(): int | ||
{ | ||
return 0; | ||
} | ||
|
||
public function getSlice(int $offset, int $length): iterable | ||
{ | ||
return []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Adapter; | ||
|
||
use Pagerfanta\Adapter\EmptyAdapter; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class EmptyAdapterTest extends TestCase | ||
{ | ||
public function testGetNbResults(): void | ||
{ | ||
$adapter = new EmptyAdapter(); | ||
|
||
self::assertSame(0, $adapter->getNbResults()); | ||
} | ||
|
||
public function testGetSliceShouldReturnAnEmptyArray(): void | ||
{ | ||
$adapter = new EmptyAdapter(); | ||
|
||
self::assertSame([], $adapter->getSlice(10, 5)); | ||
} | ||
} |