From 67c27d70437e5e167c65512af3733cb4fc872e95 Mon Sep 17 00:00:00 2001 From: Dawid Parafinski Date: Tue, 15 Sep 2026 11:57:50 +0200 Subject: [PATCH] IBX-12606: Migrated the test suite to PHPUnit 11 --- .gitignore | 2 ++ composer.json | 4 +-- phpunit.xml | 27 ++++++++----------- ...ditionallyRemoveVaryHeaderListenerTest.php | 8 +++--- .../lib/ContextProvider/RoleIdentifyTest.php | 8 +++--- .../PurgeClient/VarnishPurgeClientTest.php | 11 ++++---- .../Delegator/DispatcherTaggerTest.php | 2 +- .../Value/ContentInfoTaggerTest.php | 4 +-- .../Value/LocationTaggerTest.php | 14 +++++----- 9 files changed, 38 insertions(+), 42 deletions(-) diff --git a/.gitignore b/.gitignore index 724bff3..2b7cb20 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ composer.lock .php_cs.cache .php-cs-fixer.cache +.phpunit.cache/ +.phpunit.result.cache diff --git a/composer.json b/composer.json index 6bfce0c..7e69898 100644 --- a/composer.json +++ b/composer.json @@ -35,12 +35,12 @@ "ibexa/code-style": "~2.0.0", "ibexa/doctrine-schema": "~6.0.x-dev", "ibexa/rector": "~6.0.x-dev", - "matthiasnoback/symfony-dependency-injection-test": "^5.0", + "matthiasnoback/symfony-dependency-injection-test": "^6.0", "phpspec/phpspec": "^7.1 || ^8.0", "phpstan/phpstan": "^2.0", "phpstan/phpstan-phpunit": "^2.0", "phpstan/phpstan-symfony": "^2.0", - "phpunit/phpunit": "^9.6", + "phpunit/phpunit": "^11.5", "symfony/phpunit-bridge": "^7.4" }, "autoload": { diff --git a/phpunit.xml b/phpunit.xml index 05e6535..a259cf0 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,20 +1,15 @@ - + + - + - - tests - - - - + + + + + + tests + + diff --git a/tests/bundle/EventListener/ConditionallyRemoveVaryHeaderListenerTest.php b/tests/bundle/EventListener/ConditionallyRemoveVaryHeaderListenerTest.php index 3f75281..7b7b80d 100644 --- a/tests/bundle/EventListener/ConditionallyRemoveVaryHeaderListenerTest.php +++ b/tests/bundle/EventListener/ConditionallyRemoveVaryHeaderListenerTest.php @@ -8,6 +8,7 @@ namespace Ibexa\Tests\Bundle\HttpCache\EventListener; use Ibexa\HttpCache\EventListener\ConditionallyRemoveVaryHeaderListener; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -27,7 +28,7 @@ protected function setUp(): void /** * @return iterable */ - public function onKernelResponseProvider(): iterable + public static function onKernelResponseProvider(): iterable { return [ [ @@ -70,11 +71,10 @@ public function onKernelResponseProvider(): iterable } /** - * @dataProvider onKernelResponseProvider - * * @param string[] $varyHeaders * @param string[] $expectedVaryHeaders */ + #[DataProvider('onKernelResponseProvider')] public function testOnKernelResponse(array $varyHeaders, array $expectedVaryHeaders): void { $request = new Request(); @@ -82,7 +82,7 @@ public function testOnKernelResponse(array $varyHeaders, array $expectedVaryHead $response = new Response('test content', Response::HTTP_OK, ['vary' => $varyHeaders]); - $kernel = $this->createMock(HttpKernelInterface::class); + $kernel = $this->createStub(HttpKernelInterface::class); $event = new ResponseEvent($kernel, $request, HttpKernelInterface::MAIN_REQUEST, $response); $this->conditionallyRemoveVaryHeaderListener->onKernelResponse($event); diff --git a/tests/lib/ContextProvider/RoleIdentifyTest.php b/tests/lib/ContextProvider/RoleIdentifyTest.php index f3f9864..2ba7e6d 100644 --- a/tests/lib/ContextProvider/RoleIdentifyTest.php +++ b/tests/lib/ContextProvider/RoleIdentifyTest.php @@ -36,7 +36,7 @@ protected function setUp(): void $this->repositoryMock = $this ->getMockBuilder(Repository::class) ->disableOriginalConstructor() - ->setMethods(['getRoleService', 'getPermissionResolver']) + ->onlyMethods(['getRoleService', 'getPermissionResolver']) ->getMock(); $this->roleServiceMock = $this->createMock(RoleService::class); @@ -49,8 +49,8 @@ protected function setUp(): void public function testSetIdentity(): void { - $user = $this->createMock(APIUser::class); - $userReference = $this->createMock(UserReference::class); + $user = $this->createStub(APIUser::class); + $userReference = $this->createStub(UserReference::class); $userContext = new UserContext(); $permissionResolver = $this->getPermissionResolverMock(); @@ -175,8 +175,8 @@ protected function getPermissionResolverMock(): PermissionResolver & MockObject { return $this ->getMockBuilder(PermissionResolver::class) - ->setMethods(['getCurrentUserReference']) ->disableOriginalConstructor() + ->onlyMethods(['getCurrentUserReference']) ->getMock(); } diff --git a/tests/lib/PurgeClient/VarnishPurgeClientTest.php b/tests/lib/PurgeClient/VarnishPurgeClientTest.php index 1e5c069..19c37c7 100644 --- a/tests/lib/PurgeClient/VarnishPurgeClientTest.php +++ b/tests/lib/PurgeClient/VarnishPurgeClientTest.php @@ -10,6 +10,7 @@ use FOS\HttpCache\ProxyClient\ProxyClient; use FOS\HttpCacheBundle\CacheManager; use Ibexa\HttpCache\PurgeClient\VarnishPurgeClient; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; @@ -26,8 +27,8 @@ protected function setUp(): void $this->cacheManager = $this->getMockBuilder(CacheManager::class) ->setConstructorArgs( [ - $this->createMock(ProxyClient::class), - $this->createMock( + $this->createStub(ProxyClient::class), + $this->createStub( UrlGeneratorInterface::class ), ] @@ -48,9 +49,7 @@ public function testPurgeNoLocationIds(): void $this->purgeClient->purge([]); } - /** - * @dataProvider purgeTestProvider - */ + #[DataProvider('purgeTestProvider')] public function testPurge(array $locationIds): void { $keys = array_map( @@ -68,7 +67,7 @@ static function ($id): string { $this->purgeClient->purge($keys); } - public function purgeTestProvider(): array + public static function purgeTestProvider(): array { return [ [[123]], diff --git a/tests/lib/ResponseTagger/Delegator/DispatcherTaggerTest.php b/tests/lib/ResponseTagger/Delegator/DispatcherTaggerTest.php index abe672d..f556ed0 100644 --- a/tests/lib/ResponseTagger/Delegator/DispatcherTaggerTest.php +++ b/tests/lib/ResponseTagger/Delegator/DispatcherTaggerTest.php @@ -164,7 +164,7 @@ public function testToStringWithNoTaggers(): void public function testToStringListsRegisteredTaggerTypes(): void { - $fosResponseTagger = $this->createMock(FosResponseTagger::class); + $fosResponseTagger = $this->createStub(FosResponseTagger::class); $dispatcher = new DispatcherTagger([ new ContentInfoTagger($fosResponseTagger), diff --git a/tests/lib/ResponseTagger/Value/ContentInfoTaggerTest.php b/tests/lib/ResponseTagger/Value/ContentInfoTaggerTest.php index 61ec151..fa6e327 100644 --- a/tests/lib/ResponseTagger/Value/ContentInfoTaggerTest.php +++ b/tests/lib/ResponseTagger/Value/ContentInfoTaggerTest.php @@ -61,7 +61,7 @@ public function testTagsWithLocationIdWhenMainLocationIsSet(): void ->expects($matcher) ->method('addTags') ->willReturnCallback(function (array $tags) use ($matcher): ResponseTagger { - if ($matcher->getInvocationCount() === 1) { + if ($matcher->numberOfInvocations() === 1) { self::assertSame( [ ContentTagInterface::CONTENT_PREFIX . '1', @@ -71,7 +71,7 @@ public function testTagsWithLocationIdWhenMainLocationIsSet(): void ); } - if ($matcher->getInvocationCount() === 2) { + if ($matcher->numberOfInvocations() === 2) { self::assertSame( [ ContentTagInterface::LOCATION_PREFIX . '456', diff --git a/tests/lib/ResponseTagger/Value/LocationTaggerTest.php b/tests/lib/ResponseTagger/Value/LocationTaggerTest.php index 63981cf..7aa6e7e 100644 --- a/tests/lib/ResponseTagger/Value/LocationTaggerTest.php +++ b/tests/lib/ResponseTagger/Value/LocationTaggerTest.php @@ -51,15 +51,15 @@ public function testTagsWithLocationIdWhenNotMainLocation(): void ->expects($matcher) ->method('addTags') ->willReturnCallback(function (array $tags) use ($matcher): ResponseTagger { - if ($matcher->getInvocationCount() === 1) { + if ($matcher->numberOfInvocations() === 1) { self::assertSame([ContentTagInterface::LOCATION_PREFIX . '123'], $tags); } - if ($matcher->getInvocationCount() === 2) { + if ($matcher->numberOfInvocations() === 2) { self::assertSame([ContentTagInterface::PARENT_LOCATION_PREFIX . '2'], $tags); } - if ($matcher->getInvocationCount() === 3) { + if ($matcher->numberOfInvocations() === 3) { self::assertSame([ ContentTagInterface::PATH_PREFIX . '1', ContentTagInterface::PATH_PREFIX . '2', @@ -88,11 +88,11 @@ public function testDoesNotTagLocationIdWhenItIsMainLocation(): void ->expects($matcher) ->method('addTags') ->willReturnCallback(function (array $tags) use ($matcher): ResponseTagger { - if ($matcher->getInvocationCount() === 1) { + if ($matcher->numberOfInvocations() === 1) { self::assertSame([ContentTagInterface::PARENT_LOCATION_PREFIX . '2'], $tags); } - if ($matcher->getInvocationCount() === 2) { + if ($matcher->numberOfInvocations() === 2) { self::assertSame([ ContentTagInterface::PATH_PREFIX . '1', ContentTagInterface::PATH_PREFIX . '2', @@ -121,7 +121,7 @@ public function testTagsWithParentLocationId(): void ->expects($matcher) ->method('addTags') ->willReturnCallback(function (array $tags) use ($matcher): ResponseTagger { - if ($matcher->getInvocationCount() === 0) { + if ($matcher->numberOfInvocations() === 0) { self::assertSame([ContentTagInterface::PARENT_LOCATION_PREFIX . '123'], $tags); } @@ -145,7 +145,7 @@ public function testTagsWithPathItems(): void ->expects($matcher) ->method('addTags') ->willReturnCallback(function (array $tags) use ($matcher): ResponseTagger { - if ($matcher->getInvocationCount() === 0) { + if ($matcher->numberOfInvocations() === 0) { self::assertSame([ ContentTagInterface::PATH_PREFIX . '1', ContentTagInterface::PATH_PREFIX . '2',