From 1650499a38c2d0d67494f06e46ddee808fb58386 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Mon, 24 Oct 2022 19:59:03 +0200 Subject: [PATCH] Added more stricter types for mocks --- .../test/Command/Domain/GetDomainVisitsCommandTest.php | 4 ++-- .../Command/ShortUrl/GetShortUrlVisitsCommandTest.php | 2 +- module/CLI/test/Command/Tag/GetTagVisitsCommandTest.php | 4 ++-- .../test/Command/Visit/GetNonOrphanVisitsCommandTest.php | 4 ++-- .../CLI/test/Command/Visit/GetOrphanVisitsCommandTest.php | 2 +- module/CLI/test/GeoLite/GeolocationDbUpdaterTest.php | 6 +++--- .../test/EventDispatcher/LocateUnlocatedVisitsTest.php | 4 ++-- .../RedisPubSub/NotifyVisitToRedisTest.php | 8 ++++---- module/Core/test/ShortUrl/DeleteShortUrlServiceTest.php | 4 ++-- .../ShortUrl/Helper/ShortCodeUniquenessHelperTest.php | 4 ++-- .../Middleware/TrimTrailingSlashMiddlewareTest.php | 2 +- module/Core/test/ShortUrl/ShortUrlResolverTest.php | 4 ++-- module/Core/test/ShortUrl/ShortUrlServiceTest.php | 6 +++--- module/Core/test/ShortUrl/UrlShortenerTest.php | 6 +++--- .../test/Visit/Geolocation/VisitToLocationHelperTest.php | 2 +- module/Rest/test/ApiKey/InitialApiKeyDelegatorTest.php | 2 +- .../Rest/test/Middleware/AuthenticationMiddlewareTest.php | 4 ++-- .../BackwardsCompatibleProblemDetailsHandlerTest.php | 1 + 18 files changed, 35 insertions(+), 34 deletions(-) diff --git a/module/CLI/test/Command/Domain/GetDomainVisitsCommandTest.php b/module/CLI/test/Command/Domain/GetDomainVisitsCommandTest.php index 7fffbcc4..e02aa36a 100644 --- a/module/CLI/test/Command/Domain/GetDomainVisitsCommandTest.php +++ b/module/CLI/test/Command/Domain/GetDomainVisitsCommandTest.php @@ -24,8 +24,8 @@ class GetDomainVisitsCommandTest extends TestCase use CliTestUtilsTrait; private CommandTester $commandTester; - private MockObject $visitsHelper; - private MockObject $stringifier; + private MockObject & VisitsStatsHelperInterface $visitsHelper; + private MockObject & ShortUrlStringifierInterface $stringifier; protected function setUp(): void { diff --git a/module/CLI/test/Command/ShortUrl/GetShortUrlVisitsCommandTest.php b/module/CLI/test/Command/ShortUrl/GetShortUrlVisitsCommandTest.php index dd2f4ddc..8706699b 100644 --- a/module/CLI/test/Command/ShortUrl/GetShortUrlVisitsCommandTest.php +++ b/module/CLI/test/Command/ShortUrl/GetShortUrlVisitsCommandTest.php @@ -30,7 +30,7 @@ class GetShortUrlVisitsCommandTest extends TestCase use CliTestUtilsTrait; private CommandTester $commandTester; - private MockObject $visitsHelper; + private MockObject & VisitsStatsHelperInterface $visitsHelper; protected function setUp(): void { diff --git a/module/CLI/test/Command/Tag/GetTagVisitsCommandTest.php b/module/CLI/test/Command/Tag/GetTagVisitsCommandTest.php index c10c9d8d..be56cdee 100644 --- a/module/CLI/test/Command/Tag/GetTagVisitsCommandTest.php +++ b/module/CLI/test/Command/Tag/GetTagVisitsCommandTest.php @@ -24,8 +24,8 @@ class GetTagVisitsCommandTest extends TestCase use CliTestUtilsTrait; private CommandTester $commandTester; - private MockObject $visitsHelper; - private MockObject $stringifier; + private MockObject & VisitsStatsHelperInterface $visitsHelper; + private MockObject & ShortUrlStringifierInterface $stringifier; protected function setUp(): void { diff --git a/module/CLI/test/Command/Visit/GetNonOrphanVisitsCommandTest.php b/module/CLI/test/Command/Visit/GetNonOrphanVisitsCommandTest.php index 71008d16..90147541 100644 --- a/module/CLI/test/Command/Visit/GetNonOrphanVisitsCommandTest.php +++ b/module/CLI/test/Command/Visit/GetNonOrphanVisitsCommandTest.php @@ -24,8 +24,8 @@ class GetNonOrphanVisitsCommandTest extends TestCase use CliTestUtilsTrait; private CommandTester $commandTester; - private MockObject $visitsHelper; - private MockObject $stringifier; + private MockObject & VisitsStatsHelperInterface $visitsHelper; + private MockObject & ShortUrlStringifierInterface $stringifier; protected function setUp(): void { diff --git a/module/CLI/test/Command/Visit/GetOrphanVisitsCommandTest.php b/module/CLI/test/Command/Visit/GetOrphanVisitsCommandTest.php index 71f8f7b2..199578f3 100644 --- a/module/CLI/test/Command/Visit/GetOrphanVisitsCommandTest.php +++ b/module/CLI/test/Command/Visit/GetOrphanVisitsCommandTest.php @@ -22,7 +22,7 @@ class GetOrphanVisitsCommandTest extends TestCase use CliTestUtilsTrait; private CommandTester $commandTester; - private MockObject $visitsHelper; + private MockObject & VisitsStatsHelperInterface $visitsHelper; protected function setUp(): void { diff --git a/module/CLI/test/GeoLite/GeolocationDbUpdaterTest.php b/module/CLI/test/GeoLite/GeolocationDbUpdaterTest.php index 0b890e46..e1ebb4c1 100644 --- a/module/CLI/test/GeoLite/GeolocationDbUpdaterTest.php +++ b/module/CLI/test/GeoLite/GeolocationDbUpdaterTest.php @@ -23,9 +23,9 @@ use function range; class GeolocationDbUpdaterTest extends TestCase { - private MockObject $dbUpdater; - private MockObject $geoLiteDbReader; - private MockObject $lock; + private MockObject & DbUpdaterInterface $dbUpdater; + private MockObject & Reader $geoLiteDbReader; + private MockObject & Lock\LockInterface $lock; protected function setUp(): void { diff --git a/module/Core/test/EventDispatcher/LocateUnlocatedVisitsTest.php b/module/Core/test/EventDispatcher/LocateUnlocatedVisitsTest.php index 8b10821c..7315e286 100644 --- a/module/Core/test/EventDispatcher/LocateUnlocatedVisitsTest.php +++ b/module/Core/test/EventDispatcher/LocateUnlocatedVisitsTest.php @@ -17,8 +17,8 @@ use Shlinkio\Shlink\IpGeolocation\Model\Location; class LocateUnlocatedVisitsTest extends TestCase { private LocateUnlocatedVisits $listener; - private MockObject $locator; - private MockObject $visitToLocation; + private MockObject & VisitLocatorInterface $locator; + private MockObject & VisitToLocationHelperInterface $visitToLocation; protected function setUp(): void { diff --git a/module/Core/test/EventDispatcher/RedisPubSub/NotifyVisitToRedisTest.php b/module/Core/test/EventDispatcher/RedisPubSub/NotifyVisitToRedisTest.php index 92bf4583..f50cf906 100644 --- a/module/Core/test/EventDispatcher/RedisPubSub/NotifyVisitToRedisTest.php +++ b/module/Core/test/EventDispatcher/RedisPubSub/NotifyVisitToRedisTest.php @@ -22,10 +22,10 @@ use Throwable; class NotifyVisitToRedisTest extends TestCase { - private MockObject $helper; - private MockObject $updatesGenerator; - private MockObject $em; - private MockObject $logger; + private MockObject & PublishingHelperInterface $helper; + private MockObject & PublishingUpdatesGeneratorInterface $updatesGenerator; + private MockObject & EntityManagerInterface $em; + private MockObject & LoggerInterface $logger; protected function setUp(): void { diff --git a/module/Core/test/ShortUrl/DeleteShortUrlServiceTest.php b/module/Core/test/ShortUrl/DeleteShortUrlServiceTest.php index 4ce1568b..be036264 100644 --- a/module/Core/test/ShortUrl/DeleteShortUrlServiceTest.php +++ b/module/Core/test/ShortUrl/DeleteShortUrlServiceTest.php @@ -23,8 +23,8 @@ use function sprintf; class DeleteShortUrlServiceTest extends TestCase { - private MockObject $em; - private MockObject $urlResolver; + private MockObject & EntityManagerInterface $em; + private MockObject & ShortUrlResolverInterface $urlResolver; private string $shortCode; protected function setUp(): void diff --git a/module/Core/test/ShortUrl/Helper/ShortCodeUniquenessHelperTest.php b/module/Core/test/ShortUrl/Helper/ShortCodeUniquenessHelperTest.php index 2dfd4433..cc18be07 100644 --- a/module/Core/test/ShortUrl/Helper/ShortCodeUniquenessHelperTest.php +++ b/module/Core/test/ShortUrl/Helper/ShortCodeUniquenessHelperTest.php @@ -16,8 +16,8 @@ use Shlinkio\Shlink\Core\ShortUrl\Repository\ShortUrlRepository; class ShortCodeUniquenessHelperTest extends TestCase { private ShortCodeUniquenessHelper $helper; - private MockObject $em; - private MockObject $shortUrl; + private MockObject & EntityManagerInterface $em; + private MockObject & ShortUrl $shortUrl; protected function setUp(): void { diff --git a/module/Core/test/ShortUrl/Middleware/TrimTrailingSlashMiddlewareTest.php b/module/Core/test/ShortUrl/Middleware/TrimTrailingSlashMiddlewareTest.php index ca971b00..eb078902 100644 --- a/module/Core/test/ShortUrl/Middleware/TrimTrailingSlashMiddlewareTest.php +++ b/module/Core/test/ShortUrl/Middleware/TrimTrailingSlashMiddlewareTest.php @@ -19,7 +19,7 @@ use function Functional\const_function; class TrimTrailingSlashMiddlewareTest extends TestCase { - private MockObject $requestHandler; + private MockObject & RequestHandlerInterface $requestHandler; protected function setUp(): void { diff --git a/module/Core/test/ShortUrl/ShortUrlResolverTest.php b/module/Core/test/ShortUrl/ShortUrlResolverTest.php index e15bb124..1e86ec1c 100644 --- a/module/Core/test/ShortUrl/ShortUrlResolverTest.php +++ b/module/Core/test/ShortUrl/ShortUrlResolverTest.php @@ -28,8 +28,8 @@ class ShortUrlResolverTest extends TestCase use ApiKeyHelpersTrait; private ShortUrlResolver $urlResolver; - private MockObject $em; - private MockObject $repo; + private MockObject & EntityManagerInterface $em; + private MockObject & ShortUrlRepositoryInterface $repo; protected function setUp(): void { diff --git a/module/Core/test/ShortUrl/ShortUrlServiceTest.php b/module/Core/test/ShortUrl/ShortUrlServiceTest.php index 9513b6dc..876d322b 100644 --- a/module/Core/test/ShortUrl/ShortUrlServiceTest.php +++ b/module/Core/test/ShortUrl/ShortUrlServiceTest.php @@ -27,9 +27,9 @@ class ShortUrlServiceTest extends TestCase use ApiKeyHelpersTrait; private ShortUrlService $service; - private MockObject $em; - private MockObject $urlResolver; - private MockObject $titleResolutionHelper; + private MockObject & EntityManagerInterface $em; + private MockObject & ShortUrlResolverInterface $urlResolver; + private MockObject & ShortUrlTitleResolutionHelperInterface $titleResolutionHelper; protected function setUp(): void { diff --git a/module/Core/test/ShortUrl/UrlShortenerTest.php b/module/Core/test/ShortUrl/UrlShortenerTest.php index e5fe7eca..4c9e8646 100644 --- a/module/Core/test/ShortUrl/UrlShortenerTest.php +++ b/module/Core/test/ShortUrl/UrlShortenerTest.php @@ -21,9 +21,9 @@ use Shlinkio\Shlink\Core\ShortUrl\UrlShortener; class UrlShortenerTest extends TestCase { private UrlShortener $urlShortener; - private MockObject $em; - private MockObject $titleResolutionHelper; - private MockObject $shortCodeHelper; + private MockObject & EntityManager $em; + private MockObject & ShortUrlTitleResolutionHelperInterface $titleResolutionHelper; + private MockObject & ShortCodeUniquenessHelperInterface $shortCodeHelper; protected function setUp(): void { diff --git a/module/Core/test/Visit/Geolocation/VisitToLocationHelperTest.php b/module/Core/test/Visit/Geolocation/VisitToLocationHelperTest.php index b32dc037..7d0fb7f1 100644 --- a/module/Core/test/Visit/Geolocation/VisitToLocationHelperTest.php +++ b/module/Core/test/Visit/Geolocation/VisitToLocationHelperTest.php @@ -17,7 +17,7 @@ use Shlinkio\Shlink\IpGeolocation\Resolver\IpLocationResolverInterface; class VisitToLocationHelperTest extends TestCase { private VisitToLocationHelper $helper; - private MockObject $ipLocationResolver; + private MockObject & IpLocationResolverInterface $ipLocationResolver; protected function setUp(): void { diff --git a/module/Rest/test/ApiKey/InitialApiKeyDelegatorTest.php b/module/Rest/test/ApiKey/InitialApiKeyDelegatorTest.php index a44700a6..cf32ba10 100644 --- a/module/Rest/test/ApiKey/InitialApiKeyDelegatorTest.php +++ b/module/Rest/test/ApiKey/InitialApiKeyDelegatorTest.php @@ -17,7 +17,7 @@ use Shlinkio\Shlink\Rest\Entity\ApiKey; class InitialApiKeyDelegatorTest extends TestCase { private InitialApiKeyDelegator $delegator; - private MockObject $container; + private MockObject & ContainerInterface $container; protected function setUp(): void { diff --git a/module/Rest/test/Middleware/AuthenticationMiddlewareTest.php b/module/Rest/test/Middleware/AuthenticationMiddlewareTest.php index 03379921..3eb77dcb 100644 --- a/module/Rest/test/Middleware/AuthenticationMiddlewareTest.php +++ b/module/Rest/test/Middleware/AuthenticationMiddlewareTest.php @@ -28,8 +28,8 @@ use function Laminas\Stratigility\middleware; class AuthenticationMiddlewareTest extends TestCase { private AuthenticationMiddleware $middleware; - private MockObject $apiKeyService; - private MockObject $handler; + private MockObject & ApiKeyServiceInterface $apiKeyService; + private MockObject & RequestHandlerInterface $handler; protected function setUp(): void { diff --git a/module/Rest/test/Middleware/ErrorHandler/BackwardsCompatibleProblemDetailsHandlerTest.php b/module/Rest/test/Middleware/ErrorHandler/BackwardsCompatibleProblemDetailsHandlerTest.php index ab468803..40ba6965 100644 --- a/module/Rest/test/Middleware/ErrorHandler/BackwardsCompatibleProblemDetailsHandlerTest.php +++ b/module/Rest/test/Middleware/ErrorHandler/BackwardsCompatibleProblemDetailsHandlerTest.php @@ -23,6 +23,7 @@ class BackwardsCompatibleProblemDetailsHandlerTest extends TestCase } /** + * @param class-string $expectedException * @test * @dataProvider provideExceptions */