From 51f243995af4bef40fe5db9599ea6f684c2bb505 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Mon, 24 Oct 2022 19:53:13 +0200 Subject: [PATCH] Added stricter types for mocks --- composer.json | 3 ++- module/CLI/test/ApiKey/RoleResolverTest.php | 2 +- module/CLI/test/CliTestUtilsTrait.php | 5 +---- .../CLI/test/Command/Api/DisableKeyCommandTest.php | 2 +- .../CLI/test/Command/Api/GenerateKeyCommandTest.php | 2 +- module/CLI/test/Command/Api/ListKeysCommandTest.php | 2 +- .../test/Command/Db/CreateDatabaseCommandTest.php | 8 ++++---- .../test/Command/Db/MigrateDatabaseCommandTest.php | 2 +- .../Command/Domain/DomainRedirectsCommandTest.php | 2 +- .../test/Command/Domain/ListDomainsCommandTest.php | 2 +- .../Command/ShortUrl/CreateShortUrlCommandTest.php | 8 ++++---- .../Command/ShortUrl/DeleteShortUrlCommandTest.php | 2 +- .../Command/ShortUrl/ListShortUrlsCommandTest.php | 2 +- .../test/Command/ShortUrl/ResolveUrlCommandTest.php | 2 +- .../CLI/test/Command/Tag/DeleteTagsCommandTest.php | 2 +- module/CLI/test/Command/Tag/ListTagsCommandTest.php | 2 +- .../CLI/test/Command/Tag/RenameTagCommandTest.php | 2 +- .../Command/Visit/DownloadGeoLiteDbCommandTest.php | 2 +- .../test/Command/Visit/LocateVisitsCommandTest.php | 13 +++++++------ module/CLI/test/Util/ProcessRunnerTest.php | 8 ++++---- module/CLI/test/Util/ShlinkTableTest.php | 2 +- module/Core/test/Action/PixelActionTest.php | 4 ++-- module/Core/test/Action/QrCodeActionTest.php | 2 +- module/Core/test/Action/RedirectActionTest.php | 6 +++--- module/Core/test/Action/RobotsActionTest.php | 2 +- .../test/Config/NotFoundRedirectResolverTest.php | 2 +- module/Core/test/Crawling/CrawlingHelperTest.php | 2 +- module/Core/test/Domain/DomainServiceTest.php | 2 +- .../ErrorHandler/NotFoundRedirectHandlerTest.php | 6 +++--- .../ErrorHandler/NotFoundTrackerMiddlewareTest.php | 4 ++-- .../NotFoundTypeResolverMiddlewareTest.php | 2 +- .../CloseDbConnectionEventListenerDelegatorTest.php | 2 +- .../CloseDbConnectionEventListenerTest.php | 2 +- .../Core/test/EventDispatcher/LocateVisitTest.php | 10 +++++----- .../Mercure/NotifyNewShortUrlToMercureTest.php | 8 ++++---- .../Mercure/NotifyVisitToMercureTest.php | 8 ++++---- .../EventDispatcher/NotifyVisitToWebHooksTest.php | 6 +++--- .../RabbitMq/NotifyNewShortUrlToRabbitMqTest.php | 8 ++++---- .../RabbitMq/NotifyVisitToRabbitMqTest.php | 8 ++++---- .../RedisPubSub/NotifyNewShortUrlToRedisTest.php | 8 ++++---- .../test/EventDispatcher/UpdateGeoLiteDbTest.php | 6 +++--- .../test/Importer/ImportedLinksProcessorTest.php | 8 ++++---- .../Helper/ShortUrlTitleResolutionHelperTest.php | 2 +- .../Middleware/ExtraPathRedirectMiddlewareTest.php | 10 +++++----- .../Adapter/ShortUrlRepositoryAdapterTest.php | 2 +- .../PersistenceShortUrlRelationResolverTest.php | 2 +- .../Adapter/TagsInfoPaginatorAdapterTest.php | 2 +- .../Paginator/Adapter/TagsPaginatorAdapterTest.php | 2 +- module/Core/test/Tag/TagServiceTest.php | 4 ++-- module/Core/test/Util/DoctrineBatchHelperTest.php | 2 +- module/Core/test/Util/UrlValidatorTest.php | 2 +- .../test/Visit/Geolocation/VisitLocatorTest.php | 4 ++-- .../Adapter/NonOrphanVisitsPaginatorAdapterTest.php | 2 +- .../Adapter/OrphanVisitsPaginatorAdapterTest.php | 2 +- .../Adapter/ShortUrlVisitsPaginatorAdapterTest.php | 2 +- .../Adapter/VisitsForTagPaginatorAdapterTest.php | 2 +- module/Core/test/Visit/RequestTrackerTest.php | 4 ++-- module/Core/test/Visit/VisitsStatsHelperTest.php | 2 +- module/Core/test/Visit/VisitsTrackerTest.php | 4 ++-- .../Action/Domain/DomainRedirectsActionTest.php | 2 +- .../test/Action/Domain/ListDomainsActionTest.php | 2 +- module/Rest/test/Action/HealthActionTest.php | 2 +- module/Rest/test/Action/MercureInfoActionTest.php | 2 +- .../Action/ShortUrl/CreateShortUrlActionTest.php | 4 ++-- .../Action/ShortUrl/DeleteShortUrlActionTest.php | 2 +- .../test/Action/ShortUrl/EditShortUrlActionTest.php | 2 +- .../Action/ShortUrl/ListShortUrlsActionTest.php | 2 +- .../Action/ShortUrl/ResolveShortUrlActionTest.php | 2 +- .../ShortUrl/SingleStepCreateShortUrlActionTest.php | 2 +- .../Rest/test/Action/Tag/DeleteTagsActionTest.php | 2 +- module/Rest/test/Action/Tag/ListTagsActionTest.php | 2 +- module/Rest/test/Action/Tag/TagsStatsActionTest.php | 2 +- module/Rest/test/Action/Tag/UpdateTagActionTest.php | 2 +- .../test/Action/Visit/DomainVisitsActionTest.php | 2 +- .../test/Action/Visit/GlobalVisitsActionTest.php | 2 +- .../test/Action/Visit/NonOrphanVisitsActionTest.php | 2 +- .../test/Action/Visit/OrphanVisitsActionTest.php | 4 ++-- .../test/Action/Visit/ShortUrlVisitsActionTest.php | 2 +- .../Rest/test/Action/Visit/TagVisitsActionTest.php | 2 +- .../test/Middleware/CrossDomainMiddlewareTest.php | 2 +- .../NotConfiguredMercureErrorHandlerTest.php | 6 +++--- ...eateShortUrlContentNegotiationMiddlewareTest.php | 2 +- .../DefaultShortCodesLengthMiddlewareTest.php | 4 ++-- .../DropDefaultDomainFromRequestMiddlewareTest.php | 2 +- .../ShortUrl/OverrideDomainMiddlewareTest.php | 6 +++--- module/Rest/test/Service/ApiKeyServiceTest.php | 9 ++++++--- phpstan.neon | 2 ++ 87 files changed, 156 insertions(+), 152 deletions(-) diff --git a/composer.json b/composer.json index cdf2c42e..f052e27c 100644 --- a/composer.json +++ b/composer.json @@ -67,6 +67,7 @@ "openswoole/ide-helper": "~4.11.5", "phpstan/phpstan": "^1.8", "phpstan/phpstan-doctrine": "^1.3", + "phpstan/phpstan-phpunit": "^1.1", "phpstan/phpstan-symfony": "^1.2", "phpunit/php-code-coverage": "^9.2", "phpunit/phpunit": "^9.5", @@ -108,7 +109,7 @@ ], "cs": "phpcs", "cs:fix": "phpcbf", - "stan": "APP_ENV=test php vendor/bin/phpstan analyse module/*/src module/*/config config docker/config data/migrations --level=8", + "stan": "APP_ENV=test php vendor/bin/phpstan analyse module/*/src module/*/test module/*/config config docker/config data/migrations --level=8", "test": [ "@parallel test:unit test:db", "@parallel test:api test:cli" diff --git a/module/CLI/test/ApiKey/RoleResolverTest.php b/module/CLI/test/ApiKey/RoleResolverTest.php index 5195d46d..af50e17e 100644 --- a/module/CLI/test/ApiKey/RoleResolverTest.php +++ b/module/CLI/test/ApiKey/RoleResolverTest.php @@ -19,7 +19,7 @@ use function Functional\map; class RoleResolverTest extends TestCase { private RoleResolver $resolver; - private MockObject $domainService; + private MockObject & DomainServiceInterface $domainService; protected function setUp(): void { diff --git a/module/CLI/test/CliTestUtilsTrait.php b/module/CLI/test/CliTestUtilsTrait.php index 00b493e3..761567ae 100644 --- a/module/CLI/test/CliTestUtilsTrait.php +++ b/module/CLI/test/CliTestUtilsTrait.php @@ -13,10 +13,7 @@ use Symfony\Component\Console\Tester\CommandTester; trait CliTestUtilsTrait { - /** - * @return MockObject & Command - */ - private function createCommandMock(string $name): MockObject + private function createCommandMock(string $name): MockObject & Command { $command = $this->createMock(Command::class); $command->method('getName')->willReturn($name); diff --git a/module/CLI/test/Command/Api/DisableKeyCommandTest.php b/module/CLI/test/Command/Api/DisableKeyCommandTest.php index 864ef0a4..3a3c2def 100644 --- a/module/CLI/test/Command/Api/DisableKeyCommandTest.php +++ b/module/CLI/test/Command/Api/DisableKeyCommandTest.php @@ -17,7 +17,7 @@ class DisableKeyCommandTest extends TestCase use CliTestUtilsTrait; private CommandTester $commandTester; - private MockObject $apiKeyService; + private MockObject & ApiKeyServiceInterface $apiKeyService; protected function setUp(): void { diff --git a/module/CLI/test/Command/Api/GenerateKeyCommandTest.php b/module/CLI/test/Command/Api/GenerateKeyCommandTest.php index 02e704ee..631a01c8 100644 --- a/module/CLI/test/Command/Api/GenerateKeyCommandTest.php +++ b/module/CLI/test/Command/Api/GenerateKeyCommandTest.php @@ -20,7 +20,7 @@ class GenerateKeyCommandTest extends TestCase use CliTestUtilsTrait; private CommandTester $commandTester; - private MockObject $apiKeyService; + private MockObject & ApiKeyServiceInterface $apiKeyService; protected function setUp(): void { diff --git a/module/CLI/test/Command/Api/ListKeysCommandTest.php b/module/CLI/test/Command/Api/ListKeysCommandTest.php index 2983367b..a0e7d833 100644 --- a/module/CLI/test/Command/Api/ListKeysCommandTest.php +++ b/module/CLI/test/Command/Api/ListKeysCommandTest.php @@ -21,7 +21,7 @@ class ListKeysCommandTest extends TestCase use CliTestUtilsTrait; private CommandTester $commandTester; - private MockObject $apiKeyService; + private MockObject & ApiKeyServiceInterface $apiKeyService; protected function setUp(): void { diff --git a/module/CLI/test/Command/Db/CreateDatabaseCommandTest.php b/module/CLI/test/Command/Db/CreateDatabaseCommandTest.php index 4462c949..bf1eac98 100644 --- a/module/CLI/test/Command/Db/CreateDatabaseCommandTest.php +++ b/module/CLI/test/Command/Db/CreateDatabaseCommandTest.php @@ -27,10 +27,10 @@ class CreateDatabaseCommandTest extends TestCase use CliTestUtilsTrait; private CommandTester $commandTester; - private MockObject $processHelper; - private MockObject $regularConn; - private MockObject $schemaManager; - private MockObject $driver; + private MockObject & ProcessRunnerInterface $processHelper; + private MockObject & Connection $regularConn; + private MockObject & AbstractSchemaManager $schemaManager; + private MockObject & Driver $driver; protected function setUp(): void { diff --git a/module/CLI/test/Command/Db/MigrateDatabaseCommandTest.php b/module/CLI/test/Command/Db/MigrateDatabaseCommandTest.php index 5132e892..7027ca21 100644 --- a/module/CLI/test/Command/Db/MigrateDatabaseCommandTest.php +++ b/module/CLI/test/Command/Db/MigrateDatabaseCommandTest.php @@ -20,7 +20,7 @@ class MigrateDatabaseCommandTest extends TestCase use CliTestUtilsTrait; private CommandTester $commandTester; - private MockObject $processHelper; + private MockObject & ProcessRunnerInterface $processHelper; protected function setUp(): void { diff --git a/module/CLI/test/Command/Domain/DomainRedirectsCommandTest.php b/module/CLI/test/Command/Domain/DomainRedirectsCommandTest.php index ee3320a3..1bf5cec3 100644 --- a/module/CLI/test/Command/Domain/DomainRedirectsCommandTest.php +++ b/module/CLI/test/Command/Domain/DomainRedirectsCommandTest.php @@ -22,7 +22,7 @@ class DomainRedirectsCommandTest extends TestCase use CliTestUtilsTrait; private CommandTester $commandTester; - private MockObject $domainService; + private MockObject & DomainServiceInterface $domainService; protected function setUp(): void { diff --git a/module/CLI/test/Command/Domain/ListDomainsCommandTest.php b/module/CLI/test/Command/Domain/ListDomainsCommandTest.php index ef8b276c..0275ba87 100644 --- a/module/CLI/test/Command/Domain/ListDomainsCommandTest.php +++ b/module/CLI/test/Command/Domain/ListDomainsCommandTest.php @@ -21,7 +21,7 @@ class ListDomainsCommandTest extends TestCase use CliTestUtilsTrait; private CommandTester $commandTester; - private MockObject $domainService; + private MockObject & DomainServiceInterface $domainService; protected function setUp(): void { diff --git a/module/CLI/test/Command/ShortUrl/CreateShortUrlCommandTest.php b/module/CLI/test/Command/ShortUrl/CreateShortUrlCommandTest.php index 79ce3b5f..16b85290 100644 --- a/module/CLI/test/Command/ShortUrl/CreateShortUrlCommandTest.php +++ b/module/CLI/test/Command/ShortUrl/CreateShortUrlCommandTest.php @@ -15,7 +15,7 @@ use Shlinkio\Shlink\Core\Options\UrlShortenerOptions; use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl; use Shlinkio\Shlink\Core\ShortUrl\Helper\ShortUrlStringifierInterface; use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlCreation; -use Shlinkio\Shlink\Core\ShortUrl\UrlShortener; +use Shlinkio\Shlink\Core\ShortUrl\UrlShortenerInterface; use ShlinkioTest\Shlink\CLI\CliTestUtilsTrait; use Symfony\Component\Console\Tester\CommandTester; @@ -26,12 +26,12 @@ class CreateShortUrlCommandTest extends TestCase private const DEFAULT_DOMAIN = 'default.com'; private CommandTester $commandTester; - private MockObject $urlShortener; - private MockObject $stringifier; + private MockObject & UrlShortenerInterface $urlShortener; + private MockObject & ShortUrlStringifierInterface $stringifier; protected function setUp(): void { - $this->urlShortener = $this->createMock(UrlShortener::class); + $this->urlShortener = $this->createMock(UrlShortenerInterface::class); $this->stringifier = $this->createMock(ShortUrlStringifierInterface::class); $command = new CreateShortUrlCommand( diff --git a/module/CLI/test/Command/ShortUrl/DeleteShortUrlCommandTest.php b/module/CLI/test/Command/ShortUrl/DeleteShortUrlCommandTest.php index 537ed51b..09d48d12 100644 --- a/module/CLI/test/Command/ShortUrl/DeleteShortUrlCommandTest.php +++ b/module/CLI/test/Command/ShortUrl/DeleteShortUrlCommandTest.php @@ -22,7 +22,7 @@ class DeleteShortUrlCommandTest extends TestCase use CliTestUtilsTrait; private CommandTester $commandTester; - private MockObject $service; + private MockObject & DeleteShortUrlServiceInterface $service; protected function setUp(): void { diff --git a/module/CLI/test/Command/ShortUrl/ListShortUrlsCommandTest.php b/module/CLI/test/Command/ShortUrl/ListShortUrlsCommandTest.php index 208e595a..3b186bd1 100644 --- a/module/CLI/test/Command/ShortUrl/ListShortUrlsCommandTest.php +++ b/module/CLI/test/Command/ShortUrl/ListShortUrlsCommandTest.php @@ -30,7 +30,7 @@ class ListShortUrlsCommandTest extends TestCase use CliTestUtilsTrait; private CommandTester $commandTester; - private MockObject $shortUrlService; + private MockObject & ShortUrlServiceInterface $shortUrlService; protected function setUp(): void { diff --git a/module/CLI/test/Command/ShortUrl/ResolveUrlCommandTest.php b/module/CLI/test/Command/ShortUrl/ResolveUrlCommandTest.php index 87962355..89614e6f 100644 --- a/module/CLI/test/Command/ShortUrl/ResolveUrlCommandTest.php +++ b/module/CLI/test/Command/ShortUrl/ResolveUrlCommandTest.php @@ -23,7 +23,7 @@ class ResolveUrlCommandTest extends TestCase use CliTestUtilsTrait; private CommandTester $commandTester; - private MockObject $urlResolver; + private MockObject & ShortUrlResolverInterface $urlResolver; protected function setUp(): void { diff --git a/module/CLI/test/Command/Tag/DeleteTagsCommandTest.php b/module/CLI/test/Command/Tag/DeleteTagsCommandTest.php index 74c02dde..0528af24 100644 --- a/module/CLI/test/Command/Tag/DeleteTagsCommandTest.php +++ b/module/CLI/test/Command/Tag/DeleteTagsCommandTest.php @@ -16,7 +16,7 @@ class DeleteTagsCommandTest extends TestCase use CliTestUtilsTrait; private CommandTester $commandTester; - private MockObject $tagService; + private MockObject & TagServiceInterface $tagService; protected function setUp(): void { diff --git a/module/CLI/test/Command/Tag/ListTagsCommandTest.php b/module/CLI/test/Command/Tag/ListTagsCommandTest.php index e3802a1a..6ac53f8a 100644 --- a/module/CLI/test/Command/Tag/ListTagsCommandTest.php +++ b/module/CLI/test/Command/Tag/ListTagsCommandTest.php @@ -19,7 +19,7 @@ class ListTagsCommandTest extends TestCase use CliTestUtilsTrait; private CommandTester $commandTester; - private MockObject $tagService; + private MockObject & TagServiceInterface $tagService; protected function setUp(): void { diff --git a/module/CLI/test/Command/Tag/RenameTagCommandTest.php b/module/CLI/test/Command/Tag/RenameTagCommandTest.php index 4a752de9..95a1e85d 100644 --- a/module/CLI/test/Command/Tag/RenameTagCommandTest.php +++ b/module/CLI/test/Command/Tag/RenameTagCommandTest.php @@ -19,7 +19,7 @@ class RenameTagCommandTest extends TestCase use CliTestUtilsTrait; private CommandTester $commandTester; - private MockObject $tagService; + private MockObject & TagServiceInterface $tagService; protected function setUp(): void { diff --git a/module/CLI/test/Command/Visit/DownloadGeoLiteDbCommandTest.php b/module/CLI/test/Command/Visit/DownloadGeoLiteDbCommandTest.php index b5197dde..742fa31b 100644 --- a/module/CLI/test/Command/Visit/DownloadGeoLiteDbCommandTest.php +++ b/module/CLI/test/Command/Visit/DownloadGeoLiteDbCommandTest.php @@ -21,7 +21,7 @@ class DownloadGeoLiteDbCommandTest extends TestCase use CliTestUtilsTrait; private CommandTester $commandTester; - private MockObject $dbUpdater; + private MockObject & GeolocationDbUpdaterInterface $dbUpdater; protected function setUp(): void { diff --git a/module/CLI/test/Command/Visit/LocateVisitsCommandTest.php b/module/CLI/test/Command/Visit/LocateVisitsCommandTest.php index 418e3af6..518d9f45 100644 --- a/module/CLI/test/Command/Visit/LocateVisitsCommandTest.php +++ b/module/CLI/test/Command/Visit/LocateVisitsCommandTest.php @@ -14,12 +14,13 @@ use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl; use Shlinkio\Shlink\Core\Visit\Entity\Visit; use Shlinkio\Shlink\Core\Visit\Entity\VisitLocation; use Shlinkio\Shlink\Core\Visit\Geolocation\VisitGeolocationHelperInterface; -use Shlinkio\Shlink\Core\Visit\Geolocation\VisitLocator; +use Shlinkio\Shlink\Core\Visit\Geolocation\VisitLocatorInterface; use Shlinkio\Shlink\Core\Visit\Geolocation\VisitToLocationHelperInterface; use Shlinkio\Shlink\Core\Visit\Model\Visitor; use Shlinkio\Shlink\IpGeolocation\Exception\WrongIpException; use Shlinkio\Shlink\IpGeolocation\Model\Location; use ShlinkioTest\Shlink\CLI\CliTestUtilsTrait; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Exception\RuntimeException; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Tester\CommandTester; @@ -34,14 +35,14 @@ class LocateVisitsCommandTest extends TestCase use CliTestUtilsTrait; private CommandTester $commandTester; - private MockObject $visitService; - private MockObject $visitToLocation; - private MockObject $lock; - private MockObject $downloadDbCommand; + private MockObject & VisitLocatorInterface $visitService; + private MockObject & VisitToLocationHelperInterface $visitToLocation; + private MockObject & Lock\LockInterface $lock; + private MockObject & Command $downloadDbCommand; protected function setUp(): void { - $this->visitService = $this->createMock(VisitLocator::class); + $this->visitService = $this->createMock(VisitLocatorInterface::class); $this->visitToLocation = $this->createMock(VisitToLocationHelperInterface::class); $locker = $this->createMock(Lock\LockFactory::class); diff --git a/module/CLI/test/Util/ProcessRunnerTest.php b/module/CLI/test/Util/ProcessRunnerTest.php index 28ff21af..a23d1b48 100644 --- a/module/CLI/test/Util/ProcessRunnerTest.php +++ b/module/CLI/test/Util/ProcessRunnerTest.php @@ -16,10 +16,10 @@ use Symfony\Component\Process\Process; class ProcessRunnerTest extends TestCase { private ProcessRunner $runner; - private MockObject $helper; - private MockObject $formatter; - private MockObject $process; - private MockObject $output; + private MockObject & ProcessHelper $helper; + private MockObject & DebugFormatterHelper $formatter; + private MockObject & Process $process; + private MockObject & OutputInterface $output; protected function setUp(): void { diff --git a/module/CLI/test/Util/ShlinkTableTest.php b/module/CLI/test/Util/ShlinkTableTest.php index 01e1be1f..829e56d9 100644 --- a/module/CLI/test/Util/ShlinkTableTest.php +++ b/module/CLI/test/Util/ShlinkTableTest.php @@ -15,7 +15,7 @@ use Symfony\Component\Console\Output\OutputInterface; class ShlinkTableTest extends TestCase { private ShlinkTable $shlinkTable; - private MockObject $baseTable; + private MockObject & Table $baseTable; protected function setUp(): void { diff --git a/module/Core/test/Action/PixelActionTest.php b/module/Core/test/Action/PixelActionTest.php index e2e75144..b493e2cb 100644 --- a/module/Core/test/Action/PixelActionTest.php +++ b/module/Core/test/Action/PixelActionTest.php @@ -18,8 +18,8 @@ use Shlinkio\Shlink\Core\Visit\RequestTrackerInterface; class PixelActionTest extends TestCase { private PixelAction $action; - private MockObject $urlResolver; - private MockObject $requestTracker; + private MockObject & ShortUrlResolverInterface $urlResolver; + private MockObject & RequestTrackerInterface $requestTracker; protected function setUp(): void { diff --git a/module/Core/test/Action/QrCodeActionTest.php b/module/Core/test/Action/QrCodeActionTest.php index 06b07ecf..497fb009 100644 --- a/module/Core/test/Action/QrCodeActionTest.php +++ b/module/Core/test/Action/QrCodeActionTest.php @@ -30,7 +30,7 @@ class QrCodeActionTest extends TestCase private const WHITE = 0xFFFFFF; private const BLACK = 0x0; - private MockObject $urlResolver; + private MockObject & ShortUrlResolverInterface $urlResolver; protected function setUp(): void { diff --git a/module/Core/test/Action/RedirectActionTest.php b/module/Core/test/Action/RedirectActionTest.php index de572d2c..7e4d1cb0 100644 --- a/module/Core/test/Action/RedirectActionTest.php +++ b/module/Core/test/Action/RedirectActionTest.php @@ -23,9 +23,9 @@ class RedirectActionTest extends TestCase private const LONG_URL = 'https://domain.com/foo/bar?some=thing'; private RedirectAction $action; - private MockObject $urlResolver; - private MockObject $requestTracker; - private MockObject $redirectRespHelper; + private MockObject & ShortUrlResolverInterface $urlResolver; + private MockObject & RequestTrackerInterface $requestTracker; + private MockObject & RedirectResponseHelperInterface $redirectRespHelper; protected function setUp(): void { diff --git a/module/Core/test/Action/RobotsActionTest.php b/module/Core/test/Action/RobotsActionTest.php index 4f405506..db1f7f90 100644 --- a/module/Core/test/Action/RobotsActionTest.php +++ b/module/Core/test/Action/RobotsActionTest.php @@ -13,7 +13,7 @@ use Shlinkio\Shlink\Core\Crawling\CrawlingHelperInterface; class RobotsActionTest extends TestCase { private RobotsAction $action; - private MockObject $helper; + private MockObject & CrawlingHelperInterface $helper; protected function setUp(): void { diff --git a/module/Core/test/Config/NotFoundRedirectResolverTest.php b/module/Core/test/Config/NotFoundRedirectResolverTest.php index 7ca2bb82..d2d03807 100644 --- a/module/Core/test/Config/NotFoundRedirectResolverTest.php +++ b/module/Core/test/Config/NotFoundRedirectResolverTest.php @@ -24,7 +24,7 @@ use Shlinkio\Shlink\Core\Util\RedirectResponseHelperInterface; class NotFoundRedirectResolverTest extends TestCase { private NotFoundRedirectResolver $resolver; - private MockObject $helper; + private MockObject & RedirectResponseHelperInterface $helper; protected function setUp(): void { diff --git a/module/Core/test/Crawling/CrawlingHelperTest.php b/module/Core/test/Crawling/CrawlingHelperTest.php index 8af3396a..1843d35c 100644 --- a/module/Core/test/Crawling/CrawlingHelperTest.php +++ b/module/Core/test/Crawling/CrawlingHelperTest.php @@ -14,7 +14,7 @@ use Shlinkio\Shlink\Core\ShortUrl\Repository\ShortUrlRepositoryInterface; class CrawlingHelperTest extends TestCase { private CrawlingHelper $helper; - private MockObject $em; + private MockObject & EntityManagerInterface $em; protected function setUp(): void { diff --git a/module/Core/test/Domain/DomainServiceTest.php b/module/Core/test/Domain/DomainServiceTest.php index 38d925f2..4d4606b0 100644 --- a/module/Core/test/Domain/DomainServiceTest.php +++ b/module/Core/test/Domain/DomainServiceTest.php @@ -21,7 +21,7 @@ use Shlinkio\Shlink\Rest\Entity\ApiKey; class DomainServiceTest extends TestCase { private DomainService $domainService; - private MockObject $em; + private MockObject & EntityManagerInterface $em; protected function setUp(): void { diff --git a/module/Core/test/ErrorHandler/NotFoundRedirectHandlerTest.php b/module/Core/test/ErrorHandler/NotFoundRedirectHandlerTest.php index d9e5615e..c6debfb5 100644 --- a/module/Core/test/ErrorHandler/NotFoundRedirectHandlerTest.php +++ b/module/Core/test/ErrorHandler/NotFoundRedirectHandlerTest.php @@ -22,9 +22,9 @@ class NotFoundRedirectHandlerTest extends TestCase { private NotFoundRedirectHandler $middleware; private NotFoundRedirectOptions $redirectOptions; - private MockObject $resolver; - private MockObject $domainService; - private MockObject $next; + private MockObject & NotFoundRedirectResolverInterface $resolver; + private MockObject & DomainServiceInterface $domainService; + private MockObject & RequestHandlerInterface $next; private ServerRequestInterface $req; protected function setUp(): void diff --git a/module/Core/test/ErrorHandler/NotFoundTrackerMiddlewareTest.php b/module/Core/test/ErrorHandler/NotFoundTrackerMiddlewareTest.php index f475d317..d8687223 100644 --- a/module/Core/test/ErrorHandler/NotFoundTrackerMiddlewareTest.php +++ b/module/Core/test/ErrorHandler/NotFoundTrackerMiddlewareTest.php @@ -17,8 +17,8 @@ class NotFoundTrackerMiddlewareTest extends TestCase { private NotFoundTrackerMiddleware $middleware; private ServerRequestInterface $request; - private MockObject $handler; - private MockObject $requestTracker; + private MockObject & RequestHandlerInterface $handler; + private MockObject & RequestTrackerInterface $requestTracker; protected function setUp(): void { diff --git a/module/Core/test/ErrorHandler/NotFoundTypeResolverMiddlewareTest.php b/module/Core/test/ErrorHandler/NotFoundTypeResolverMiddlewareTest.php index c2ef419b..a58e3713 100644 --- a/module/Core/test/ErrorHandler/NotFoundTypeResolverMiddlewareTest.php +++ b/module/Core/test/ErrorHandler/NotFoundTypeResolverMiddlewareTest.php @@ -17,7 +17,7 @@ use Shlinkio\Shlink\Core\ErrorHandler\NotFoundTypeResolverMiddleware; class NotFoundTypeResolverMiddlewareTest extends TestCase { private NotFoundTypeResolverMiddleware $middleware; - private MockObject $handler; + private MockObject & RequestHandlerInterface $handler; protected function setUp(): void { diff --git a/module/Core/test/EventDispatcher/CloseDbConnectionEventListenerDelegatorTest.php b/module/Core/test/EventDispatcher/CloseDbConnectionEventListenerDelegatorTest.php index ebdaebdf..7cad7732 100644 --- a/module/Core/test/EventDispatcher/CloseDbConnectionEventListenerDelegatorTest.php +++ b/module/Core/test/EventDispatcher/CloseDbConnectionEventListenerDelegatorTest.php @@ -13,7 +13,7 @@ use Shlinkio\Shlink\Core\EventDispatcher\CloseDbConnectionEventListenerDelegator class CloseDbConnectionEventListenerDelegatorTest extends TestCase { private CloseDbConnectionEventListenerDelegator $delegator; - private MockObject $container; + private MockObject & ContainerInterface $container; protected function setUp(): void { diff --git a/module/Core/test/EventDispatcher/CloseDbConnectionEventListenerTest.php b/module/Core/test/EventDispatcher/CloseDbConnectionEventListenerTest.php index 76b433e1..430f08a9 100644 --- a/module/Core/test/EventDispatcher/CloseDbConnectionEventListenerTest.php +++ b/module/Core/test/EventDispatcher/CloseDbConnectionEventListenerTest.php @@ -15,7 +15,7 @@ use Throwable; class CloseDbConnectionEventListenerTest extends TestCase { - private MockObject $em; + private MockObject & ReopeningEntityManagerInterface $em; protected function setUp(): void { diff --git a/module/Core/test/EventDispatcher/LocateVisitTest.php b/module/Core/test/EventDispatcher/LocateVisitTest.php index ca862105..cad6d164 100644 --- a/module/Core/test/EventDispatcher/LocateVisitTest.php +++ b/module/Core/test/EventDispatcher/LocateVisitTest.php @@ -26,11 +26,11 @@ use Shlinkio\Shlink\IpGeolocation\Resolver\IpLocationResolverInterface; class LocateVisitTest extends TestCase { private LocateVisit $locateVisit; - private MockObject $ipLocationResolver; - private MockObject $em; - private MockObject $logger; - private MockObject $eventDispatcher; - private MockObject $dbUpdater; + private MockObject & IpLocationResolverInterface $ipLocationResolver; + private MockObject & EntityManagerInterface $em; + private MockObject & LoggerInterface $logger; + private MockObject & EventDispatcherInterface $eventDispatcher; + private MockObject & DbUpdaterInterface $dbUpdater; protected function setUp(): void { diff --git a/module/Core/test/EventDispatcher/Mercure/NotifyNewShortUrlToMercureTest.php b/module/Core/test/EventDispatcher/Mercure/NotifyNewShortUrlToMercureTest.php index 40ba0a2a..c42bd915 100644 --- a/module/Core/test/EventDispatcher/Mercure/NotifyNewShortUrlToMercureTest.php +++ b/module/Core/test/EventDispatcher/Mercure/NotifyNewShortUrlToMercureTest.php @@ -19,10 +19,10 @@ use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl; class NotifyNewShortUrlToMercureTest extends TestCase { private NotifyNewShortUrlToMercure $listener; - 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/EventDispatcher/Mercure/NotifyVisitToMercureTest.php b/module/Core/test/EventDispatcher/Mercure/NotifyVisitToMercureTest.php index 00d521f5..1cecada7 100644 --- a/module/Core/test/EventDispatcher/Mercure/NotifyVisitToMercureTest.php +++ b/module/Core/test/EventDispatcher/Mercure/NotifyVisitToMercureTest.php @@ -22,10 +22,10 @@ use Shlinkio\Shlink\Core\Visit\Model\VisitType; class NotifyVisitToMercureTest extends TestCase { private NotifyVisitToMercure $listener; - 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/EventDispatcher/NotifyVisitToWebHooksTest.php b/module/Core/test/EventDispatcher/NotifyVisitToWebHooksTest.php index be4741d6..7a5cb888 100644 --- a/module/Core/test/EventDispatcher/NotifyVisitToWebHooksTest.php +++ b/module/Core/test/EventDispatcher/NotifyVisitToWebHooksTest.php @@ -30,9 +30,9 @@ use function Functional\contains; class NotifyVisitToWebHooksTest extends TestCase { - private MockObject $httpClient; - private MockObject $em; - private MockObject $logger; + private MockObject & ClientInterface $httpClient; + private MockObject & EntityManagerInterface $em; + private MockObject & LoggerInterface $logger; protected function setUp(): void { diff --git a/module/Core/test/EventDispatcher/RabbitMq/NotifyNewShortUrlToRabbitMqTest.php b/module/Core/test/EventDispatcher/RabbitMq/NotifyNewShortUrlToRabbitMqTest.php index ffa1b505..764f7949 100644 --- a/module/Core/test/EventDispatcher/RabbitMq/NotifyNewShortUrlToRabbitMqTest.php +++ b/module/Core/test/EventDispatcher/RabbitMq/NotifyNewShortUrlToRabbitMqTest.php @@ -23,10 +23,10 @@ use Throwable; class NotifyNewShortUrlToRabbitMqTest 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/EventDispatcher/RabbitMq/NotifyVisitToRabbitMqTest.php b/module/Core/test/EventDispatcher/RabbitMq/NotifyVisitToRabbitMqTest.php index 5abb15f0..0def544e 100644 --- a/module/Core/test/EventDispatcher/RabbitMq/NotifyVisitToRabbitMqTest.php +++ b/module/Core/test/EventDispatcher/RabbitMq/NotifyVisitToRabbitMqTest.php @@ -31,10 +31,10 @@ use function Functional\noop; class NotifyVisitToRabbitMqTest 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/EventDispatcher/RedisPubSub/NotifyNewShortUrlToRedisTest.php b/module/Core/test/EventDispatcher/RedisPubSub/NotifyNewShortUrlToRedisTest.php index 347d5029..0b5dfd27 100644 --- a/module/Core/test/EventDispatcher/RedisPubSub/NotifyNewShortUrlToRedisTest.php +++ b/module/Core/test/EventDispatcher/RedisPubSub/NotifyNewShortUrlToRedisTest.php @@ -22,10 +22,10 @@ use Throwable; class NotifyNewShortUrlToRedisTest 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/EventDispatcher/UpdateGeoLiteDbTest.php b/module/Core/test/EventDispatcher/UpdateGeoLiteDbTest.php index e74508d3..5b496123 100644 --- a/module/Core/test/EventDispatcher/UpdateGeoLiteDbTest.php +++ b/module/Core/test/EventDispatcher/UpdateGeoLiteDbTest.php @@ -19,9 +19,9 @@ use function Functional\map; class UpdateGeoLiteDbTest extends TestCase { private UpdateGeoLiteDb $listener; - private MockObject $dbUpdater; - private MockObject $logger; - private MockObject $eventDispatcher; + private MockObject & GeolocationDbUpdaterInterface $dbUpdater; + private MockObject & LoggerInterface $logger; + private MockObject & EventDispatcherInterface $eventDispatcher; protected function setUp(): void { diff --git a/module/Core/test/Importer/ImportedLinksProcessorTest.php b/module/Core/test/Importer/ImportedLinksProcessorTest.php index 3f5fa495..382d912c 100644 --- a/module/Core/test/Importer/ImportedLinksProcessorTest.php +++ b/module/Core/test/Importer/ImportedLinksProcessorTest.php @@ -32,10 +32,10 @@ use function str_contains; class ImportedLinksProcessorTest extends TestCase { private ImportedLinksProcessor $processor; - private MockObject $em; - private MockObject $shortCodeHelper; - private MockObject $repo; - private MockObject $io; + private MockObject & EntityManagerInterface $em; + private MockObject & ShortCodeUniquenessHelperInterface $shortCodeHelper; + private MockObject & ShortUrlRepositoryInterface $repo; + private MockObject & StyleInterface $io; protected function setUp(): void { diff --git a/module/Core/test/ShortUrl/Helper/ShortUrlTitleResolutionHelperTest.php b/module/Core/test/ShortUrl/Helper/ShortUrlTitleResolutionHelperTest.php index 52255be7..2d48b294 100644 --- a/module/Core/test/ShortUrl/Helper/ShortUrlTitleResolutionHelperTest.php +++ b/module/Core/test/ShortUrl/Helper/ShortUrlTitleResolutionHelperTest.php @@ -13,7 +13,7 @@ use Shlinkio\Shlink\Core\Util\UrlValidatorInterface; class ShortUrlTitleResolutionHelperTest extends TestCase { private ShortUrlTitleResolutionHelper $helper; - private MockObject $urlValidator; + private MockObject & UrlValidatorInterface $urlValidator; protected function setUp(): void { diff --git a/module/Core/test/ShortUrl/Middleware/ExtraPathRedirectMiddlewareTest.php b/module/Core/test/ShortUrl/Middleware/ExtraPathRedirectMiddlewareTest.php index 80491132..355bec0e 100644 --- a/module/Core/test/ShortUrl/Middleware/ExtraPathRedirectMiddlewareTest.php +++ b/module/Core/test/ShortUrl/Middleware/ExtraPathRedirectMiddlewareTest.php @@ -30,11 +30,11 @@ use function str_starts_with; class ExtraPathRedirectMiddlewareTest extends TestCase { - private MockObject $resolver; - private MockObject $requestTracker; - private MockObject $redirectionBuilder; - private MockObject $redirectResponseHelper; - private MockObject $handler; + private MockObject & ShortUrlResolverInterface $resolver; + private MockObject & RequestTrackerInterface $requestTracker; + private MockObject & ShortUrlRedirectionBuilderInterface $redirectionBuilder; + private MockObject & RedirectResponseHelperInterface $redirectResponseHelper; + private MockObject & RequestHandlerInterface $handler; protected function setUp(): void { diff --git a/module/Core/test/ShortUrl/Paginator/Adapter/ShortUrlRepositoryAdapterTest.php b/module/Core/test/ShortUrl/Paginator/Adapter/ShortUrlRepositoryAdapterTest.php index 1df421bb..4cbc9eae 100644 --- a/module/Core/test/ShortUrl/Paginator/Adapter/ShortUrlRepositoryAdapterTest.php +++ b/module/Core/test/ShortUrl/Paginator/Adapter/ShortUrlRepositoryAdapterTest.php @@ -17,7 +17,7 @@ use Shlinkio\Shlink\Rest\Entity\ApiKey; class ShortUrlRepositoryAdapterTest extends TestCase { - private MockObject $repo; + private MockObject & ShortUrlRepositoryInterface $repo; protected function setUp(): void { diff --git a/module/Core/test/ShortUrl/Resolver/PersistenceShortUrlRelationResolverTest.php b/module/Core/test/ShortUrl/Resolver/PersistenceShortUrlRelationResolverTest.php index 995c61cd..37a9f2e2 100644 --- a/module/Core/test/ShortUrl/Resolver/PersistenceShortUrlRelationResolverTest.php +++ b/module/Core/test/ShortUrl/Resolver/PersistenceShortUrlRelationResolverTest.php @@ -19,7 +19,7 @@ use function count; class PersistenceShortUrlRelationResolverTest extends TestCase { private PersistenceShortUrlRelationResolver $resolver; - private MockObject $em; + private MockObject & EntityManagerInterface $em; protected function setUp(): void { diff --git a/module/Core/test/Tag/Paginator/Adapter/TagsInfoPaginatorAdapterTest.php b/module/Core/test/Tag/Paginator/Adapter/TagsInfoPaginatorAdapterTest.php index 99ebddf1..fe105ce1 100644 --- a/module/Core/test/Tag/Paginator/Adapter/TagsInfoPaginatorAdapterTest.php +++ b/module/Core/test/Tag/Paginator/Adapter/TagsInfoPaginatorAdapterTest.php @@ -13,7 +13,7 @@ use Shlinkio\Shlink\Core\Tag\Repository\TagRepositoryInterface; class TagsInfoPaginatorAdapterTest extends TestCase { private TagsInfoPaginatorAdapter $adapter; - private MockObject $repo; + private MockObject & TagRepositoryInterface $repo; protected function setUp(): void { diff --git a/module/Core/test/Tag/Paginator/Adapter/TagsPaginatorAdapterTest.php b/module/Core/test/Tag/Paginator/Adapter/TagsPaginatorAdapterTest.php index bce7d9cc..a3b36215 100644 --- a/module/Core/test/Tag/Paginator/Adapter/TagsPaginatorAdapterTest.php +++ b/module/Core/test/Tag/Paginator/Adapter/TagsPaginatorAdapterTest.php @@ -13,7 +13,7 @@ use Shlinkio\Shlink\Core\Tag\Repository\TagRepositoryInterface; class TagsPaginatorAdapterTest extends TestCase { private TagsPaginatorAdapter $adapter; - private MockObject $repo; + private MockObject & TagRepositoryInterface $repo; protected function setUp(): void { diff --git a/module/Core/test/Tag/TagServiceTest.php b/module/Core/test/Tag/TagServiceTest.php index 9cba4875..069bca20 100644 --- a/module/Core/test/Tag/TagServiceTest.php +++ b/module/Core/test/Tag/TagServiceTest.php @@ -27,8 +27,8 @@ class TagServiceTest extends TestCase use ApiKeyHelpersTrait; private TagService $service; - private MockObject $em; - private MockObject $repo; + private MockObject & EntityManagerInterface $em; + private MockObject & TagRepository $repo; protected function setUp(): void { diff --git a/module/Core/test/Util/DoctrineBatchHelperTest.php b/module/Core/test/Util/DoctrineBatchHelperTest.php index aec4f0b6..2fc0f985 100644 --- a/module/Core/test/Util/DoctrineBatchHelperTest.php +++ b/module/Core/test/Util/DoctrineBatchHelperTest.php @@ -13,7 +13,7 @@ use Shlinkio\Shlink\Core\Util\DoctrineBatchHelper; class DoctrineBatchHelperTest extends TestCase { private DoctrineBatchHelper $helper; - private MockObject $em; + private MockObject & EntityManagerInterface $em; protected function setUp(): void { diff --git a/module/Core/test/Util/UrlValidatorTest.php b/module/Core/test/Util/UrlValidatorTest.php index 2610b7fd..90ab2fd7 100644 --- a/module/Core/test/Util/UrlValidatorTest.php +++ b/module/Core/test/Util/UrlValidatorTest.php @@ -20,7 +20,7 @@ use Shlinkio\Shlink\Core\Util\UrlValidator; class UrlValidatorTest extends TestCase { - private MockObject $httpClient; + private MockObject & ClientInterface $httpClient; protected function setUp(): void { diff --git a/module/Core/test/Visit/Geolocation/VisitLocatorTest.php b/module/Core/test/Visit/Geolocation/VisitLocatorTest.php index 4141f7c5..a9ed7aa2 100644 --- a/module/Core/test/Visit/Geolocation/VisitLocatorTest.php +++ b/module/Core/test/Visit/Geolocation/VisitLocatorTest.php @@ -30,8 +30,8 @@ use function sprintf; class VisitLocatorTest extends TestCase { private VisitLocator $visitService; - private MockObject $em; - private MockObject $repo; + private MockObject & EntityManager $em; + private MockObject & VisitRepositoryInterface $repo; protected function setUp(): void { diff --git a/module/Core/test/Visit/Paginator/Adapter/NonOrphanVisitsPaginatorAdapterTest.php b/module/Core/test/Visit/Paginator/Adapter/NonOrphanVisitsPaginatorAdapterTest.php index 1bd03109..9c4a6e63 100644 --- a/module/Core/test/Visit/Paginator/Adapter/NonOrphanVisitsPaginatorAdapterTest.php +++ b/module/Core/test/Visit/Paginator/Adapter/NonOrphanVisitsPaginatorAdapterTest.php @@ -18,7 +18,7 @@ use Shlinkio\Shlink\Rest\Entity\ApiKey; class NonOrphanVisitsPaginatorAdapterTest extends TestCase { private NonOrphanVisitsPaginatorAdapter $adapter; - private MockObject $repo; + private MockObject & VisitRepositoryInterface $repo; private VisitsParams $params; private ApiKey $apiKey; diff --git a/module/Core/test/Visit/Paginator/Adapter/OrphanVisitsPaginatorAdapterTest.php b/module/Core/test/Visit/Paginator/Adapter/OrphanVisitsPaginatorAdapterTest.php index adad4322..8981d05f 100644 --- a/module/Core/test/Visit/Paginator/Adapter/OrphanVisitsPaginatorAdapterTest.php +++ b/module/Core/test/Visit/Paginator/Adapter/OrphanVisitsPaginatorAdapterTest.php @@ -17,7 +17,7 @@ use Shlinkio\Shlink\Core\Visit\Repository\VisitRepositoryInterface; class OrphanVisitsPaginatorAdapterTest extends TestCase { private OrphanVisitsPaginatorAdapter $adapter; - private MockObject $repo; + private MockObject & VisitRepositoryInterface $repo; private VisitsParams $params; protected function setUp(): void diff --git a/module/Core/test/Visit/Paginator/Adapter/ShortUrlVisitsPaginatorAdapterTest.php b/module/Core/test/Visit/Paginator/Adapter/ShortUrlVisitsPaginatorAdapterTest.php index 3e6c3737..8ebf1afc 100644 --- a/module/Core/test/Visit/Paginator/Adapter/ShortUrlVisitsPaginatorAdapterTest.php +++ b/module/Core/test/Visit/Paginator/Adapter/ShortUrlVisitsPaginatorAdapterTest.php @@ -17,7 +17,7 @@ use Shlinkio\Shlink\Rest\Entity\ApiKey; class ShortUrlVisitsPaginatorAdapterTest extends TestCase { - private MockObject $repo; + private MockObject & VisitRepositoryInterface $repo; protected function setUp(): void { diff --git a/module/Core/test/Visit/Paginator/Adapter/VisitsForTagPaginatorAdapterTest.php b/module/Core/test/Visit/Paginator/Adapter/VisitsForTagPaginatorAdapterTest.php index 3a92c8d3..a9aec03f 100644 --- a/module/Core/test/Visit/Paginator/Adapter/VisitsForTagPaginatorAdapterTest.php +++ b/module/Core/test/Visit/Paginator/Adapter/VisitsForTagPaginatorAdapterTest.php @@ -16,7 +16,7 @@ use Shlinkio\Shlink\Rest\Entity\ApiKey; class VisitsForTagPaginatorAdapterTest extends TestCase { - private MockObject $repo; + private MockObject & VisitRepositoryInterface $repo; protected function setUp(): void { diff --git a/module/Core/test/Visit/RequestTrackerTest.php b/module/Core/test/Visit/RequestTrackerTest.php index 495963fb..0e1705ee 100644 --- a/module/Core/test/Visit/RequestTrackerTest.php +++ b/module/Core/test/Visit/RequestTrackerTest.php @@ -23,8 +23,8 @@ class RequestTrackerTest extends TestCase private const LONG_URL = 'https://domain.com/foo/bar?some=thing'; private RequestTracker $requestTracker; - private MockObject $notFoundType; - private MockObject $visitsTracker; + private MockObject & VisitsTrackerInterface $visitsTracker; + private MockObject & NotFoundType $notFoundType; private ServerRequestInterface $request; protected function setUp(): void diff --git a/module/Core/test/Visit/VisitsStatsHelperTest.php b/module/Core/test/Visit/VisitsStatsHelperTest.php index 4f3ffee2..8afd56db 100644 --- a/module/Core/test/Visit/VisitsStatsHelperTest.php +++ b/module/Core/test/Visit/VisitsStatsHelperTest.php @@ -38,7 +38,7 @@ class VisitsStatsHelperTest extends TestCase use ApiKeyHelpersTrait; private VisitsStatsHelper $helper; - private MockObject $em; + private MockObject & EntityManagerInterface $em; protected function setUp(): void { diff --git a/module/Core/test/Visit/VisitsTrackerTest.php b/module/Core/test/Visit/VisitsTrackerTest.php index abdf8fb3..d981f755 100644 --- a/module/Core/test/Visit/VisitsTrackerTest.php +++ b/module/Core/test/Visit/VisitsTrackerTest.php @@ -17,8 +17,8 @@ use Shlinkio\Shlink\Core\Visit\VisitsTracker; class VisitsTrackerTest extends TestCase { - private MockObject $em; - private MockObject $eventDispatcher; + private MockObject & EntityManager $em; + private MockObject & EventDispatcherInterface $eventDispatcher; protected function setUp(): void { diff --git a/module/Rest/test/Action/Domain/DomainRedirectsActionTest.php b/module/Rest/test/Action/Domain/DomainRedirectsActionTest.php index a620ee01..5ff409a0 100644 --- a/module/Rest/test/Action/Domain/DomainRedirectsActionTest.php +++ b/module/Rest/test/Action/Domain/DomainRedirectsActionTest.php @@ -21,7 +21,7 @@ use function array_key_exists; class DomainRedirectsActionTest extends TestCase { private DomainRedirectsAction $action; - private MockObject $domainService; + private MockObject & DomainServiceInterface $domainService; protected function setUp(): void { diff --git a/module/Rest/test/Action/Domain/ListDomainsActionTest.php b/module/Rest/test/Action/Domain/ListDomainsActionTest.php index 8c7fcc94..ac31cd0e 100644 --- a/module/Rest/test/Action/Domain/ListDomainsActionTest.php +++ b/module/Rest/test/Action/Domain/ListDomainsActionTest.php @@ -19,7 +19,7 @@ use Shlinkio\Shlink\Rest\Entity\ApiKey; class ListDomainsActionTest extends TestCase { private ListDomainsAction $action; - private MockObject $domainService; + private MockObject & DomainServiceInterface $domainService; private NotFoundRedirectOptions $options; protected function setUp(): void diff --git a/module/Rest/test/Action/HealthActionTest.php b/module/Rest/test/Action/HealthActionTest.php index 48289290..4ce00578 100644 --- a/module/Rest/test/Action/HealthActionTest.php +++ b/module/Rest/test/Action/HealthActionTest.php @@ -19,7 +19,7 @@ use Shlinkio\Shlink\Rest\Action\HealthAction; class HealthActionTest extends TestCase { private HealthAction $action; - private MockObject $conn; + private MockObject & Connection $conn; protected function setUp(): void { diff --git a/module/Rest/test/Action/MercureInfoActionTest.php b/module/Rest/test/Action/MercureInfoActionTest.php index f99a8a37..ada836c1 100644 --- a/module/Rest/test/Action/MercureInfoActionTest.php +++ b/module/Rest/test/Action/MercureInfoActionTest.php @@ -15,7 +15,7 @@ use Shlinkio\Shlink\Rest\Exception\MercureException; class MercureInfoActionTest extends TestCase { - private MockObject $provider; + private MockObject & JwtProviderInterface $provider; protected function setUp(): void { diff --git a/module/Rest/test/Action/ShortUrl/CreateShortUrlActionTest.php b/module/Rest/test/Action/ShortUrl/CreateShortUrlActionTest.php index 140f0230..246b2edf 100644 --- a/module/Rest/test/Action/ShortUrl/CreateShortUrlActionTest.php +++ b/module/Rest/test/Action/ShortUrl/CreateShortUrlActionTest.php @@ -22,8 +22,8 @@ use Shlinkio\Shlink\Rest\Entity\ApiKey; class CreateShortUrlActionTest extends TestCase { private CreateShortUrlAction $action; - private MockObject $urlShortener; - private MockObject $transformer; + private MockObject & UrlShortener $urlShortener; + private MockObject & DataTransformerInterface $transformer; protected function setUp(): void { diff --git a/module/Rest/test/Action/ShortUrl/DeleteShortUrlActionTest.php b/module/Rest/test/Action/ShortUrl/DeleteShortUrlActionTest.php index 30a8e647..d68e3608 100644 --- a/module/Rest/test/Action/ShortUrl/DeleteShortUrlActionTest.php +++ b/module/Rest/test/Action/ShortUrl/DeleteShortUrlActionTest.php @@ -14,7 +14,7 @@ use Shlinkio\Shlink\Rest\Entity\ApiKey; class DeleteShortUrlActionTest extends TestCase { private DeleteShortUrlAction $action; - private MockObject $service; + private MockObject & DeleteShortUrlServiceInterface $service; protected function setUp(): void { diff --git a/module/Rest/test/Action/ShortUrl/EditShortUrlActionTest.php b/module/Rest/test/Action/ShortUrl/EditShortUrlActionTest.php index 94f3dbae..dde17ca6 100644 --- a/module/Rest/test/Action/ShortUrl/EditShortUrlActionTest.php +++ b/module/Rest/test/Action/ShortUrl/EditShortUrlActionTest.php @@ -18,7 +18,7 @@ use Shlinkio\Shlink\Rest\Entity\ApiKey; class EditShortUrlActionTest extends TestCase { private EditShortUrlAction $action; - private MockObject $shortUrlService; + private MockObject & ShortUrlServiceInterface $shortUrlService; protected function setUp(): void { diff --git a/module/Rest/test/Action/ShortUrl/ListShortUrlsActionTest.php b/module/Rest/test/Action/ShortUrl/ListShortUrlsActionTest.php index 068677d3..5ccd20ec 100644 --- a/module/Rest/test/Action/ShortUrl/ListShortUrlsActionTest.php +++ b/module/Rest/test/Action/ShortUrl/ListShortUrlsActionTest.php @@ -21,7 +21,7 @@ use Shlinkio\Shlink\Rest\Entity\ApiKey; class ListShortUrlsActionTest extends TestCase { private ListShortUrlsAction $action; - private MockObject $service; + private MockObject & ShortUrlService $service; protected function setUp(): void { diff --git a/module/Rest/test/Action/ShortUrl/ResolveShortUrlActionTest.php b/module/Rest/test/Action/ShortUrl/ResolveShortUrlActionTest.php index 0e91290f..c7d6fd26 100644 --- a/module/Rest/test/Action/ShortUrl/ResolveShortUrlActionTest.php +++ b/module/Rest/test/Action/ShortUrl/ResolveShortUrlActionTest.php @@ -18,7 +18,7 @@ use Shlinkio\Shlink\Rest\Entity\ApiKey; class ResolveShortUrlActionTest extends TestCase { private ResolveShortUrlAction $action; - private MockObject $urlResolver; + private MockObject & ShortUrlResolverInterface $urlResolver; protected function setUp(): void { diff --git a/module/Rest/test/Action/ShortUrl/SingleStepCreateShortUrlActionTest.php b/module/Rest/test/Action/ShortUrl/SingleStepCreateShortUrlActionTest.php index 5e0867e7..14848696 100644 --- a/module/Rest/test/Action/ShortUrl/SingleStepCreateShortUrlActionTest.php +++ b/module/Rest/test/Action/ShortUrl/SingleStepCreateShortUrlActionTest.php @@ -18,7 +18,7 @@ use Shlinkio\Shlink\Rest\Entity\ApiKey; class SingleStepCreateShortUrlActionTest extends TestCase { private SingleStepCreateShortUrlAction $action; - private MockObject $urlShortener; + private MockObject & UrlShortenerInterface $urlShortener; protected function setUp(): void { diff --git a/module/Rest/test/Action/Tag/DeleteTagsActionTest.php b/module/Rest/test/Action/Tag/DeleteTagsActionTest.php index cca532a4..63d30c4b 100644 --- a/module/Rest/test/Action/Tag/DeleteTagsActionTest.php +++ b/module/Rest/test/Action/Tag/DeleteTagsActionTest.php @@ -14,7 +14,7 @@ use Shlinkio\Shlink\Rest\Entity\ApiKey; class DeleteTagsActionTest extends TestCase { private DeleteTagsAction $action; - private MockObject $tagService; + private MockObject & TagServiceInterface $tagService; protected function setUp(): void { diff --git a/module/Rest/test/Action/Tag/ListTagsActionTest.php b/module/Rest/test/Action/Tag/ListTagsActionTest.php index d340c82f..dc4c2c06 100644 --- a/module/Rest/test/Action/Tag/ListTagsActionTest.php +++ b/module/Rest/test/Action/Tag/ListTagsActionTest.php @@ -22,7 +22,7 @@ use function count; class ListTagsActionTest extends TestCase { private ListTagsAction $action; - private MockObject $tagService; + private MockObject & TagServiceInterface $tagService; protected function setUp(): void { diff --git a/module/Rest/test/Action/Tag/TagsStatsActionTest.php b/module/Rest/test/Action/Tag/TagsStatsActionTest.php index 8e0e8e74..0694e7bf 100644 --- a/module/Rest/test/Action/Tag/TagsStatsActionTest.php +++ b/module/Rest/test/Action/Tag/TagsStatsActionTest.php @@ -21,7 +21,7 @@ use function count; class TagsStatsActionTest extends TestCase { private TagsStatsAction $action; - private MockObject $tagService; + private MockObject & TagServiceInterface $tagService; protected function setUp(): void { diff --git a/module/Rest/test/Action/Tag/UpdateTagActionTest.php b/module/Rest/test/Action/Tag/UpdateTagActionTest.php index d1424849..d08d00e2 100644 --- a/module/Rest/test/Action/Tag/UpdateTagActionTest.php +++ b/module/Rest/test/Action/Tag/UpdateTagActionTest.php @@ -18,7 +18,7 @@ use Shlinkio\Shlink\Rest\Entity\ApiKey; class UpdateTagActionTest extends TestCase { private UpdateTagAction $action; - private MockObject $tagService; + private MockObject & TagServiceInterface $tagService; protected function setUp(): void { diff --git a/module/Rest/test/Action/Visit/DomainVisitsActionTest.php b/module/Rest/test/Action/Visit/DomainVisitsActionTest.php index b56f557b..e4b714e4 100644 --- a/module/Rest/test/Action/Visit/DomainVisitsActionTest.php +++ b/module/Rest/test/Action/Visit/DomainVisitsActionTest.php @@ -17,7 +17,7 @@ use Shlinkio\Shlink\Rest\Entity\ApiKey; class DomainVisitsActionTest extends TestCase { private DomainVisitsAction $action; - private MockObject $visitsHelper; + private MockObject & VisitsStatsHelperInterface $visitsHelper; protected function setUp(): void { diff --git a/module/Rest/test/Action/Visit/GlobalVisitsActionTest.php b/module/Rest/test/Action/Visit/GlobalVisitsActionTest.php index 87830cb5..bd078eaa 100644 --- a/module/Rest/test/Action/Visit/GlobalVisitsActionTest.php +++ b/module/Rest/test/Action/Visit/GlobalVisitsActionTest.php @@ -16,7 +16,7 @@ use Shlinkio\Shlink\Rest\Entity\ApiKey; class GlobalVisitsActionTest extends TestCase { private GlobalVisitsAction $action; - private MockObject $helper; + private MockObject & VisitsStatsHelperInterface $helper; protected function setUp(): void { diff --git a/module/Rest/test/Action/Visit/NonOrphanVisitsActionTest.php b/module/Rest/test/Action/Visit/NonOrphanVisitsActionTest.php index 4cf6d8a2..9065d318 100644 --- a/module/Rest/test/Action/Visit/NonOrphanVisitsActionTest.php +++ b/module/Rest/test/Action/Visit/NonOrphanVisitsActionTest.php @@ -18,7 +18,7 @@ use Shlinkio\Shlink\Rest\Entity\ApiKey; class NonOrphanVisitsActionTest extends TestCase { private NonOrphanVisitsAction $action; - private MockObject $visitsHelper; + private MockObject & VisitsStatsHelperInterface $visitsHelper; protected function setUp(): void { diff --git a/module/Rest/test/Action/Visit/OrphanVisitsActionTest.php b/module/Rest/test/Action/Visit/OrphanVisitsActionTest.php index 7ad77425..6facfb1c 100644 --- a/module/Rest/test/Action/Visit/OrphanVisitsActionTest.php +++ b/module/Rest/test/Action/Visit/OrphanVisitsActionTest.php @@ -22,8 +22,8 @@ use function count; class OrphanVisitsActionTest extends TestCase { private OrphanVisitsAction $action; - private MockObject $visitsHelper; - private MockObject $orphanVisitTransformer; + private MockObject & VisitsStatsHelperInterface $visitsHelper; + private MockObject & DataTransformerInterface $orphanVisitTransformer; protected function setUp(): void { diff --git a/module/Rest/test/Action/Visit/ShortUrlVisitsActionTest.php b/module/Rest/test/Action/Visit/ShortUrlVisitsActionTest.php index 8302dd27..b9c92d6c 100644 --- a/module/Rest/test/Action/Visit/ShortUrlVisitsActionTest.php +++ b/module/Rest/test/Action/Visit/ShortUrlVisitsActionTest.php @@ -21,7 +21,7 @@ use Shlinkio\Shlink\Rest\Entity\ApiKey; class ShortUrlVisitsActionTest extends TestCase { private ShortUrlVisitsAction $action; - private MockObject $visitsHelper; + private MockObject & VisitsStatsHelperInterface $visitsHelper; protected function setUp(): void { diff --git a/module/Rest/test/Action/Visit/TagVisitsActionTest.php b/module/Rest/test/Action/Visit/TagVisitsActionTest.php index fd924d17..1d5b9447 100644 --- a/module/Rest/test/Action/Visit/TagVisitsActionTest.php +++ b/module/Rest/test/Action/Visit/TagVisitsActionTest.php @@ -17,7 +17,7 @@ use Shlinkio\Shlink\Rest\Entity\ApiKey; class TagVisitsActionTest extends TestCase { private TagVisitsAction $action; - private MockObject $visitsHelper; + private MockObject & VisitsStatsHelperInterface $visitsHelper; protected function setUp(): void { diff --git a/module/Rest/test/Middleware/CrossDomainMiddlewareTest.php b/module/Rest/test/Middleware/CrossDomainMiddlewareTest.php index e9b294da..de87f34f 100644 --- a/module/Rest/test/Middleware/CrossDomainMiddlewareTest.php +++ b/module/Rest/test/Middleware/CrossDomainMiddlewareTest.php @@ -14,7 +14,7 @@ use Shlinkio\Shlink\Rest\Middleware\CrossDomainMiddleware; class CrossDomainMiddlewareTest extends TestCase { private CrossDomainMiddleware $middleware; - private MockObject $handler; + private MockObject & RequestHandlerInterface $handler; protected function setUp(): void { diff --git a/module/Rest/test/Middleware/Mercure/NotConfiguredMercureErrorHandlerTest.php b/module/Rest/test/Middleware/Mercure/NotConfiguredMercureErrorHandlerTest.php index 9fe595ec..4f576d7d 100644 --- a/module/Rest/test/Middleware/Mercure/NotConfiguredMercureErrorHandlerTest.php +++ b/module/Rest/test/Middleware/Mercure/NotConfiguredMercureErrorHandlerTest.php @@ -17,9 +17,9 @@ use Shlinkio\Shlink\Rest\Middleware\Mercure\NotConfiguredMercureErrorHandler; class NotConfiguredMercureErrorHandlerTest extends TestCase { private NotConfiguredMercureErrorHandler $middleware; - private MockObject $respFactory; - private MockObject $logger; - private MockObject $handler; + private MockObject & ProblemDetailsResponseFactory $respFactory; + private MockObject & LoggerInterface $logger; + private MockObject & RequestHandlerInterface $handler; protected function setUp(): void { diff --git a/module/Rest/test/Middleware/ShortUrl/CreateShortUrlContentNegotiationMiddlewareTest.php b/module/Rest/test/Middleware/ShortUrl/CreateShortUrlContentNegotiationMiddlewareTest.php index 1e56d690..58a3f34d 100644 --- a/module/Rest/test/Middleware/ShortUrl/CreateShortUrlContentNegotiationMiddlewareTest.php +++ b/module/Rest/test/Middleware/ShortUrl/CreateShortUrlContentNegotiationMiddlewareTest.php @@ -16,7 +16,7 @@ use Shlinkio\Shlink\Rest\Middleware\ShortUrl\CreateShortUrlContentNegotiationMid class CreateShortUrlContentNegotiationMiddlewareTest extends TestCase { private CreateShortUrlContentNegotiationMiddleware $middleware; - private MockObject $requestHandler; + private MockObject & RequestHandlerInterface $requestHandler; protected function setUp(): void { diff --git a/module/Rest/test/Middleware/ShortUrl/DefaultShortCodesLengthMiddlewareTest.php b/module/Rest/test/Middleware/ShortUrl/DefaultShortCodesLengthMiddlewareTest.php index f7a647b1..d8fb3092 100644 --- a/module/Rest/test/Middleware/ShortUrl/DefaultShortCodesLengthMiddlewareTest.php +++ b/module/Rest/test/Middleware/ShortUrl/DefaultShortCodesLengthMiddlewareTest.php @@ -17,7 +17,7 @@ use Shlinkio\Shlink\Rest\Middleware\ShortUrl\DefaultShortCodesLengthMiddleware; class DefaultShortCodesLengthMiddlewareTest extends TestCase { private DefaultShortCodesLengthMiddleware $middleware; - private MockObject $handler; + private MockObject & RequestHandlerInterface $handler; protected function setUp(): void { @@ -34,7 +34,7 @@ class DefaultShortCodesLengthMiddlewareTest extends TestCase $request = ServerRequestFactory::fromGlobals()->withParsedBody($body); $this->handler->expects($this->once())->method('handle')->with($this->callback( function (ServerRequestInterface $req) use ($expectedLength) { - $parsedBody = $req->getParsedBody(); + $parsedBody = (array) $req->getParsedBody(); Assert::assertArrayHasKey(ShortUrlInputFilter::SHORT_CODE_LENGTH, $parsedBody); Assert::assertEquals($expectedLength, $parsedBody[ShortUrlInputFilter::SHORT_CODE_LENGTH]); diff --git a/module/Rest/test/Middleware/ShortUrl/DropDefaultDomainFromRequestMiddlewareTest.php b/module/Rest/test/Middleware/ShortUrl/DropDefaultDomainFromRequestMiddlewareTest.php index eb018ad3..1af34a48 100644 --- a/module/Rest/test/Middleware/ShortUrl/DropDefaultDomainFromRequestMiddlewareTest.php +++ b/module/Rest/test/Middleware/ShortUrl/DropDefaultDomainFromRequestMiddlewareTest.php @@ -16,7 +16,7 @@ use Shlinkio\Shlink\Rest\Middleware\ShortUrl\DropDefaultDomainFromRequestMiddlew class DropDefaultDomainFromRequestMiddlewareTest extends TestCase { private DropDefaultDomainFromRequestMiddleware $middleware; - private MockObject $next; + private MockObject & RequestHandlerInterface $next; protected function setUp(): void { diff --git a/module/Rest/test/Middleware/ShortUrl/OverrideDomainMiddlewareTest.php b/module/Rest/test/Middleware/ShortUrl/OverrideDomainMiddlewareTest.php index f4f0b4d1..ad558abf 100644 --- a/module/Rest/test/Middleware/ShortUrl/OverrideDomainMiddlewareTest.php +++ b/module/Rest/test/Middleware/ShortUrl/OverrideDomainMiddlewareTest.php @@ -21,9 +21,9 @@ use Shlinkio\Shlink\Rest\Middleware\ShortUrl\OverrideDomainMiddleware; class OverrideDomainMiddlewareTest extends TestCase { private OverrideDomainMiddleware $middleware; - private MockObject $domainService; - private MockObject $apiKey; - private MockObject $handler; + private MockObject & DomainServiceInterface $domainService; + private MockObject & ApiKey $apiKey; + private MockObject & RequestHandlerInterface $handler; protected function setUp(): void { diff --git a/module/Rest/test/Service/ApiKeyServiceTest.php b/module/Rest/test/Service/ApiKeyServiceTest.php index 9336da9e..a592313d 100644 --- a/module/Rest/test/Service/ApiKeyServiceTest.php +++ b/module/Rest/test/Service/ApiKeyServiceTest.php @@ -19,8 +19,8 @@ use Shlinkio\Shlink\Rest\Service\ApiKeyService; class ApiKeyServiceTest extends TestCase { private ApiKeyService $service; - private MockObject $em; - private MockObject $repo; + private MockObject & EntityManager $em; + private MockObject & EntityRepository $repo; protected function setUp(): void { @@ -50,10 +50,13 @@ class ApiKeyServiceTest extends TestCase public function provideCreationDate(): iterable { + $domain = Domain::withAuthority(''); + $domain->setId('123'); + yield 'no expiration date or name' => [null, null, []]; yield 'expiration date' => [Chronos::parse('2030-01-01'), null, []]; yield 'roles' => [null, null, [ - RoleDefinition::forDomain(Domain::withAuthority('')->setId('123')), + RoleDefinition::forDomain($domain), RoleDefinition::forAuthoredShortUrls(), ]]; yield 'single name' => [null, 'Alice', []]; diff --git a/phpstan.neon b/phpstan.neon index aa5dab08..eee4853b 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,6 +1,8 @@ includes: - vendor/phpstan/phpstan-doctrine/extension.neon - vendor/phpstan/phpstan-symfony/extension.neon + - vendor/phpstan/phpstan-phpunit/extension.neon + - vendor/phpstan/phpstan-phpunit/rules.neon parameters: checkMissingIterableValueType: false checkGenericClassInNonGenericObjectType: false