From 55ddc4ae75113ff06cde1d24c0590d4621851296 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sat, 23 Jan 2021 14:37:34 +0100 Subject: [PATCH 1/2] Replaced laminas-paginator with pagerfanta --- composer.json | 4 ++-- .../CLI/src/Command/ShortUrl/GetVisitsCommand.php | 2 +- .../src/Command/ShortUrl/ListShortUrlsCommand.php | 8 ++++---- .../test/Command/ShortUrl/GetVisitsCommandTest.php | 4 ++-- .../Command/ShortUrl/ListShortUrlsCommandTest.php | 14 +++++++------- .../AbstractCacheableCountPaginatorAdapter.php | 4 ++-- .../Adapter/ShortUrlRepositoryAdapter.php | 8 ++++---- .../Adapter/VisitsForTagPaginatorAdapter.php | 4 ++-- .../Paginator/Adapter/VisitsPaginatorAdapter.php | 4 ++-- module/Core/src/Service/ShortUrlService.php | 6 +++--- .../Core/src/Service/ShortUrlServiceInterface.php | 2 +- module/Core/src/Service/VisitsTracker.php | 10 +++++----- module/Core/src/Service/VisitsTrackerInterface.php | 2 +- .../Adapter/ShortUrlRepositoryAdapterTest.php | 4 ++-- .../Adapter/VisitsForTagPaginatorAdapterTest.php | 4 ++-- .../Adapter/VisitsPaginatorAdapterTest.php | 4 ++-- module/Core/test/Service/ShortUrlServiceTest.php | 6 ++++-- module/Core/test/Service/VisitsTrackerTest.php | 4 ++-- .../src/Action/ShortUrl/ListShortUrlsAction.php | 4 ++-- .../Rest/src/Action/Visit/ShortUrlVisitsAction.php | 4 ++-- module/Rest/src/Action/Visit/TagVisitsAction.php | 4 ++-- .../test-api/Action/ShortUrlVisitsActionTest.php | 4 ++-- .../Action/ShortUrl/ListShortUrlsActionTest.php | 6 +++--- .../test/Action/Visit/ShortUrlVisitsActionTest.php | 4 ++-- .../Rest/test/Action/Visit/TagVisitsActionTest.php | 4 ++-- 25 files changed, 63 insertions(+), 61 deletions(-) diff --git a/composer.json b/composer.json index f47cb296..af175a90 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,6 @@ "laminas/laminas-config-aggregator": "^1.1", "laminas/laminas-diactoros": "^2.1.3", "laminas/laminas-inputfilter": "^2.10", - "laminas/laminas-paginator": "^2.8", "laminas/laminas-servicemanager": "^3.6", "laminas/laminas-stdlib": "^3.2", "lcobucci/jwt": "^4.0", @@ -43,11 +42,12 @@ "monolog/monolog": "^2.0", "nikolaposa/monolog-factory": "^3.1", "ocramius/proxy-manager": "^2.11", + "pagerfanta/core": "^2.5", "php-middleware/request-id": "^4.1", "predis/predis": "^1.1", "pugx/shortid-php": "^0.7", "ramsey/uuid": "^3.9", - "shlinkio/shlink-common": "^3.4", + "shlinkio/shlink-common": "dev-main#cab9f39 as 3.5", "shlinkio/shlink-config": "^1.0", "shlinkio/shlink-event-dispatcher": "^2.0", "shlinkio/shlink-importer": "^2.1", diff --git a/module/CLI/src/Command/ShortUrl/GetVisitsCommand.php b/module/CLI/src/Command/ShortUrl/GetVisitsCommand.php index a0c2c91a..b58ea3ac 100644 --- a/module/CLI/src/Command/ShortUrl/GetVisitsCommand.php +++ b/module/CLI/src/Command/ShortUrl/GetVisitsCommand.php @@ -75,7 +75,7 @@ class GetVisitsCommand extends AbstractWithDateRangeCommand $paginator = $this->visitsTracker->info($identifier, new VisitsParams(new DateRange($startDate, $endDate))); - $rows = map($paginator->getCurrentItems(), function (Visit $visit) { + $rows = map($paginator->getCurrentPageResults(), function (Visit $visit) { $rowData = $visit->jsonSerialize(); $rowData['country'] = ($visit->getVisitLocation() ?? new UnknownVisitLocation())->getCountryName(); return select_keys($rowData, ['referer', 'date', 'userAgent', 'country']); diff --git a/module/CLI/src/Command/ShortUrl/ListShortUrlsCommand.php b/module/CLI/src/Command/ShortUrl/ListShortUrlsCommand.php index 38abbb4d..3f539e27 100644 --- a/module/CLI/src/Command/ShortUrl/ListShortUrlsCommand.php +++ b/module/CLI/src/Command/ShortUrl/ListShortUrlsCommand.php @@ -4,11 +4,11 @@ declare(strict_types=1); namespace Shlinkio\Shlink\CLI\Command\ShortUrl; -use Laminas\Paginator\Paginator; use Shlinkio\Shlink\CLI\Command\Util\AbstractWithDateRangeCommand; use Shlinkio\Shlink\CLI\Util\ExitCodes; use Shlinkio\Shlink\CLI\Util\ShlinkTable; -use Shlinkio\Shlink\Common\Paginator\Util\PaginatorUtilsTrait; +use Shlinkio\Shlink\Common\Paginator\Paginator; +use Shlinkio\Shlink\Common\Paginator\Util\PagerfantaUtilsTrait; use Shlinkio\Shlink\Core\Model\ShortUrlsOrdering; use Shlinkio\Shlink\Core\Model\ShortUrlsParams; use Shlinkio\Shlink\Core\Service\ShortUrlServiceInterface; @@ -29,7 +29,7 @@ use function sprintf; class ListShortUrlsCommand extends AbstractWithDateRangeCommand { - use PaginatorUtilsTrait; + use PagerfantaUtilsTrait; public const NAME = 'short-url:list'; private const COLUMNS_WHITELIST = [ @@ -132,7 +132,7 @@ class ListShortUrlsCommand extends AbstractWithDateRangeCommand $result = $this->renderPage($output, $showTags, ShortUrlsParams::fromRawData($data), $all); $page++; - $continue = ! $this->isLastPage($result) && $io->confirm( + $continue = $result->hasNextPage() && $io->confirm( sprintf('Continue with page %s?', $page), false, ); diff --git a/module/CLI/test/Command/ShortUrl/GetVisitsCommandTest.php b/module/CLI/test/Command/ShortUrl/GetVisitsCommandTest.php index 9239544e..50c1751f 100644 --- a/module/CLI/test/Command/ShortUrl/GetVisitsCommandTest.php +++ b/module/CLI/test/Command/ShortUrl/GetVisitsCommandTest.php @@ -5,13 +5,13 @@ declare(strict_types=1); namespace ShlinkioTest\Shlink\CLI\Command\ShortUrl; use Cake\Chronos\Chronos; -use Laminas\Paginator\Adapter\ArrayAdapter; -use Laminas\Paginator\Paginator; +use Pagerfanta\Adapter\ArrayAdapter; use PHPUnit\Framework\TestCase; use Prophecy\Argument; use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\Prophecy\ObjectProphecy; use Shlinkio\Shlink\CLI\Command\ShortUrl\GetVisitsCommand; +use Shlinkio\Shlink\Common\Paginator\Paginator; use Shlinkio\Shlink\Common\Util\DateRange; use Shlinkio\Shlink\Core\Entity\ShortUrl; use Shlinkio\Shlink\Core\Entity\Visit; diff --git a/module/CLI/test/Command/ShortUrl/ListShortUrlsCommandTest.php b/module/CLI/test/Command/ShortUrl/ListShortUrlsCommandTest.php index 918dc39a..aca72e06 100644 --- a/module/CLI/test/Command/ShortUrl/ListShortUrlsCommandTest.php +++ b/module/CLI/test/Command/ShortUrl/ListShortUrlsCommandTest.php @@ -5,13 +5,13 @@ declare(strict_types=1); namespace ShlinkioTest\Shlink\CLI\Command\ShortUrl; use Cake\Chronos\Chronos; -use Laminas\Paginator\Adapter\ArrayAdapter; -use Laminas\Paginator\Paginator; +use Pagerfanta\Adapter\ArrayAdapter; use PHPUnit\Framework\TestCase; use Prophecy\Argument; use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\Prophecy\ObjectProphecy; use Shlinkio\Shlink\CLI\Command\ShortUrl\ListShortUrlsCommand; +use Shlinkio\Shlink\Common\Paginator\Paginator; use Shlinkio\Shlink\Core\Entity\ShortUrl; use Shlinkio\Shlink\Core\Model\ShortUrlsParams; use Shlinkio\Shlink\Core\Service\ShortUrlServiceInterface; @@ -89,7 +89,7 @@ class ListShortUrlsCommandTest extends TestCase { $page = 5; $this->shortUrlService->listShortUrls(ShortUrlsParams::fromRawData(['page' => $page])) - ->willReturn(new Paginator(new ArrayAdapter())) + ->willReturn(new Paginator(new ArrayAdapter([]))) ->shouldBeCalledOnce(); $this->commandTester->setInputs(['y']); @@ -100,7 +100,7 @@ class ListShortUrlsCommandTest extends TestCase public function ifTagsFlagIsProvidedTagsColumnIsIncluded(): void { $this->shortUrlService->listShortUrls(ShortUrlsParams::emptyInstance()) - ->willReturn(new Paginator(new ArrayAdapter())) + ->willReturn(new Paginator(new ArrayAdapter([]))) ->shouldBeCalledOnce(); $this->commandTester->setInputs(['y']); @@ -127,7 +127,7 @@ class ListShortUrlsCommandTest extends TestCase 'tags' => $tags, 'startDate' => $startDate !== null ? Chronos::parse($startDate)->toAtomString() : null, 'endDate' => $endDate !== null ? Chronos::parse($endDate)->toAtomString() : null, - ]))->willReturn(new Paginator(new ArrayAdapter())); + ]))->willReturn(new Paginator(new ArrayAdapter([]))); $this->commandTester->setInputs(['n']); $this->commandTester->execute($commandArgs); @@ -180,7 +180,7 @@ class ListShortUrlsCommandTest extends TestCase { $listShortUrls = $this->shortUrlService->listShortUrls(ShortUrlsParams::fromRawData([ 'orderBy' => $expectedOrderBy, - ]))->willReturn(new Paginator(new ArrayAdapter())); + ]))->willReturn(new Paginator(new ArrayAdapter([]))); $this->commandTester->setInputs(['n']); $this->commandTester->execute($commandArgs); @@ -207,7 +207,7 @@ class ListShortUrlsCommandTest extends TestCase 'endDate' => null, 'orderBy' => null, 'itemsPerPage' => -1, - ]))->willReturn(new Paginator(new ArrayAdapter())); + ]))->willReturn(new Paginator(new ArrayAdapter([]))); $this->commandTester->execute(['--all' => true]); diff --git a/module/Core/src/Paginator/Adapter/AbstractCacheableCountPaginatorAdapter.php b/module/Core/src/Paginator/Adapter/AbstractCacheableCountPaginatorAdapter.php index cc2a8287..217d5eff 100644 --- a/module/Core/src/Paginator/Adapter/AbstractCacheableCountPaginatorAdapter.php +++ b/module/Core/src/Paginator/Adapter/AbstractCacheableCountPaginatorAdapter.php @@ -4,13 +4,13 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Core\Paginator\Adapter; -use Laminas\Paginator\Adapter\AdapterInterface; +use Pagerfanta\Adapter\AdapterInterface; abstract class AbstractCacheableCountPaginatorAdapter implements AdapterInterface { private ?int $count = null; - final public function count(): int + final public function getNbResults(): int { // Since a new adapter instance is created every time visits are fetched, it is reasonably safe to internally // cache the count value. diff --git a/module/Core/src/Paginator/Adapter/ShortUrlRepositoryAdapter.php b/module/Core/src/Paginator/Adapter/ShortUrlRepositoryAdapter.php index 93fd88c7..093bd8fd 100644 --- a/module/Core/src/Paginator/Adapter/ShortUrlRepositoryAdapter.php +++ b/module/Core/src/Paginator/Adapter/ShortUrlRepositoryAdapter.php @@ -5,7 +5,7 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Core\Paginator\Adapter; use Happyr\DoctrineSpecification\Specification\Specification; -use Laminas\Paginator\Adapter\AdapterInterface; +use Pagerfanta\Adapter\AdapterInterface; use Shlinkio\Shlink\Core\Model\ShortUrlsParams; use Shlinkio\Shlink\Core\Repository\ShortUrlRepositoryInterface; use Shlinkio\Shlink\Rest\Entity\ApiKey; @@ -23,10 +23,10 @@ class ShortUrlRepositoryAdapter implements AdapterInterface $this->apiKey = $apiKey; } - public function getItems($offset, $itemCountPerPage): array // phpcs:ignore + public function getSlice($offset, $length): array // phpcs:ignore { return $this->repository->findList( - $itemCountPerPage, + $length, $offset, $this->params->searchTerm(), $this->params->tags(), @@ -36,7 +36,7 @@ class ShortUrlRepositoryAdapter implements AdapterInterface ); } - public function count(): int + public function getNbResults(): int { return $this->repository->countList( $this->params->searchTerm(), diff --git a/module/Core/src/Paginator/Adapter/VisitsForTagPaginatorAdapter.php b/module/Core/src/Paginator/Adapter/VisitsForTagPaginatorAdapter.php index 3b73509a..4c4e718b 100644 --- a/module/Core/src/Paginator/Adapter/VisitsForTagPaginatorAdapter.php +++ b/module/Core/src/Paginator/Adapter/VisitsForTagPaginatorAdapter.php @@ -28,12 +28,12 @@ class VisitsForTagPaginatorAdapter extends AbstractCacheableCountPaginatorAdapte $this->apiKey = $apiKey; } - public function getItems($offset, $itemCountPerPage): array // phpcs:ignore + public function getSlice($offset, $length): array // phpcs:ignore { return $this->visitRepository->findVisitsByTag( $this->tag, $this->params->getDateRange(), - $itemCountPerPage, + $length, $offset, $this->resolveSpec(), ); diff --git a/module/Core/src/Paginator/Adapter/VisitsPaginatorAdapter.php b/module/Core/src/Paginator/Adapter/VisitsPaginatorAdapter.php index 29498a6d..02ba37b3 100644 --- a/module/Core/src/Paginator/Adapter/VisitsPaginatorAdapter.php +++ b/module/Core/src/Paginator/Adapter/VisitsPaginatorAdapter.php @@ -28,13 +28,13 @@ class VisitsPaginatorAdapter extends AbstractCacheableCountPaginatorAdapter $this->spec = $spec; } - public function getItems($offset, $itemCountPerPage): array // phpcs:ignore + public function getSlice($offset, $length): array // phpcs:ignore { return $this->visitRepository->findVisitsByShortCode( $this->identifier->shortCode(), $this->identifier->domain(), $this->params->getDateRange(), - $itemCountPerPage, + $length, $offset, $this->spec, ); diff --git a/module/Core/src/Service/ShortUrlService.php b/module/Core/src/Service/ShortUrlService.php index 06b39f08..aeb5233b 100644 --- a/module/Core/src/Service/ShortUrlService.php +++ b/module/Core/src/Service/ShortUrlService.php @@ -5,7 +5,7 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Core\Service; use Doctrine\ORM; -use Laminas\Paginator\Paginator; +use Shlinkio\Shlink\Common\Paginator\Paginator; use Shlinkio\Shlink\Core\Entity\ShortUrl; use Shlinkio\Shlink\Core\Exception\InvalidUrlException; use Shlinkio\Shlink\Core\Exception\ShortUrlNotFoundException; @@ -45,8 +45,8 @@ class ShortUrlService implements ShortUrlServiceInterface /** @var ShortUrlRepository $repo */ $repo = $this->em->getRepository(ShortUrl::class); $paginator = new Paginator(new ShortUrlRepositoryAdapter($repo, $params, $apiKey)); - $paginator->setItemCountPerPage($params->itemsPerPage()) - ->setCurrentPageNumber($params->page()); + $paginator->setMaxPerPage($params->itemsPerPage()) + ->setCurrentPage($params->page()); return $paginator; } diff --git a/module/Core/src/Service/ShortUrlServiceInterface.php b/module/Core/src/Service/ShortUrlServiceInterface.php index 5f6b9b30..b1cfbc2d 100644 --- a/module/Core/src/Service/ShortUrlServiceInterface.php +++ b/module/Core/src/Service/ShortUrlServiceInterface.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Core\Service; -use Laminas\Paginator\Paginator; +use Shlinkio\Shlink\Common\Paginator\Paginator; use Shlinkio\Shlink\Core\Entity\ShortUrl; use Shlinkio\Shlink\Core\Exception\InvalidUrlException; use Shlinkio\Shlink\Core\Exception\ShortUrlNotFoundException; diff --git a/module/Core/src/Service/VisitsTracker.php b/module/Core/src/Service/VisitsTracker.php index 46d4bd6b..a8362f7c 100644 --- a/module/Core/src/Service/VisitsTracker.php +++ b/module/Core/src/Service/VisitsTracker.php @@ -5,8 +5,8 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Core\Service; use Doctrine\ORM; -use Laminas\Paginator\Paginator; use Psr\EventDispatcher\EventDispatcherInterface; +use Shlinkio\Shlink\Common\Paginator\Paginator; use Shlinkio\Shlink\Core\Entity\ShortUrl; use Shlinkio\Shlink\Core\Entity\Tag; use Shlinkio\Shlink\Core\Entity\Visit; @@ -66,8 +66,8 @@ class VisitsTracker implements VisitsTrackerInterface /** @var VisitRepositoryInterface $repo */ $repo = $this->em->getRepository(Visit::class); $paginator = new Paginator(new VisitsPaginatorAdapter($repo, $identifier, $params, $spec)); - $paginator->setItemCountPerPage($params->getItemsPerPage()) - ->setCurrentPageNumber($params->getPage()); + $paginator->setMaxPerPage($params->getItemsPerPage()) + ->setCurrentPage($params->getPage()); return $paginator; } @@ -87,8 +87,8 @@ class VisitsTracker implements VisitsTrackerInterface /** @var VisitRepositoryInterface $repo */ $repo = $this->em->getRepository(Visit::class); $paginator = new Paginator(new VisitsForTagPaginatorAdapter($repo, $tag, $params, $apiKey)); - $paginator->setItemCountPerPage($params->getItemsPerPage()) - ->setCurrentPageNumber($params->getPage()); + $paginator->setMaxPerPage($params->getItemsPerPage()) + ->setCurrentPage($params->getPage()); return $paginator; } diff --git a/module/Core/src/Service/VisitsTrackerInterface.php b/module/Core/src/Service/VisitsTrackerInterface.php index ecffae23..0814d986 100644 --- a/module/Core/src/Service/VisitsTrackerInterface.php +++ b/module/Core/src/Service/VisitsTrackerInterface.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Core\Service; -use Laminas\Paginator\Paginator; +use Shlinkio\Shlink\Common\Paginator\Paginator; use Shlinkio\Shlink\Core\Entity\ShortUrl; use Shlinkio\Shlink\Core\Entity\Visit; use Shlinkio\Shlink\Core\Exception\ShortUrlNotFoundException; diff --git a/module/Core/test/Paginator/Adapter/ShortUrlRepositoryAdapterTest.php b/module/Core/test/Paginator/Adapter/ShortUrlRepositoryAdapterTest.php index c3848aa5..93aba122 100644 --- a/module/Core/test/Paginator/Adapter/ShortUrlRepositoryAdapterTest.php +++ b/module/Core/test/Paginator/Adapter/ShortUrlRepositoryAdapterTest.php @@ -47,7 +47,7 @@ class ShortUrlRepositoryAdapterTest extends TestCase $dateRange = $params->dateRange(); $this->repo->findList(10, 5, $searchTerm, $tags, $orderBy, $dateRange, null)->shouldBeCalledOnce(); - $adapter->getItems(5, 10); + $adapter->getSlice(5, 10); } /** @@ -71,7 +71,7 @@ class ShortUrlRepositoryAdapterTest extends TestCase $dateRange = $params->dateRange(); $this->repo->countList($searchTerm, $tags, $dateRange, $apiKey->spec())->shouldBeCalledOnce(); - $adapter->count(); + $adapter->getNbResults(); } public function provideFilteringArgs(): iterable diff --git a/module/Core/test/Paginator/Adapter/VisitsForTagPaginatorAdapterTest.php b/module/Core/test/Paginator/Adapter/VisitsForTagPaginatorAdapterTest.php index a0bc6405..8dc88495 100644 --- a/module/Core/test/Paginator/Adapter/VisitsForTagPaginatorAdapterTest.php +++ b/module/Core/test/Paginator/Adapter/VisitsForTagPaginatorAdapterTest.php @@ -34,7 +34,7 @@ class VisitsForTagPaginatorAdapterTest extends TestCase $findVisits = $this->repo->findVisitsByTag('foo', new DateRange(), $limit, $offset, null)->willReturn([]); for ($i = 0; $i < $count; $i++) { - $adapter->getItems($offset, $limit); + $adapter->getSlice($offset, $limit); } $findVisits->shouldHaveBeenCalledTimes($count); @@ -49,7 +49,7 @@ class VisitsForTagPaginatorAdapterTest extends TestCase $countVisits = $this->repo->countVisitsByTag('foo', new DateRange(), $apiKey->spec())->willReturn(3); for ($i = 0; $i < $count; $i++) { - $adapter->count(); + $adapter->getNbResults(); } $countVisits->shouldHaveBeenCalledOnce(); diff --git a/module/Core/test/Paginator/Adapter/VisitsPaginatorAdapterTest.php b/module/Core/test/Paginator/Adapter/VisitsPaginatorAdapterTest.php index 76ccc220..436b4b7d 100644 --- a/module/Core/test/Paginator/Adapter/VisitsPaginatorAdapterTest.php +++ b/module/Core/test/Paginator/Adapter/VisitsPaginatorAdapterTest.php @@ -37,7 +37,7 @@ class VisitsPaginatorAdapterTest extends TestCase ); for ($i = 0; $i < $count; $i++) { - $adapter->getItems($offset, $limit); + $adapter->getSlice($offset, $limit); } $findVisits->shouldHaveBeenCalledTimes($count); @@ -52,7 +52,7 @@ class VisitsPaginatorAdapterTest extends TestCase $countVisits = $this->repo->countVisitsByShortCode('', null, new DateRange(), $apiKey->spec())->willReturn(3); for ($i = 0; $i < $count; $i++) { - $adapter->count(); + $adapter->getNbResults(); } $countVisits->shouldHaveBeenCalledOnce(); diff --git a/module/Core/test/Service/ShortUrlServiceTest.php b/module/Core/test/Service/ShortUrlServiceTest.php index 99f26a53..5ced9b1a 100644 --- a/module/Core/test/Service/ShortUrlServiceTest.php +++ b/module/Core/test/Service/ShortUrlServiceTest.php @@ -69,8 +69,10 @@ class ShortUrlServiceTest extends TestCase $repo->countList(Argument::cetera())->willReturn(count($list))->shouldBeCalledOnce(); $this->em->getRepository(ShortUrl::class)->willReturn($repo->reveal()); - $list = $this->service->listShortUrls(ShortUrlsParams::emptyInstance(), $apiKey); - self::assertEquals(4, $list->getCurrentItemCount()); + $paginator = $this->service->listShortUrls(ShortUrlsParams::emptyInstance(), $apiKey); + + self::assertCount(4, $paginator); + self::assertCount(4, $paginator->getCurrentPageResults()); } /** diff --git a/module/Core/test/Service/VisitsTrackerTest.php b/module/Core/test/Service/VisitsTrackerTest.php index 17135f57..1efe61df 100644 --- a/module/Core/test/Service/VisitsTrackerTest.php +++ b/module/Core/test/Service/VisitsTrackerTest.php @@ -83,7 +83,7 @@ class VisitsTrackerTest extends TestCase $paginator = $this->visitsTracker->info(new ShortUrlIdentifier($shortCode), new VisitsParams(), $apiKey); - self::assertEquals($list, ArrayUtils::iteratorToArray($paginator->getCurrentItems())); + self::assertEquals($list, ArrayUtils::iteratorToArray($paginator->getCurrentPageResults())); $count->shouldHaveBeenCalledOnce(); } @@ -137,7 +137,7 @@ class VisitsTrackerTest extends TestCase $paginator = $this->visitsTracker->visitsForTag($tag, new VisitsParams(), $apiKey); - self::assertEquals($list, ArrayUtils::iteratorToArray($paginator->getCurrentItems())); + self::assertEquals($list, ArrayUtils::iteratorToArray($paginator->getCurrentPageResults())); $tagExists->shouldHaveBeenCalledOnce(); $getRepo->shouldHaveBeenCalledOnce(); } diff --git a/module/Rest/src/Action/ShortUrl/ListShortUrlsAction.php b/module/Rest/src/Action/ShortUrl/ListShortUrlsAction.php index 35273dcc..8da502cf 100644 --- a/module/Rest/src/Action/ShortUrl/ListShortUrlsAction.php +++ b/module/Rest/src/Action/ShortUrl/ListShortUrlsAction.php @@ -7,7 +7,7 @@ namespace Shlinkio\Shlink\Rest\Action\ShortUrl; use Laminas\Diactoros\Response\JsonResponse; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; -use Shlinkio\Shlink\Common\Paginator\Util\PaginatorUtilsTrait; +use Shlinkio\Shlink\Common\Paginator\Util\PagerfantaUtilsTrait; use Shlinkio\Shlink\Core\Model\ShortUrlsParams; use Shlinkio\Shlink\Core\Service\ShortUrlServiceInterface; use Shlinkio\Shlink\Core\Transformer\ShortUrlDataTransformer; @@ -16,7 +16,7 @@ use Shlinkio\Shlink\Rest\Middleware\AuthenticationMiddleware; class ListShortUrlsAction extends AbstractRestAction { - use PaginatorUtilsTrait; + use PagerfantaUtilsTrait; protected const ROUTE_PATH = '/short-urls'; protected const ROUTE_ALLOWED_METHODS = [self::METHOD_GET]; diff --git a/module/Rest/src/Action/Visit/ShortUrlVisitsAction.php b/module/Rest/src/Action/Visit/ShortUrlVisitsAction.php index 4a9a95e9..7b7c1055 100644 --- a/module/Rest/src/Action/Visit/ShortUrlVisitsAction.php +++ b/module/Rest/src/Action/Visit/ShortUrlVisitsAction.php @@ -7,7 +7,7 @@ namespace Shlinkio\Shlink\Rest\Action\Visit; use Laminas\Diactoros\Response\JsonResponse; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; -use Shlinkio\Shlink\Common\Paginator\Util\PaginatorUtilsTrait; +use Shlinkio\Shlink\Common\Paginator\Util\PagerfantaUtilsTrait; use Shlinkio\Shlink\Core\Model\ShortUrlIdentifier; use Shlinkio\Shlink\Core\Model\VisitsParams; use Shlinkio\Shlink\Core\Service\VisitsTrackerInterface; @@ -16,7 +16,7 @@ use Shlinkio\Shlink\Rest\Middleware\AuthenticationMiddleware; class ShortUrlVisitsAction extends AbstractRestAction { - use PaginatorUtilsTrait; + use PagerfantaUtilsTrait; protected const ROUTE_PATH = '/short-urls/{shortCode}/visits'; protected const ROUTE_ALLOWED_METHODS = [self::METHOD_GET]; diff --git a/module/Rest/src/Action/Visit/TagVisitsAction.php b/module/Rest/src/Action/Visit/TagVisitsAction.php index c83ee95c..aec42ebb 100644 --- a/module/Rest/src/Action/Visit/TagVisitsAction.php +++ b/module/Rest/src/Action/Visit/TagVisitsAction.php @@ -7,7 +7,7 @@ namespace Shlinkio\Shlink\Rest\Action\Visit; use Laminas\Diactoros\Response\JsonResponse; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; -use Shlinkio\Shlink\Common\Paginator\Util\PaginatorUtilsTrait; +use Shlinkio\Shlink\Common\Paginator\Util\PagerfantaUtilsTrait; use Shlinkio\Shlink\Core\Model\VisitsParams; use Shlinkio\Shlink\Core\Service\VisitsTrackerInterface; use Shlinkio\Shlink\Rest\Action\AbstractRestAction; @@ -15,7 +15,7 @@ use Shlinkio\Shlink\Rest\Middleware\AuthenticationMiddleware; class TagVisitsAction extends AbstractRestAction { - use PaginatorUtilsTrait; + use PagerfantaUtilsTrait; protected const ROUTE_PATH = '/tags/{tag}/visits'; protected const ROUTE_ALLOWED_METHODS = [self::METHOD_GET]; diff --git a/module/Rest/test-api/Action/ShortUrlVisitsActionTest.php b/module/Rest/test-api/Action/ShortUrlVisitsActionTest.php index 22864108..a9bdca71 100644 --- a/module/Rest/test-api/Action/ShortUrlVisitsActionTest.php +++ b/module/Rest/test-api/Action/ShortUrlVisitsActionTest.php @@ -4,11 +4,11 @@ declare(strict_types=1); namespace ShlinkioApiTest\Shlink\Rest\Action; +use GuzzleHttp\Psr7\Query; use Laminas\Diactoros\Uri; use Shlinkio\Shlink\TestUtils\ApiTest\ApiTestCase; use ShlinkioApiTest\Shlink\Rest\Utils\NotFoundUrlHelpersTrait; -use function GuzzleHttp\Psr7\build_query; use function sprintf; class ShortUrlVisitsActionTest extends ApiTestCase @@ -52,7 +52,7 @@ class ShortUrlVisitsActionTest extends ApiTestCase $url = new Uri(sprintf('/short-urls/%s/visits', $shortCode)); if ($domain !== null) { - $url = $url->withQuery(build_query(['domain' => $domain])); + $url = $url->withQuery(Query::build(['domain' => $domain])); } $resp = $this->callApiWithKey(self::METHOD_GET, (string) $url); diff --git a/module/Rest/test/Action/ShortUrl/ListShortUrlsActionTest.php b/module/Rest/test/Action/ShortUrl/ListShortUrlsActionTest.php index 7c4d47f7..fd51fa16 100644 --- a/module/Rest/test/Action/ShortUrl/ListShortUrlsActionTest.php +++ b/module/Rest/test/Action/ShortUrl/ListShortUrlsActionTest.php @@ -7,11 +7,11 @@ namespace ShlinkioTest\Shlink\Rest\Action\ShortUrl; use Cake\Chronos\Chronos; use Laminas\Diactoros\Response\JsonResponse; use Laminas\Diactoros\ServerRequest; -use Laminas\Paginator\Adapter\ArrayAdapter; -use Laminas\Paginator\Paginator; +use Pagerfanta\Adapter\ArrayAdapter; use PHPUnit\Framework\TestCase; use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\Prophecy\ObjectProphecy; +use Shlinkio\Shlink\Common\Paginator\Paginator; use Shlinkio\Shlink\Core\Model\ShortUrlsParams; use Shlinkio\Shlink\Core\Service\ShortUrlService; use Shlinkio\Shlink\Rest\Action\ShortUrl\ListShortUrlsAction; @@ -56,7 +56,7 @@ class ListShortUrlsActionTest extends TestCase 'orderBy' => $expectedOrderBy, 'startDate' => $startDate, 'endDate' => $endDate, - ]), $apiKey)->willReturn(new Paginator(new ArrayAdapter())); + ]), $apiKey)->willReturn(new Paginator(new ArrayAdapter([]))); /** @var JsonResponse $response */ $response = $this->action->handle($request); diff --git a/module/Rest/test/Action/Visit/ShortUrlVisitsActionTest.php b/module/Rest/test/Action/Visit/ShortUrlVisitsActionTest.php index 0bedbd37..9c751214 100644 --- a/module/Rest/test/Action/Visit/ShortUrlVisitsActionTest.php +++ b/module/Rest/test/Action/Visit/ShortUrlVisitsActionTest.php @@ -6,13 +6,13 @@ namespace ShlinkioTest\Shlink\Rest\Action\Visit; use Cake\Chronos\Chronos; use Laminas\Diactoros\ServerRequestFactory; -use Laminas\Paginator\Adapter\ArrayAdapter; -use Laminas\Paginator\Paginator; +use Pagerfanta\Adapter\ArrayAdapter; use PHPUnit\Framework\TestCase; use Prophecy\Argument; use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\Prophecy\ObjectProphecy; use Psr\Http\Message\ServerRequestInterface; +use Shlinkio\Shlink\Common\Paginator\Paginator; use Shlinkio\Shlink\Common\Util\DateRange; use Shlinkio\Shlink\Core\Model\ShortUrlIdentifier; use Shlinkio\Shlink\Core\Model\VisitsParams; diff --git a/module/Rest/test/Action/Visit/TagVisitsActionTest.php b/module/Rest/test/Action/Visit/TagVisitsActionTest.php index a7598971..c9097d07 100644 --- a/module/Rest/test/Action/Visit/TagVisitsActionTest.php +++ b/module/Rest/test/Action/Visit/TagVisitsActionTest.php @@ -5,12 +5,12 @@ declare(strict_types=1); namespace ShlinkioTest\Shlink\Rest\Action\Visit; use Laminas\Diactoros\ServerRequest; -use Laminas\Paginator\Adapter\ArrayAdapter; -use Laminas\Paginator\Paginator; +use Pagerfanta\Adapter\ArrayAdapter; use PHPUnit\Framework\TestCase; use Prophecy\Argument; use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\Prophecy\ObjectProphecy; +use Shlinkio\Shlink\Common\Paginator\Paginator; use Shlinkio\Shlink\Core\Model\VisitsParams; use Shlinkio\Shlink\Core\Service\VisitsTracker; use Shlinkio\Shlink\Rest\Action\Visit\TagVisitsAction; From 83a29d6ed0b5c834a62f54416af1f5cefe04d2b7 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sat, 23 Jan 2021 14:38:58 +0100 Subject: [PATCH 2/2] Updated changelog --- CHANGELOG.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d940e7d..84af470c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,23 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com), and this project adheres to [Semantic Versioning](https://semver.org). +## [Unreleased] +### Added +* *Nothing* + +### Changed +* [#977](https://github.com/shlinkio/shlink/issues/977) Migrated from `laminas/laminas-paginator` to `pagerfanta/core` to handle pagination. + +### Deprecated +* *Nothing* + +### Removed +* *Nothing* + +### Fixed +* *Nothing* + + ## [2.5.1] - 2021-01-21 ### Added * *Nothing*