Fix compatibility with PHPUnit 12.0.9 and phpstan-phpunit

This commit is contained in:
Alejandro Celaya
2025-03-24 19:33:52 +01:00
parent b7d9ba8258
commit 87d5f9bc75
6 changed files with 25 additions and 11 deletions

View File

@@ -70,6 +70,9 @@ class NotifyVisitToRabbitMqTest extends TestCase
($this->listener())(new UrlVisited($visitId));
}
/**
* @param non-empty-string[] $expectedChannels
*/
#[Test, DataProvider('provideVisits')]
public function expectedChannelsAreNotifiedBasedOnTheVisitType(Visit $visit, array $expectedChannels): void
{

View File

@@ -118,6 +118,9 @@ class IpGeolocationMiddlewareTest extends TestCase
$this->middleware()->process($request, $this->handler);
}
/**
* @param non-empty-string $loggerMethod
*/
#[Test]
#[TestWith([
new WrongIpException(),

View File

@@ -24,6 +24,8 @@ use Shlinkio\Shlink\Core\Visit\Model\Visitor;
use Shlinkio\Shlink\Core\Visit\Repository\VisitIterationRepositoryInterface;
use Shlinkio\Shlink\IpGeolocation\Model\Location;
use function array_values;
class MatomoVisitSenderTest extends TestCase
{
private MockObject & MatomoTrackerBuilderInterface $trackerBuilder;
@@ -42,10 +44,10 @@ class MatomoVisitSenderTest extends TestCase
);
}
#[Test, DataProvider('provideTrackerMethods')]
/**
* @param array<string, string[]> $invokedMethods
* @param array<non-empty-string, string[]> $invokedMethods
*/
#[Test, DataProvider('provideTrackerMethods')]
public function visitIsSentToMatomo(Visit $visit, string|null $originalIpAddress, array $invokedMethods): void
{
$tracker = $this->createMock(MatomoTracker::class);
@@ -70,7 +72,9 @@ class MatomoVisitSenderTest extends TestCase
}
foreach ($invokedMethods as $invokedMethod => $args) {
$tracker->expects($this->once())->method($invokedMethod)->with(...$args)->willReturn($tracker);
$tracker->expects($this->once())->method($invokedMethod)->with(...array_values($args))->willReturn(
$tracker,
);
}
$this->trackerBuilder->expects($this->once())->method('buildMatomoTracker')->willReturn($tracker);

View File

@@ -13,7 +13,7 @@ use Laminas\Diactoros\Response\JsonResponse;
use Laminas\Diactoros\Stream;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\Attributes\TestWith;
use PHPUnit\Framework\MockObject\Builder\InvocationMocker;
use PHPUnit\Framework\MockObject\InvocationStubber;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
@@ -152,9 +152,8 @@ class ShortUrlTitleResolutionHelperTest extends TestCase
}
/**
* @return InvocationMocker<ClientInterface>
*/
private function expectRequestToBeCalled(): InvocationMocker
private function expectRequestToBeCalled(): InvocationStubber
{
return $this->httpClient->expects($this->once())->method('request')->with(
RequestMethodInterface::METHOD_GET,

View File

@@ -40,6 +40,9 @@ class VisitLocatorTest extends TestCase
$this->visitService = new VisitLocator($this->em, $this->repo);
}
/**
* @param non-empty-string $expectedRepoMethodName
*/
#[Test, DataProvider('provideMethodNames')]
public function locateVisitsIteratesAndLocatesExpectedVisits(
string $serviceMethodName,
@@ -80,6 +83,9 @@ class VisitLocatorTest extends TestCase
yield 'locateAllVisits' => ['locateAllVisits', 'findAllVisits'];
}
/**
* @param non-empty-string $expectedRepoMethodName
*/
#[Test, DataProvider('provideIsNonLocatableAddress')]
public function visitsWhichCannotBeLocatedAreIgnoredOrLocatedAsEmpty(
string $serviceMethodName,