diff --git a/composer.json b/composer.json index cdf2c42e..f9c68dbb 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..9f2ec2aa 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 { @@ -38,7 +38,7 @@ class RoleResolverTest extends TestCase ): void { $this->domainService->expects($this->exactly($expectedDomainCalls))->method('getOrCreate')->with( 'example.com', - )->willReturn(Domain::withAuthority('example.com')->setId('1')); + )->willReturn($this->domainWithId(Domain::withAuthority('example.com'))); $result = $this->resolver->determineRoles($input); @@ -47,7 +47,7 @@ class RoleResolverTest extends TestCase public function provideRoles(): iterable { - $domain = Domain::withAuthority('example.com')->setId('1'); + $domain = $this->domainWithId(Domain::withAuthority('example.com')); $buildInput = function (array $definition): InputInterface { $input = $this->createStub(InputInterface::class); $input->method('getOption')->willReturnMap( @@ -113,4 +113,10 @@ class RoleResolverTest extends TestCase $this->resolver->determineRoles($input); } + + private function domainWithId(Domain $domain): Domain + { + $domain->setId('1'); + return $domain; + } } 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..f4101ec6 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 { @@ -86,12 +86,12 @@ class ListKeysCommandTest extends TestCase $apiKey1 = ApiKey::create(), $apiKey2 = $this->apiKeyWithRoles([RoleDefinition::forAuthoredShortUrls()]), $apiKey3 = $this->apiKeyWithRoles( - [RoleDefinition::forDomain(Domain::withAuthority('example.com')->setId('1'))], + [RoleDefinition::forDomain($this->domainWithId(Domain::withAuthority('example.com')))], ), $apiKey4 = ApiKey::create(), $apiKey5 = $this->apiKeyWithRoles([ RoleDefinition::forAuthoredShortUrls(), - RoleDefinition::forDomain(Domain::withAuthority('example.com')->setId('1')), + RoleDefinition::forDomain($this->domainWithId(Domain::withAuthority('example.com'))), ]), $apiKey6 = ApiKey::create(), ], @@ -150,4 +150,10 @@ class ListKeysCommandTest extends TestCase return $apiKey; } + + private function domainWithId(Domain $domain): Domain + { + $domain->setId('1'); + return $domain; + } } 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/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/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..734089c9 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,18 +26,21 @@ 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( $this->urlShortener, $this->stringifier, - new UrlShortenerOptions(domain: ['hostname' => self::DEFAULT_DOMAIN], defaultShortCodesLength: 5), + new UrlShortenerOptions( + domain: ['hostname' => self::DEFAULT_DOMAIN, 'schema' => ''], + defaultShortCodesLength: 5, + ), ); $this->commandTester = $this->testerForCommand($command); } 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/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/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/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/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/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/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/GeoLite/GeolocationDbUpdaterTest.php b/module/CLI/test/GeoLite/GeolocationDbUpdaterTest.php index 0b890e46..8d6188e9 100644 --- a/module/CLI/test/GeoLite/GeolocationDbUpdaterTest.php +++ b/module/CLI/test/GeoLite/GeolocationDbUpdaterTest.php @@ -23,16 +23,14 @@ 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 { $this->dbUpdater = $this->createMock(DbUpdaterInterface::class); $this->geoLiteDbReader = $this->createMock(Reader::class); - $this->trackingOptions = new TrackingOptions(); - $this->lock = $this->createMock(Lock\LockInterface::class); $this->lock->method('acquire')->with($this->isTrue())->willReturn(true); } 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-db/Tag/Paginator/Adapter/TagsPaginatorAdapterTest.php b/module/Core/test-db/Tag/Paginator/Adapter/TagsPaginatorAdapterTest.php index 849b768f..385f2335 100644 --- a/module/Core/test-db/Tag/Paginator/Adapter/TagsPaginatorAdapterTest.php +++ b/module/Core/test-db/Tag/Paginator/Adapter/TagsPaginatorAdapterTest.php @@ -22,6 +22,8 @@ class TagsPaginatorAdapterTest extends DatabaseTestCase } /** + * @param int<0, max> $offset + * @param int<0, max> $length * @test * @dataProvider provideFilters */ diff --git a/module/Core/test-db/Visit/Repository/VisitRepositoryTest.php b/module/Core/test-db/Visit/Repository/VisitRepositoryTest.php index 0eaa87e1..25512f15 100644 --- a/module/Core/test-db/Visit/Repository/VisitRepositoryTest.php +++ b/module/Core/test-db/Visit/Repository/VisitRepositoryTest.php @@ -213,7 +213,6 @@ class VisitRepositoryTest extends DatabaseTestCase { $foo = 'foo'; - /** @var ShortUrl $shortUrl */ $this->createShortUrlsAndVisits(false, [$foo]); $this->getEntityManager()->flush(); 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..89c105c0 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 { @@ -115,8 +115,10 @@ class QrCodeActionTest extends TestCase $delegate = $this->createMock(RequestHandlerInterface::class); $resp = $this->action($defaultOptions)->process($req->withAttribute('shortCode', $code), $delegate); - [$size] = getimagesizefromstring($resp->getBody()->__toString()); + $result = getimagesizefromstring($resp->getBody()->__toString()); + self::assertNotFalse($result); + [$size] = $result; self::assertEquals($expectedSize, $size); } @@ -207,8 +209,9 @@ class QrCodeActionTest extends TestCase $resp = $this->action($defaultOptions)->process($req, $delegate); $image = imagecreatefromstring($resp->getBody()->__toString()); - $color = imagecolorat($image, 1, 1); + self::assertNotFalse($image); + $color = imagecolorat($image, 1, 1); self::assertEquals($color, $expectedColor); } 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..46d3e567 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 { @@ -48,8 +48,10 @@ class DomainServiceTest extends TestCase { $default = DomainItem::forDefaultDomain('default.com', new EmptyNotFoundRedirectConfig()); $adminApiKey = ApiKey::create(); + $domain = Domain::withAuthority(''); + $domain->setId('123'); $domainSpecificApiKey = ApiKey::fromMeta( - ApiKeyMeta::withRoles(RoleDefinition::forDomain(Domain::withAuthority('')->setId('123'))), + ApiKeyMeta::withRoles(RoleDefinition::forDomain($domain)), ); yield 'empty list without API key' => [[], [$default], null]; @@ -147,7 +149,8 @@ class DomainServiceTest extends TestCase public function getOrCreateThrowsExceptionForApiKeysWithDomainRole(): void { $authority = 'example.com'; - $domain = Domain::withAuthority($authority)->setId('1'); + $domain = Domain::withAuthority($authority); + $domain->setId('1'); $apiKey = ApiKey::fromMeta(ApiKeyMeta::withRoles(RoleDefinition::forDomain($domain))); $repo = $this->createMock(DomainRepositoryInterface::class); $repo->method('findOneByAuthority')->with($authority, $apiKey)->willReturn(null); 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/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/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/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/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/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/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/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/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/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/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..a39940ae 100644 --- a/module/Core/test/Visit/Geolocation/VisitLocatorTest.php +++ b/module/Core/test/Visit/Geolocation/VisitLocatorTest.php @@ -6,7 +6,6 @@ namespace ShlinkioTest\Shlink\Core\Visit\Geolocation; use Doctrine\ORM\EntityManager; use Exception; -use PHPUnit\Framework\Assert; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Shlinkio\Shlink\Core\Exception\IpCannotBeLocatedException; @@ -19,10 +18,8 @@ use Shlinkio\Shlink\Core\Visit\Model\Visitor; use Shlinkio\Shlink\Core\Visit\Repository\VisitRepositoryInterface; use Shlinkio\Shlink\IpGeolocation\Model\Location; -use function array_shift; use function count; use function floor; -use function func_get_args; use function Functional\map; use function range; use function sprintf; @@ -30,8 +27,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 { @@ -72,10 +69,6 @@ class VisitLocatorTest extends TestCase public function onVisitLocated(VisitLocation $visitLocation, Visit $visit): void { - $args = func_get_args(); - - Assert::assertInstanceOf(VisitLocation::class, array_shift($args)); - Assert::assertInstanceOf(Visit::class, array_shift($args)); } }); } 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/Core/test/Visit/Paginator/Adapter/NonOrphanVisitsPaginatorAdapterTest.php b/module/Core/test/Visit/Paginator/Adapter/NonOrphanVisitsPaginatorAdapterTest.php index 1bd03109..ec256eeb 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; @@ -45,6 +45,8 @@ class NonOrphanVisitsPaginatorAdapterTest extends TestCase } /** + * @param int<0, max> $limit + * @param int<0, max> $offset * @test * @dataProvider provideLimitAndOffset */ diff --git a/module/Core/test/Visit/Paginator/Adapter/OrphanVisitsPaginatorAdapterTest.php b/module/Core/test/Visit/Paginator/Adapter/OrphanVisitsPaginatorAdapterTest.php index adad4322..6b91a20b 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 @@ -41,6 +41,8 @@ class OrphanVisitsPaginatorAdapterTest extends TestCase } /** + * @param int<0, max> $limit + * @param int<0, max> $offset * @test * @dataProvider provideLimitAndOffset */ 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-api/Action/CreateShortUrlTest.php b/module/Rest/test-api/Action/CreateShortUrlTest.php index 26d271f0..889b67af 100644 --- a/module/Rest/test-api/Action/CreateShortUrlTest.php +++ b/module/Rest/test-api/Action/CreateShortUrlTest.php @@ -363,7 +363,7 @@ class CreateShortUrlTest extends ApiTestCase } /** - * @return array{int $statusCode, array $payload} + * @return array{int, array} */ private function createShortUrl(array $body = [], string $apiKey = 'valid_api_key', string $version = '2'): array { diff --git a/module/Rest/test-api/Action/EditShortUrlTest.php b/module/Rest/test-api/Action/EditShortUrlTest.php index 92f9bbe0..fefbdcba 100644 --- a/module/Rest/test-api/Action/EditShortUrlTest.php +++ b/module/Rest/test-api/Action/EditShortUrlTest.php @@ -62,13 +62,13 @@ class EditShortUrlTest extends ApiTestCase ]]; } - private function findShortUrlMetaByShortCode(string $shortCode): ?array + private function findShortUrlMetaByShortCode(string $shortCode): array { $matchingShortUrl = $this->getJsonResponsePayload( $this->callApiWithKey(self::METHOD_GET, '/short-urls/' . $shortCode), ); - return $matchingShortUrl['meta'] ?? null; + return $matchingShortUrl['meta'] ?? []; } /** diff --git a/module/Rest/test-api/Fixtures/ShortUrlsFixture.php b/module/Rest/test-api/Fixtures/ShortUrlsFixture.php index a159737e..eadf60ee 100644 --- a/module/Rest/test-api/Fixtures/ShortUrlsFixture.php +++ b/module/Rest/test-api/Fixtures/ShortUrlsFixture.php @@ -23,7 +23,7 @@ class ShortUrlsFixture extends AbstractFixture implements DependentFixtureInterf public function load(ObjectManager $manager): void { - $relationResolver = new PersistenceShortUrlRelationResolver($manager); + $relationResolver = new PersistenceShortUrlRelationResolver($manager); // @phpstan-ignore-line /** @var ApiKey $authorApiKey */ $authorApiKey = $this->getReference('author_api_key'); 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/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/ApiKey/Model/RoleDefinitionTest.php b/module/Rest/test/ApiKey/Model/RoleDefinitionTest.php index 4198aa9b..ac513959 100644 --- a/module/Rest/test/ApiKey/Model/RoleDefinitionTest.php +++ b/module/Rest/test/ApiKey/Model/RoleDefinitionTest.php @@ -23,7 +23,8 @@ class RoleDefinitionTest extends TestCase /** @test */ public function forDomainCreatesRoleDefinitionAsExpected(): void { - $domain = Domain::withAuthority('foo.com')->setId('123'); + $domain = Domain::withAuthority('foo.com'); + $domain->setId('123'); $definition = RoleDefinition::forDomain($domain); self::assertEquals(Role::DOMAIN_SPECIFIC, $definition->role); 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/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/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 */ 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