diff --git a/module/CLI/test/Command/ShortUrl/CreateShortUrlCommandTest.php b/module/CLI/test/Command/ShortUrl/CreateShortUrlCommandTest.php index 805dc253..b9367ddc 100644 --- a/module/CLI/test/Command/ShortUrl/CreateShortUrlCommandTest.php +++ b/module/CLI/test/Command/ShortUrl/CreateShortUrlCommandTest.php @@ -50,7 +50,7 @@ class CreateShortUrlCommandTest extends TestCase $this->urlShortener->expects($this->once())->method('shorten')->withAnyParameters()->willReturn( UrlShorteningResult::withoutErrorOnEventDispatching($shortUrl), ); - $this->stringifier->method('stringify')->with($shortUrl)->willReturn('stringified_short_url'); + $this->stringifier->method('stringify')->willReturnMap([[$shortUrl, 'stringified_short_url']]); $this->commandTester->execute([ 'long-url' => 'http://domain.com/foo/bar', @@ -70,7 +70,7 @@ class CreateShortUrlCommandTest extends TestCase $this->urlShortener->expects($this->once())->method('shorten')->withAnyParameters()->willReturn( UrlShorteningResult::withoutErrorOnEventDispatching($shortUrl), ); - $this->stringifier->method('stringify')->with($shortUrl)->willReturn('stringified_short_url'); + $this->stringifier->method('stringify')->willReturnMap([[$shortUrl, 'stringified_short_url']]); $this->commandTester->setInputs([$shortUrl->getLongUrl()]); $this->commandTester->execute([]); @@ -101,7 +101,7 @@ class CreateShortUrlCommandTest extends TestCase return true; }), )->willReturn(UrlShorteningResult::withoutErrorOnEventDispatching($shortUrl)); - $this->stringifier->method('stringify')->with($shortUrl)->willReturn('stringified_short_url'); + $this->stringifier->method('stringify')->willReturnMap([[$shortUrl, 'stringified_short_url']]); $this->commandTester->execute([ 'long-url' => 'http://domain.com/foo/bar', diff --git a/module/CLI/test/RedirectRule/RedirectRuleHandlerTest.php b/module/CLI/test/RedirectRule/RedirectRuleHandlerTest.php index fce94954..cc55dbd0 100644 --- a/module/CLI/test/RedirectRule/RedirectRuleHandlerTest.php +++ b/module/CLI/test/RedirectRule/RedirectRuleHandlerTest.php @@ -113,7 +113,7 @@ class RedirectRuleHandlerTest extends TestCase array $expectedConditions, bool $continue = false, ): void { - $this->io->expects($this->any())->method('ask')->willReturnCallback( + $this->io->method('ask')->willReturnCallback( fn (string $message): string|int => match ($message) { 'Rule priority (the lower the value, the higher the priority)' => 2, // Add in between existing rules 'Long URL to redirect when the rule matches' => 'https://example.com/new-two', @@ -127,7 +127,7 @@ class RedirectRuleHandlerTest extends TestCase default => '', }, ); - $this->io->expects($this->any())->method('choice')->willReturnCallback( + $this->io->method('choice')->willReturnCallback( function (string $message) use (&$callIndex, $type): string { $callIndex++; @@ -241,7 +241,7 @@ class RedirectRuleHandlerTest extends TestCase #[Test] public function existingRulesCanBeReArranged(): void { - $this->io->expects($this->any())->method('ask')->willReturnCallback( + $this->io->method('ask')->willReturnCallback( fn (string $message): string|int => match ($message) { 'Rule priority (the lower the value, the higher the priority)' => 1, default => '', diff --git a/module/CLI/test/Util/CliTestUtils.php b/module/CLI/test/Util/CliTestUtils.php index 2e0e642b..02c6c9da 100644 --- a/module/CLI/test/Util/CliTestUtils.php +++ b/module/CLI/test/Util/CliTestUtils.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace ShlinkioTest\Shlink\CLI\Util; -use PHPUnit\Framework\Assert; use PHPUnit\Framework\MockObject\Generator\Generator; use PHPUnit\Framework\MockObject\Stub; use Symfony\Component\Console\Application; @@ -32,7 +31,6 @@ class CliTestUtils $command->method('isEnabled')->willReturn(true); $command->method('getAliases')->willReturn([]); $command->method('getDefinition')->willReturn(new InputDefinition()); - $command->method('setApplication')->with(Assert::isInstanceOf(Application::class)); return $command; } diff --git a/module/Core/test/Domain/DomainServiceTest.php b/module/Core/test/Domain/DomainServiceTest.php index 1677022a..980d5a4c 100644 --- a/module/Core/test/Domain/DomainServiceTest.php +++ b/module/Core/test/Domain/DomainServiceTest.php @@ -111,7 +111,7 @@ class DomainServiceTest extends TestCase #[Test, AllowMockObjectsWithoutExpectations] public function getDomainThrowsExceptionWhenDomainIsNotFound(): void { - $this->em->method('find')->with(Domain::class, '123')->willReturn(null); + $this->em->method('find')->willReturnMap([[Domain::class, '123', null]]); $this->expectException(DomainNotFoundException::class); @@ -122,7 +122,7 @@ class DomainServiceTest extends TestCase public function getDomainReturnsEntityWhenFound(): void { $domain = Domain::withAuthority(''); - $this->em->method('find')->with(Domain::class, '123')->willReturn($domain); + $this->em->method('find')->willReturnMap([[Domain::class, '123', $domain]]); $result = $this->domainService->getDomain('123'); @@ -136,7 +136,6 @@ class DomainServiceTest extends TestCase $this->repo->expects($this->once())->method('findOneByAuthority')->with($authority, $apiKey)->willReturn( $foundDomain, ); - $this->em->method('persist')->with($foundDomain ?? $this->isInstanceOf(Domain::class)); $result = $this->domainService->getOrCreate($authority, $apiKey); @@ -168,7 +167,6 @@ class DomainServiceTest extends TestCase $this->repo->expects($this->once())->method('findOneByAuthority')->with($authority, $apiKey)->willReturn( $foundDomain, ); - $this->em->method('persist')->with($foundDomain ?? $this->isInstanceOf(Domain::class)); $result = $this->domainService->configureNotFoundRedirects($authority, NotFoundRedirects::withRedirects( 'foo.com', diff --git a/module/Core/test/Importer/ImportedLinksProcessorTest.php b/module/Core/test/Importer/ImportedLinksProcessorTest.php index ac82e1a4..f87dc723 100644 --- a/module/Core/test/Importer/ImportedLinksProcessorTest.php +++ b/module/Core/test/Importer/ImportedLinksProcessorTest.php @@ -229,7 +229,7 @@ class ImportedLinksProcessorTest extends TestCase $this->em->expects($this->exactly($amountOfPersistedVisits + ($foundShortUrl === null ? 1 : 0)))->method( 'persist', )->with($this->callback(fn (object $arg) => $arg instanceof ShortUrl || $arg instanceof Visit)); - $this->em->expects($this->any())->method('find')->willReturn(null); + $this->em->method('find')->willReturn(null); $this->io->expects($this->once())->method('text')->with($this->stringContains($expectedOutput)); $this->processor->process($this->io, ImportResult::withShortUrls([$importedUrl]), $this->buildParams()); diff --git a/module/Core/test/Matomo/MatomoVisitSenderTest.php b/module/Core/test/Matomo/MatomoVisitSenderTest.php index 0693f8aa..9655d3a4 100644 --- a/module/Core/test/Matomo/MatomoVisitSenderTest.php +++ b/module/Core/test/Matomo/MatomoVisitSenderTest.php @@ -116,15 +116,12 @@ class MatomoVisitSenderTest extends TestCase #[Test, DataProvider('provideUrlsToTrack')] public function properUrlIsTracked(Visit $visit, string $expectedTrackedUrl): void { - $tracker = $this->createMock(MatomoTracker::class); - $tracker->expects($this->once())->method('setUrl')->with($expectedTrackedUrl)->willReturn($tracker); - $tracker->expects($this->once())->method('setUserAgent')->willReturn($tracker); - $tracker->expects($this->once())->method('setUrlReferrer')->willReturn($tracker); - $tracker->expects($this->any())->method('setCustomTrackingParameter')->willReturn($tracker); - $tracker->expects($this->once())->method('doTrackPageView'); - $tracker->expects($this->once())->method('setForceVisitDateTime')->with( - $visit->date->setTimezone('UTC')->toDateTimeString(), - ); + $tracker = $this->createStub(MatomoTracker::class); + $tracker->method('setUrl')->willReturn($tracker); + $tracker->method('setUserAgent')->willReturn($tracker); + $tracker->method('setUrlReferrer')->willReturn($tracker); + $tracker->method('setCustomTrackingParameter')->willReturn($tracker); + $tracker->method('doTrackPageView'); $this->trackerBuilder->expects($this->once())->method('buildMatomoTracker')->willReturn($tracker); @@ -156,7 +153,7 @@ class MatomoVisitSenderTest extends TestCase $visitor = Visitor::empty(); $bot = Visitor::botInstance(); - $this->visitIterationRepository->method('findAllVisits')->with($dateRange)->willReturn([ + $this->visitIterationRepository->method('findAllVisits')->willReturn([ Visit::forBasePath($bot), Visit::forValidShortUrl(ShortUrl::createFake(), $visitor), Visit::forInvalidShortUrl($visitor), diff --git a/phpunit-api.xml b/phpunit-api.xml index 7b9eee65..d63fb854 100644 --- a/phpunit-api.xml +++ b/phpunit-api.xml @@ -8,6 +8,7 @@ displayDetailsOnTestsThatTriggerWarnings="true" displayDetailsOnTestsThatTriggerDeprecations="true" displayDetailsOnPhpunitNotices="true" + displayDetailsOnPhpunitDeprecations="true" displayDetailsOnTestsThatTriggerNotices="true" > diff --git a/phpunit-cli.xml b/phpunit-cli.xml index f16b5ad3..a8c153d4 100644 --- a/phpunit-cli.xml +++ b/phpunit-cli.xml @@ -8,6 +8,7 @@ displayDetailsOnTestsThatTriggerWarnings="true" displayDetailsOnTestsThatTriggerDeprecations="true" displayDetailsOnPhpunitNotices="true" + displayDetailsOnPhpunitDeprecations="true" displayDetailsOnTestsThatTriggerNotices="true" > diff --git a/phpunit-db.xml b/phpunit-db.xml index 32d19d4b..6a274b9f 100644 --- a/phpunit-db.xml +++ b/phpunit-db.xml @@ -8,6 +8,7 @@ displayDetailsOnTestsThatTriggerWarnings="true" displayDetailsOnTestsThatTriggerDeprecations="true" displayDetailsOnPhpunitNotices="true" + displayDetailsOnPhpunitDeprecations="true" displayDetailsOnTestsThatTriggerNotices="true" > diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 76df50d3..c19ba8d3 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -8,6 +8,7 @@ displayDetailsOnTestsThatTriggerWarnings="true" displayDetailsOnTestsThatTriggerDeprecations="true" displayDetailsOnPhpunitNotices="true" + displayDetailsOnPhpunitDeprecations="true" displayDetailsOnTestsThatTriggerNotices="true" >