From 7acf27dd38dc6125922616547082486578f72d2d Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Thu, 4 Aug 2022 11:27:33 +0200 Subject: [PATCH] Replaced usage of deprecated methods in DateRange class --- config/autoload/routes.config.php | 12 ++-- .../ShortUrl/GetShortUrlVisitsCommandTest.php | 4 +- module/Core/src/Model/VisitsParams.php | 2 +- .../Repository/ShortUrlRepositoryTest.php | 8 +-- .../Repository/VisitRepositoryTest.php | 68 +++++++++---------- .../ShortUrlVisitsPaginatorAdapterTest.php | 4 +- .../VisitsForTagPaginatorAdapterTest.php | 4 +- .../Action/Visit/ShortUrlVisitsActionTest.php | 2 +- 8 files changed, 53 insertions(+), 51 deletions(-) diff --git a/config/autoload/routes.config.php b/config/autoload/routes.config.php index 38b4edc7..f7c515fb 100644 --- a/config/autoload/routes.config.php +++ b/config/autoload/routes.config.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace Shlinkio\Shlink; -use Fig\Http\Message\RequestMethodInterface as RequestMethod; +use Fig\Http\Message\RequestMethodInterface; use RKA\Middleware\IpAddress; use Shlinkio\Shlink\Core\Action as CoreAction; use Shlinkio\Shlink\Rest\Action; @@ -12,6 +12,7 @@ use Shlinkio\Shlink\Rest\ConfigProvider; use Shlinkio\Shlink\Rest\Middleware; use Shlinkio\Shlink\Rest\Middleware\Mercure\NotConfiguredMercureErrorHandler; +// The order of the routes defined here matters. Changing it might cause path conflicts return (static function (): array { $contentNegotiationMiddleware = Middleware\ShortUrl\CreateShortUrlContentNegotiationMiddleware::class; $dropDomainMiddleware = Middleware\ShortUrl\DropDefaultDomainFromRequestMiddleware::class; @@ -20,6 +21,7 @@ return (static function (): array { return [ 'routes' => [ + // Rest ...ConfigProvider::applyRoutesPrefix([ Action\HealthAction::getRouteDef(), @@ -67,7 +69,7 @@ return (static function (): array { 'middleware' => [ CoreAction\RobotsAction::class, ], - 'allowed_methods' => [RequestMethod::METHOD_GET], + 'allowed_methods' => [RequestMethodInterface::METHOD_GET], ], [ 'name' => CoreAction\PixelAction::class, @@ -76,7 +78,7 @@ return (static function (): array { IpAddress::class, CoreAction\PixelAction::class, ], - 'allowed_methods' => [RequestMethod::METHOD_GET], + 'allowed_methods' => [RequestMethodInterface::METHOD_GET], ], [ 'name' => CoreAction\QrCodeAction::class, @@ -84,7 +86,7 @@ return (static function (): array { 'middleware' => [ CoreAction\QrCodeAction::class, ], - 'allowed_methods' => [RequestMethod::METHOD_GET], + 'allowed_methods' => [RequestMethodInterface::METHOD_GET], ], [ 'name' => CoreAction\RedirectAction::class, @@ -93,7 +95,7 @@ return (static function (): array { IpAddress::class, CoreAction\RedirectAction::class, ], - 'allowed_methods' => [RequestMethod::METHOD_GET], + 'allowed_methods' => [RequestMethodInterface::METHOD_GET], ], ], diff --git a/module/CLI/test/Command/ShortUrl/GetShortUrlVisitsCommandTest.php b/module/CLI/test/Command/ShortUrl/GetShortUrlVisitsCommandTest.php index 076eb9b2..316c762e 100644 --- a/module/CLI/test/Command/ShortUrl/GetShortUrlVisitsCommandTest.php +++ b/module/CLI/test/Command/ShortUrl/GetShortUrlVisitsCommandTest.php @@ -46,7 +46,7 @@ class GetShortUrlVisitsCommandTest extends TestCase $shortCode = 'abc123'; $this->visitsHelper->visitsForShortUrl( ShortUrlIdentifier::fromShortCodeAndDomain($shortCode), - new VisitsParams(DateRange::emptyInstance()), + new VisitsParams(DateRange::allTime()), ) ->willReturn(new Paginator(new ArrayAdapter([]))) ->shouldBeCalledOnce(); @@ -81,7 +81,7 @@ class GetShortUrlVisitsCommandTest extends TestCase $startDate = 'foo'; $info = $this->visitsHelper->visitsForShortUrl( ShortUrlIdentifier::fromShortCodeAndDomain($shortCode), - new VisitsParams(DateRange::emptyInstance()), + new VisitsParams(DateRange::allTime()), )->willReturn(new Paginator(new ArrayAdapter([]))); $this->commandTester->execute([ diff --git a/module/Core/src/Model/VisitsParams.php b/module/Core/src/Model/VisitsParams.php index ab9e8002..dfc4663d 100644 --- a/module/Core/src/Model/VisitsParams.php +++ b/module/Core/src/Model/VisitsParams.php @@ -19,7 +19,7 @@ final class VisitsParams extends AbstractInfinitePaginableListParams public readonly bool $excludeBots = false, ) { parent::__construct($page, $itemsPerPage); - $this->dateRange = $dateRange ?? DateRange::emptyInstance(); + $this->dateRange = $dateRange ?? DateRange::allTime(); } public static function fromRawData(array $query): self diff --git a/module/Core/test-db/Repository/ShortUrlRepositoryTest.php b/module/Core/test-db/Repository/ShortUrlRepositoryTest.php index bfa38169..3143e90c 100644 --- a/module/Core/test-db/Repository/ShortUrlRepositoryTest.php +++ b/module/Core/test-db/Repository/ShortUrlRepositoryTest.php @@ -152,23 +152,23 @@ class ShortUrlRepositoryTest extends DatabaseTestCase self::assertSame($bar, $result[0]); $result = $this->repo->findList( - new ShortUrlsListFiltering(null, null, Ordering::emptyInstance(), null, [], null, DateRange::withEndDate( + new ShortUrlsListFiltering(null, null, Ordering::emptyInstance(), null, [], null, DateRange::until( Chronos::now()->subDays(2), )), ); self::assertCount(1, $result); - self::assertEquals(1, $this->repo->countList(new ShortUrlsCountFiltering(null, [], null, DateRange::withEndDate( + self::assertEquals(1, $this->repo->countList(new ShortUrlsCountFiltering(null, [], null, DateRange::until( Chronos::now()->subDays(2), )))); self::assertSame($foo2, $result[0]); self::assertCount(2, $this->repo->findList( - new ShortUrlsListFiltering(null, null, Ordering::emptyInstance(), null, [], null, DateRange::withStartDate( + new ShortUrlsListFiltering(null, null, Ordering::emptyInstance(), null, [], null, DateRange::since( Chronos::now()->subDays(2), )), )); self::assertEquals(2, $this->repo->countList( - new ShortUrlsCountFiltering(null, [], null, DateRange::withStartDate(Chronos::now()->subDays(2))), + new ShortUrlsCountFiltering(null, [], null, DateRange::since(Chronos::now()->subDays(2))), )); } diff --git a/module/Core/test-db/Repository/VisitRepositoryTest.php b/module/Core/test-db/Repository/VisitRepositoryTest.php index b16c3382..041f5e4c 100644 --- a/module/Core/test-db/Repository/VisitRepositoryTest.php +++ b/module/Core/test-db/Repository/VisitRepositoryTest.php @@ -114,16 +114,16 @@ class VisitRepositoryTest extends DatabaseTestCase self::assertCount(2, $this->repo->findVisitsByShortCode( ShortUrlIdentifier::fromShortCodeAndDomain($shortCode), new VisitsListFiltering( - DateRange::withStartAndEndDate(Chronos::parse('2016-01-02'), Chronos::parse('2016-01-03')), + DateRange::between(Chronos::parse('2016-01-02'), Chronos::parse('2016-01-03')), ), )); self::assertCount(4, $this->repo->findVisitsByShortCode( ShortUrlIdentifier::fromShortCodeAndDomain($shortCode), - new VisitsListFiltering(DateRange::withStartDate(Chronos::parse('2016-01-03'))), + new VisitsListFiltering(DateRange::since(Chronos::parse('2016-01-03'))), )); self::assertCount(1, $this->repo->findVisitsByShortCode( ShortUrlIdentifier::fromShortCodeAndDomain($shortCode, $domain), - new VisitsListFiltering(DateRange::withStartDate(Chronos::parse('2016-01-03'))), + new VisitsListFiltering(DateRange::since(Chronos::parse('2016-01-03'))), )); self::assertCount(3, $this->repo->findVisitsByShortCode( ShortUrlIdentifier::fromShortCodeAndDomain($shortCode), @@ -163,16 +163,16 @@ class VisitRepositoryTest extends DatabaseTestCase self::assertEquals(2, $this->repo->countVisitsByShortCode( ShortUrlIdentifier::fromShortCodeAndDomain($shortCode), new VisitsCountFiltering( - DateRange::withStartAndEndDate(Chronos::parse('2016-01-02'), Chronos::parse('2016-01-03')), + DateRange::between(Chronos::parse('2016-01-02'), Chronos::parse('2016-01-03')), ), )); self::assertEquals(4, $this->repo->countVisitsByShortCode( ShortUrlIdentifier::fromShortCodeAndDomain($shortCode), - new VisitsCountFiltering(DateRange::withStartDate(Chronos::parse('2016-01-03'))), + new VisitsCountFiltering(DateRange::since(Chronos::parse('2016-01-03'))), )); self::assertEquals(1, $this->repo->countVisitsByShortCode( ShortUrlIdentifier::fromShortCodeAndDomain($shortCode, $domain), - new VisitsCountFiltering(DateRange::withStartDate(Chronos::parse('2016-01-03'))), + new VisitsCountFiltering(DateRange::since(Chronos::parse('2016-01-03'))), )); } @@ -227,10 +227,10 @@ class VisitRepositoryTest extends DatabaseTestCase self::assertCount(18, $this->repo->findVisitsByTag($foo, new VisitsListFiltering())); self::assertCount(12, $this->repo->findVisitsByTag($foo, new VisitsListFiltering(null, true))); self::assertCount(6, $this->repo->findVisitsByTag($foo, new VisitsListFiltering( - DateRange::withStartAndEndDate(Chronos::parse('2016-01-02'), Chronos::parse('2016-01-03')), + DateRange::between(Chronos::parse('2016-01-02'), Chronos::parse('2016-01-03')), ))); self::assertCount(12, $this->repo->findVisitsByTag($foo, new VisitsListFiltering( - DateRange::withStartDate(Chronos::parse('2016-01-03')), + DateRange::since(Chronos::parse('2016-01-03')), ))); } @@ -249,10 +249,10 @@ class VisitRepositoryTest extends DatabaseTestCase self::assertEquals(12, $this->repo->countVisitsByTag($foo, new VisitsCountFiltering())); self::assertEquals(8, $this->repo->countVisitsByTag($foo, new VisitsCountFiltering(null, true))); self::assertEquals(4, $this->repo->countVisitsByTag($foo, new VisitsCountFiltering( - DateRange::withStartAndEndDate(Chronos::parse('2016-01-02'), Chronos::parse('2016-01-03')), + DateRange::between(Chronos::parse('2016-01-02'), Chronos::parse('2016-01-03')), ))); self::assertEquals(8, $this->repo->countVisitsByTag($foo, new VisitsCountFiltering( - DateRange::withStartDate(Chronos::parse('2016-01-03')), + DateRange::since(Chronos::parse('2016-01-03')), ))); } @@ -267,16 +267,16 @@ class VisitRepositoryTest extends DatabaseTestCase self::assertCount(3, $this->repo->findVisitsByDomain('doma.in', new VisitsListFiltering())); self::assertCount(1, $this->repo->findVisitsByDomain('doma.in', new VisitsListFiltering(null, true))); self::assertCount(2, $this->repo->findVisitsByDomain('doma.in', new VisitsListFiltering( - DateRange::withStartAndEndDate(Chronos::parse('2016-01-02'), Chronos::parse('2016-01-03')), + DateRange::between(Chronos::parse('2016-01-02'), Chronos::parse('2016-01-03')), ))); self::assertCount(1, $this->repo->findVisitsByDomain('doma.in', new VisitsListFiltering( - DateRange::withStartDate(Chronos::parse('2016-01-03')), + DateRange::since(Chronos::parse('2016-01-03')), ))); self::assertCount(2, $this->repo->findVisitsByDomain('DEFAULT', new VisitsListFiltering( - DateRange::withStartAndEndDate(Chronos::parse('2016-01-02'), Chronos::parse('2016-01-03')), + DateRange::between(Chronos::parse('2016-01-02'), Chronos::parse('2016-01-03')), ))); self::assertCount(4, $this->repo->findVisitsByDomain('DEFAULT', new VisitsListFiltering( - DateRange::withStartDate(Chronos::parse('2016-01-03')), + DateRange::since(Chronos::parse('2016-01-03')), ))); } @@ -291,16 +291,16 @@ class VisitRepositoryTest extends DatabaseTestCase self::assertEquals(3, $this->repo->countVisitsByDomain('doma.in', new VisitsListFiltering())); self::assertEquals(1, $this->repo->countVisitsByDomain('doma.in', new VisitsListFiltering(null, true))); self::assertEquals(2, $this->repo->countVisitsByDomain('doma.in', new VisitsListFiltering( - DateRange::withStartAndEndDate(Chronos::parse('2016-01-02'), Chronos::parse('2016-01-03')), + DateRange::between(Chronos::parse('2016-01-02'), Chronos::parse('2016-01-03')), ))); self::assertEquals(1, $this->repo->countVisitsByDomain('doma.in', new VisitsListFiltering( - DateRange::withStartDate(Chronos::parse('2016-01-03')), + DateRange::since(Chronos::parse('2016-01-03')), ))); self::assertEquals(2, $this->repo->countVisitsByDomain('DEFAULT', new VisitsListFiltering( - DateRange::withStartAndEndDate(Chronos::parse('2016-01-02'), Chronos::parse('2016-01-03')), + DateRange::between(Chronos::parse('2016-01-02'), Chronos::parse('2016-01-03')), ))); self::assertEquals(4, $this->repo->countVisitsByDomain('DEFAULT', new VisitsListFiltering( - DateRange::withStartDate(Chronos::parse('2016-01-03')), + DateRange::since(Chronos::parse('2016-01-03')), ))); } @@ -349,13 +349,13 @@ class VisitRepositoryTest extends DatabaseTestCase self::assertEquals(4, $this->repo->countNonOrphanVisits(VisitsCountFiltering::withApiKey($apiKey1))); self::assertEquals(5 + 7, $this->repo->countNonOrphanVisits(VisitsCountFiltering::withApiKey($apiKey2))); self::assertEquals(4 + 7, $this->repo->countNonOrphanVisits(VisitsCountFiltering::withApiKey($domainApiKey))); - self::assertEquals(4, $this->repo->countNonOrphanVisits(new VisitsCountFiltering(DateRange::withStartDate( + self::assertEquals(4, $this->repo->countNonOrphanVisits(new VisitsCountFiltering(DateRange::since( Chronos::parse('2016-01-05')->startOfDay(), )))); - self::assertEquals(2, $this->repo->countNonOrphanVisits(new VisitsCountFiltering(DateRange::withStartDate( + self::assertEquals(2, $this->repo->countNonOrphanVisits(new VisitsCountFiltering(DateRange::since( Chronos::parse('2016-01-03')->startOfDay(), ), false, $apiKey1))); - self::assertEquals(1, $this->repo->countNonOrphanVisits(new VisitsCountFiltering(DateRange::withStartDate( + self::assertEquals(1, $this->repo->countNonOrphanVisits(new VisitsCountFiltering(DateRange::since( Chronos::parse('2016-01-07')->startOfDay(), ), false, $apiKey2))); self::assertEquals(3 + 5, $this->repo->countNonOrphanVisits(new VisitsCountFiltering(null, true, $apiKey2))); @@ -395,20 +395,20 @@ class VisitRepositoryTest extends DatabaseTestCase self::assertCount(5, $this->repo->findOrphanVisits(new VisitsListFiltering(null, false, null, 5))); self::assertCount(10, $this->repo->findOrphanVisits(new VisitsListFiltering(null, false, null, 15, 8))); self::assertCount(9, $this->repo->findOrphanVisits(new VisitsListFiltering( - DateRange::withStartDate(Chronos::parse('2020-01-04')), + DateRange::since(Chronos::parse('2020-01-04')), false, null, 15, ))); self::assertCount(2, $this->repo->findOrphanVisits(new VisitsListFiltering( - DateRange::withStartAndEndDate(Chronos::parse('2020-01-02'), Chronos::parse('2020-01-03')), + DateRange::between(Chronos::parse('2020-01-02'), Chronos::parse('2020-01-03')), false, null, 6, 4, ))); self::assertCount(3, $this->repo->findOrphanVisits(new VisitsListFiltering( - DateRange::withEndDate(Chronos::parse('2020-01-01')), + DateRange::until(Chronos::parse('2020-01-01')), ))); } @@ -437,15 +437,15 @@ class VisitRepositoryTest extends DatabaseTestCase $this->getEntityManager()->flush(); self::assertEquals(18, $this->repo->countOrphanVisits(new VisitsCountFiltering())); - self::assertEquals(18, $this->repo->countOrphanVisits(new VisitsCountFiltering(DateRange::emptyInstance()))); + self::assertEquals(18, $this->repo->countOrphanVisits(new VisitsCountFiltering(DateRange::allTime()))); self::assertEquals(9, $this->repo->countOrphanVisits( - new VisitsCountFiltering(DateRange::withStartDate(Chronos::parse('2020-01-04'))), + new VisitsCountFiltering(DateRange::since(Chronos::parse('2020-01-04'))), )); self::assertEquals(6, $this->repo->countOrphanVisits(new VisitsCountFiltering( - DateRange::withStartAndEndDate(Chronos::parse('2020-01-02'), Chronos::parse('2020-01-03')), + DateRange::between(Chronos::parse('2020-01-02'), Chronos::parse('2020-01-03')), ))); self::assertEquals(3, $this->repo->countOrphanVisits( - new VisitsCountFiltering(DateRange::withEndDate(Chronos::parse('2020-01-01'))), + new VisitsCountFiltering(DateRange::until(Chronos::parse('2020-01-01'))), )); } @@ -467,22 +467,22 @@ class VisitRepositoryTest extends DatabaseTestCase $this->getEntityManager()->flush(); self::assertCount(21, $this->repo->findNonOrphanVisits(new VisitsListFiltering())); - self::assertCount(21, $this->repo->findNonOrphanVisits(new VisitsListFiltering(DateRange::emptyInstance()))); - self::assertCount(7, $this->repo->findNonOrphanVisits(new VisitsListFiltering(DateRange::withStartDate( + self::assertCount(21, $this->repo->findNonOrphanVisits(new VisitsListFiltering(DateRange::allTime()))); + self::assertCount(7, $this->repo->findNonOrphanVisits(new VisitsListFiltering(DateRange::since( Chronos::parse('2016-01-05')->endOfDay(), )))); - self::assertCount(12, $this->repo->findNonOrphanVisits(new VisitsListFiltering(DateRange::withEndDate( + self::assertCount(12, $this->repo->findNonOrphanVisits(new VisitsListFiltering(DateRange::until( Chronos::parse('2016-01-04')->endOfDay(), )))); - self::assertCount(6, $this->repo->findNonOrphanVisits(new VisitsListFiltering(DateRange::withStartAndEndDate( + self::assertCount(6, $this->repo->findNonOrphanVisits(new VisitsListFiltering(DateRange::between( Chronos::parse('2016-01-03')->startOfDay(), Chronos::parse('2016-01-04')->endOfDay(), )))); - self::assertCount(13, $this->repo->findNonOrphanVisits(new VisitsListFiltering(DateRange::withStartAndEndDate( + self::assertCount(13, $this->repo->findNonOrphanVisits(new VisitsListFiltering(DateRange::between( Chronos::parse('2016-01-03')->startOfDay(), Chronos::parse('2016-01-08')->endOfDay(), )))); - self::assertCount(3, $this->repo->findNonOrphanVisits(new VisitsListFiltering(DateRange::withStartAndEndDate( + self::assertCount(3, $this->repo->findNonOrphanVisits(new VisitsListFiltering(DateRange::between( Chronos::parse('2016-01-03')->startOfDay(), Chronos::parse('2016-01-08')->endOfDay(), ), false, null, 10, 10))); diff --git a/module/Core/test/Visit/Paginator/Adapter/ShortUrlVisitsPaginatorAdapterTest.php b/module/Core/test/Visit/Paginator/Adapter/ShortUrlVisitsPaginatorAdapterTest.php index ae9a2a64..7d6d04a6 100644 --- a/module/Core/test/Visit/Paginator/Adapter/ShortUrlVisitsPaginatorAdapterTest.php +++ b/module/Core/test/Visit/Paginator/Adapter/ShortUrlVisitsPaginatorAdapterTest.php @@ -36,7 +36,7 @@ class ShortUrlVisitsPaginatorAdapterTest extends TestCase $adapter = $this->createAdapter(null); $findVisits = $this->repo->findVisitsByShortCode( ShortUrlIdentifier::fromShortCodeAndDomain(''), - new VisitsListFiltering(DateRange::emptyInstance(), false, null, $limit, $offset), + new VisitsListFiltering(DateRange::allTime(), false, null, $limit, $offset), )->willReturn([]); for ($i = 0; $i < $count; $i++) { @@ -54,7 +54,7 @@ class ShortUrlVisitsPaginatorAdapterTest extends TestCase $adapter = $this->createAdapter($apiKey); $countVisits = $this->repo->countVisitsByShortCode( ShortUrlIdentifier::fromShortCodeAndDomain(''), - new VisitsCountFiltering(DateRange::emptyInstance(), false, $apiKey), + new VisitsCountFiltering(DateRange::allTime(), false, $apiKey), )->willReturn(3); for ($i = 0; $i < $count; $i++) { diff --git a/module/Core/test/Visit/Paginator/Adapter/VisitsForTagPaginatorAdapterTest.php b/module/Core/test/Visit/Paginator/Adapter/VisitsForTagPaginatorAdapterTest.php index 442e7128..32e1bb85 100644 --- a/module/Core/test/Visit/Paginator/Adapter/VisitsForTagPaginatorAdapterTest.php +++ b/module/Core/test/Visit/Paginator/Adapter/VisitsForTagPaginatorAdapterTest.php @@ -35,7 +35,7 @@ class VisitsForTagPaginatorAdapterTest extends TestCase $adapter = $this->createAdapter(null); $findVisits = $this->repo->findVisitsByTag( 'foo', - new VisitsListFiltering(DateRange::emptyInstance(), false, null, $limit, $offset), + new VisitsListFiltering(DateRange::allTime(), false, null, $limit, $offset), )->willReturn([]); for ($i = 0; $i < $count; $i++) { @@ -53,7 +53,7 @@ class VisitsForTagPaginatorAdapterTest extends TestCase $adapter = $this->createAdapter($apiKey); $countVisits = $this->repo->countVisitsByTag( 'foo', - new VisitsCountFiltering(DateRange::emptyInstance(), false, $apiKey), + new VisitsCountFiltering(DateRange::allTime(), false, $apiKey), )->willReturn(3); for ($i = 0; $i < $count; $i++) { diff --git a/module/Rest/test/Action/Visit/ShortUrlVisitsActionTest.php b/module/Rest/test/Action/Visit/ShortUrlVisitsActionTest.php index 50cabe8e..299c42d1 100644 --- a/module/Rest/test/Action/Visit/ShortUrlVisitsActionTest.php +++ b/module/Rest/test/Action/Visit/ShortUrlVisitsActionTest.php @@ -53,7 +53,7 @@ class ShortUrlVisitsActionTest extends TestCase { $shortCode = 'abc123'; $this->visitsHelper->visitsForShortUrl(ShortUrlIdentifier::fromShortCodeAndDomain($shortCode), new VisitsParams( - DateRange::withEndDate(Chronos::parse('2016-01-01 00:00:00')), + DateRange::until(Chronos::parse('2016-01-01 00:00:00')), 3, 10, ), Argument::type(ApiKey::class))