diff --git a/.gitignore b/.gitignore index cb83629..9370642 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ /composer.lock /.php-cs-fixer.cache /vendor/ +/.phpunit.cache/ +/.phpunit.result.cache diff --git a/composer.json b/composer.json index 79d1239..5390223 100644 --- a/composer.json +++ b/composer.json @@ -9,6 +9,7 @@ "php": ">=8.3", "doctrine/dbal": "^4.4", "ibexa/jms-translation-bundle": "^2.6.1", + "phpunit/phpunit": "^11.5", "symfony/framework-bundle": "^7.4", "symfony/mime": "^7.4", "symfony/options-resolver": "^7.4", @@ -17,8 +18,7 @@ "symfony/yaml": "^7.4" }, "require-dev": { - "phpunit/phpunit": "^9", - "ibexa/code-style": "~2.3.0", + "ibexa/code-style": "^2.0", "ibexa/core": "~6.0.x-dev", "ibexa/core-persistence": "~6.0.x-dev", "ibexa/doctrine-schema": "~6.0.x-dev", @@ -26,7 +26,7 @@ "knplabs/knp-menu": "^3.3", "phpstan/phpstan": "^2.0", "phpstan/phpstan-phpunit": "^2.0", - "symfony/phpunit-bridge": "^5.4" + "symfony/phpunit-bridge": "^7.4" }, "conflict": { "phpstan/phpstan": "2.2.13" diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 2b614ac..6033ae2 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -5,9 +5,3 @@ parameters: identifier: function.alreadyNarrowedType count: 1 path: src/contracts/IbexaTestCore.php - - - - message: '#^Attribute class PHPUnit\\Framework\\Attributes\\DataProvider does not exist\.$#' - identifier: attribute.notFound - count: 1 - path: src/contracts/Translation/AbstractTranslationCase.php diff --git a/phpunit.xml.dist b/phpunit.xml.dist index e3c34c9..b8553a1 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,28 +1,24 @@ - - - - - - - - tests/bundle - - - tests/contracts - - - tests/integration - - - tests/lib - - - - - + + + + + + + + + + + + tests/bundle + + + tests/contracts + + + tests/integration + + + tests/lib + + diff --git a/src/contracts/Menu/Constraint/ContainsPath.php b/src/contracts/Menu/Constraint/ContainsPath.php index 3ff050c..216a330 100644 --- a/src/contracts/Menu/Constraint/ContainsPath.php +++ b/src/contracts/Menu/Constraint/ContainsPath.php @@ -24,7 +24,7 @@ public function __construct(array $path) $this->path = $path; } - protected function matches($other): bool + protected function matches(mixed $other): bool { assert($other instanceof ItemInterface); diff --git a/src/contracts/Translation/AbstractTranslationCase.php b/src/contracts/Translation/AbstractTranslationCase.php index 72c8bc2..790f281 100644 --- a/src/contracts/Translation/AbstractTranslationCase.php +++ b/src/contracts/Translation/AbstractTranslationCase.php @@ -21,9 +21,6 @@ abstract class AbstractTranslationCase extends IbexaKernelTestCase */ abstract public static function provideConfigNamesForTranslation(): iterable; - /** - * @dataProvider provideConfigNamesForTranslation - */ #[DataProvider('provideConfigNamesForTranslation')] final public function testTranslation(string $configName): void { diff --git a/tests/bundle/DependencyInjection/IbexaTestCoreExtensionTest.php b/tests/bundle/DependencyInjection/IbexaTestCoreExtensionTest.php index 1a2a4ab..cfceab1 100644 --- a/tests/bundle/DependencyInjection/IbexaTestCoreExtensionTest.php +++ b/tests/bundle/DependencyInjection/IbexaTestCoreExtensionTest.php @@ -10,12 +10,11 @@ use Ibexa\Bundle\Test\Core\DependencyInjection\IbexaTestCoreExtension; use Ibexa\Test\Core\Bootstrapper\HooksExecutor; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\ContainerBuilder; -/** - * @covers \Ibexa\Bundle\Test\Core\DependencyInjection\IbexaTestCoreExtension - */ +#[CoversClass(IbexaTestCoreExtension::class)] final class IbexaTestCoreExtensionTest extends TestCase { public function testRegistersNoServicesOutsideTheTestEnvironment(): void diff --git a/tests/contracts/Bootstrapper/BootstrapperTest.php b/tests/contracts/Bootstrapper/BootstrapperTest.php index 94a5e01..09b4749 100644 --- a/tests/contracts/Bootstrapper/BootstrapperTest.php +++ b/tests/contracts/Bootstrapper/BootstrapperTest.php @@ -13,15 +13,15 @@ use Ibexa\Contracts\Test\Core\Bootstrapper\HooksExecutorInterface; use Ibexa\Contracts\Test\Core\Bootstrapper\KernelProviderInterface; use Ibexa\Contracts\Test\Core\IbexaTestKernel; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\TestWith; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException; use Symfony\Component\OptionsResolver\OptionsResolver; -/** - * @covers \Ibexa\Contracts\Test\Core\Bootstrapper\Bootstrapper - */ +#[CoversClass(Bootstrapper::class)] final class BootstrapperTest extends TestCase { /** @@ -180,11 +180,10 @@ public function testSkipsKernelShutdownWhenOptedOut(): void } /** - * @testWith [{"some.unknown.key": {}}] - * [{"Ibexa\\Contracts\\Test\\Core\\Bootstrapper\\Bootstrapper": {"some_unknown_option": true}}] - * * @param array $options */ + #[TestWith([['some.unknown.key' => []]])] + #[TestWith([['Ibexa\Contracts\Test\Core\Bootstrapper\Bootstrapper' => ['some_unknown_option' => true]]])] public function testRejectsAnUnrecognizedOptions(array $options): void { $this->expectException(UndefinedOptionsException::class); diff --git a/tests/contracts/Bootstrapper/ConsoleCommandRunnerTest.php b/tests/contracts/Bootstrapper/ConsoleCommandRunnerTest.php index c4e2aa6..d1cff57 100644 --- a/tests/contracts/Bootstrapper/ConsoleCommandRunnerTest.php +++ b/tests/contracts/Bootstrapper/ConsoleCommandRunnerTest.php @@ -9,13 +9,12 @@ namespace Ibexa\Tests\Contracts\Test\Core\Bootstrapper; use Ibexa\Contracts\Test\Core\Bootstrapper\ConsoleCommandRunner; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use RuntimeException; use Symfony\Bundle\FrameworkBundle\Console\Application; -/** - * @covers \Ibexa\Contracts\Test\Core\Bootstrapper\ConsoleCommandRunner - */ +#[CoversClass(ConsoleCommandRunner::class)] final class ConsoleCommandRunnerTest extends TestCase { public function testDoesNothingOnSuccess(): void diff --git a/tests/contracts/Bootstrapper/DefaultFixtureProviderTest.php b/tests/contracts/Bootstrapper/DefaultFixtureProviderTest.php index eaf9606..cc56584 100644 --- a/tests/contracts/Bootstrapper/DefaultFixtureProviderTest.php +++ b/tests/contracts/Bootstrapper/DefaultFixtureProviderTest.php @@ -10,11 +10,10 @@ use Ibexa\Contracts\Core\Test\Persistence\Fixture\YamlFixture; use Ibexa\Contracts\Test\Core\Bootstrapper\DefaultFixtureProvider; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \Ibexa\Contracts\Test\Core\Bootstrapper\DefaultFixtureProvider - */ +#[CoversClass(DefaultFixtureProvider::class)] final class DefaultFixtureProviderTest extends TestCase { public function testYieldsTheBuiltInBaseFixture(): void diff --git a/tests/contracts/Bootstrapper/DefaultSchemaFilesProviderTest.php b/tests/contracts/Bootstrapper/DefaultSchemaFilesProviderTest.php index bdb7027..d3c3eac 100644 --- a/tests/contracts/Bootstrapper/DefaultSchemaFilesProviderTest.php +++ b/tests/contracts/Bootstrapper/DefaultSchemaFilesProviderTest.php @@ -9,12 +9,11 @@ namespace Ibexa\Tests\Contracts\Test\Core\Bootstrapper; use Ibexa\Contracts\Test\Core\Bootstrapper\DefaultSchemaFilesProvider; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Symfony\Component\HttpKernel\KernelInterface; -/** - * @covers \Ibexa\Contracts\Test\Core\Bootstrapper\DefaultSchemaFilesProvider - */ +#[CoversClass(DefaultSchemaFilesProvider::class)] final class DefaultSchemaFilesProviderTest extends TestCase { public function testYieldsSchemaFileResolvedThroughTheKernel(): void diff --git a/tests/contracts/Bootstrapper/FixtureHookTest.php b/tests/contracts/Bootstrapper/FixtureHookTest.php index 841358d..b24501b 100644 --- a/tests/contracts/Bootstrapper/FixtureHookTest.php +++ b/tests/contracts/Bootstrapper/FixtureHookTest.php @@ -14,12 +14,11 @@ use Ibexa\Contracts\Core\Test\Persistence\Fixture\FixtureImporter; use Ibexa\Contracts\Test\Core\Bootstrapper\FixtureHook; use Ibexa\Contracts\Test\Core\Bootstrapper\FixtureProviderInterface; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Symfony\Component\OptionsResolver\OptionsResolver; -/** - * @covers \Ibexa\Contracts\Test\Core\Bootstrapper\FixtureHook - */ +#[CoversClass(FixtureHook::class)] final class FixtureHookTest extends TestCase { public function testLoadFixturesOptionDefaultsToTrue(): void @@ -53,7 +52,7 @@ public function testDoesNotAskProviderForFixturesWhenDisabled(): void $provider = $this->createMock(FixtureProviderInterface::class); $provider->expects(self::never())->method('getFixtures'); - $hook = new FixtureHook($provider, new FixtureImporter($this->createMock(Connection::class))); + $hook = new FixtureHook($provider, new FixtureImporter($this->createStub(Connection::class))); $hook($this->resolve($hook, [FixtureHook::OPTION_LOAD_FIXTURES => false])); } @@ -80,7 +79,7 @@ private function hookReturningFixtures(array $fixtures): FixtureHook $provider = $this->createMock(FixtureProviderInterface::class); $provider->method('getFixtures')->willReturn($fixtures); - $fixtureImporter = new FixtureImporter($this->createMock(Connection::class)); + $fixtureImporter = new FixtureImporter($this->createStub(Connection::class)); return new FixtureHook($provider, $fixtureImporter); } diff --git a/tests/contracts/Bootstrapper/KernelProviderTest.php b/tests/contracts/Bootstrapper/KernelProviderTest.php index 88a8e86..88c2557 100644 --- a/tests/contracts/Bootstrapper/KernelProviderTest.php +++ b/tests/contracts/Bootstrapper/KernelProviderTest.php @@ -11,14 +11,14 @@ use Ibexa\Contracts\Test\Core\Bootstrapper\KernelProvider; use Ibexa\Contracts\Test\Core\IbexaTestKernel; use LogicException; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\TestWith; use PHPUnit\Framework\TestCase; use stdClass; use Symfony\Component\Config\Loader\LoaderInterface; use Symfony\Component\HttpKernel\Kernel; -/** - * @covers \Ibexa\Contracts\Test\Core\Bootstrapper\KernelProvider - */ +#[CoversClass(KernelProvider::class)] final class KernelProviderTest extends TestCase { /** @@ -53,10 +53,8 @@ protected function tearDown(): void } } - /** - * @testWith [null, "The kernel class \"null\" must implement \"Symfony\\Component\\HttpKernel\\KernelInterface\". Ensure that the KERNEL_CLASS environment variable is set to a valid test kernel class."] - * ["stdClass", "The kernel class \"stdClass\" must implement \"Symfony\\Component\\HttpKernel\\KernelInterface\". Ensure that the KERNEL_CLASS environment variable is set to a valid test kernel class."] - */ + #[TestWith([null, 'The kernel class "null" must implement "Symfony\Component\HttpKernel\KernelInterface". Ensure that the KERNEL_CLASS environment variable is set to a valid test kernel class.'])] + #[TestWith(['stdClass', 'The kernel class "stdClass" must implement "Symfony\Component\HttpKernel\KernelInterface". Ensure that the KERNEL_CLASS environment variable is set to a valid test kernel class.'])] public function testThrowsWhenKernelClassIsInvalid( ?string $kernelClass, string $exceptionMessage diff --git a/tests/contracts/Bootstrapper/PurgeIndexAfterFixturesHookTest.php b/tests/contracts/Bootstrapper/PurgeIndexAfterFixturesHookTest.php index 0bb4f36..c299c19 100644 --- a/tests/contracts/Bootstrapper/PurgeIndexAfterFixturesHookTest.php +++ b/tests/contracts/Bootstrapper/PurgeIndexAfterFixturesHookTest.php @@ -10,12 +10,11 @@ use Ibexa\Contracts\Core\Search\VersatileHandler; use Ibexa\Contracts\Test\Core\Bootstrapper\PurgeIndexAfterFixturesHook; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Symfony\Component\OptionsResolver\OptionsResolver; -/** - * @covers \Ibexa\Contracts\Test\Core\Bootstrapper\PurgeIndexAfterFixturesHook - */ +#[CoversClass(PurgeIndexAfterFixturesHook::class)] final class PurgeIndexAfterFixturesHookTest extends TestCase { public function testPurgeIndexOptionDefaultsToFalse(): void diff --git a/tests/contracts/Bootstrapper/PurgeSearchIndexHookTest.php b/tests/contracts/Bootstrapper/PurgeSearchIndexHookTest.php index 76be838..c70cabe 100644 --- a/tests/contracts/Bootstrapper/PurgeSearchIndexHookTest.php +++ b/tests/contracts/Bootstrapper/PurgeSearchIndexHookTest.php @@ -10,12 +10,11 @@ use Ibexa\Contracts\Core\Search\VersatileHandler; use Ibexa\Contracts\Test\Core\Bootstrapper\PurgeSearchIndexHook; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Symfony\Component\OptionsResolver\OptionsResolver; -/** - * @covers \Ibexa\Contracts\Test\Core\Bootstrapper\PurgeSearchIndexHook - */ +#[CoversClass(PurgeSearchIndexHook::class)] final class PurgeSearchIndexHookTest extends TestCase { public function testPurgeIndexOptionDefaultsToFalse(): void diff --git a/tests/integration/SampleTest.php b/tests/integration/SampleTest.php index 58ff5af..dcb02ea 100644 --- a/tests/integration/SampleTest.php +++ b/tests/integration/SampleTest.php @@ -9,12 +9,11 @@ namespace Ibexa\Tests\Integration\Test\Core; use Ibexa\Contracts\Test\Core\IbexaKernelTestCase; +use PHPUnit\Framework\Attributes\CoversNothing; +use PHPUnit\Framework\Attributes\Group; -/** - * @group integration - * - * @coversNothing - */ +#[Group('integration')] +#[CoversNothing] final class SampleTest extends IbexaKernelTestCase { public function testCompilesSuccessfully(): void diff --git a/tests/lib/Bootstrapper/FixtureProviderChainTest.php b/tests/lib/Bootstrapper/FixtureProviderChainTest.php index 6c713c8..b078da2 100644 --- a/tests/lib/Bootstrapper/FixtureProviderChainTest.php +++ b/tests/lib/Bootstrapper/FixtureProviderChainTest.php @@ -11,11 +11,10 @@ use Ibexa\Contracts\Core\Test\Persistence\Fixture; use Ibexa\Contracts\Test\Core\Bootstrapper\FixtureProviderInterface; use Ibexa\Test\Core\Bootstrapper\FixtureProviderChain; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \Ibexa\Test\Core\Bootstrapper\FixtureProviderChain - */ +#[CoversClass(FixtureProviderChain::class)] final class FixtureProviderChainTest extends TestCase { public function testSkipsProvidersReturningNull(): void diff --git a/tests/lib/Bootstrapper/HooksExecutorTest.php b/tests/lib/Bootstrapper/HooksExecutorTest.php index 79ff180..1b337e6 100644 --- a/tests/lib/Bootstrapper/HooksExecutorTest.php +++ b/tests/lib/Bootstrapper/HooksExecutorTest.php @@ -10,14 +10,13 @@ use Ibexa\Contracts\Test\Core\Bootstrapper\HookInterface; use Ibexa\Test\Core\Bootstrapper\HooksExecutor; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException; use Symfony\Component\OptionsResolver\OptionsResolver; -/** - * @covers \Ibexa\Test\Core\Bootstrapper\HooksExecutor - */ +#[CoversClass(HooksExecutor::class)] final class HooksExecutorTest extends TestCase { public function testConfigureOptionsRejectsUnrecognizedTopLevelKey(): void diff --git a/tests/lib/TestDataTest.php b/tests/lib/TestDataTest.php index 729545a..c58b4ac 100644 --- a/tests/lib/TestDataTest.php +++ b/tests/lib/TestDataTest.php @@ -8,13 +8,12 @@ namespace Ibexa\Tests\Test\Core; +use PHPUnit\Framework\Attributes\CoversNothing; use PHPUnit\Framework\TestCase; use SimpleXMLElement; use Symfony\Component\Yaml\Yaml; -/** - * @coversNothing - */ +#[CoversNothing] final class TestDataTest extends TestCase { private const string TEST_DATA_FILE = __DIR__ . '/../../src/contracts/Resources/test_data.yaml'; diff --git a/tests/lib/Translation/AbstractTranslationCaseTest.php b/tests/lib/Translation/AbstractTranslationCaseTest.php index d6d0ca6..a7ce052 100644 --- a/tests/lib/Translation/AbstractTranslationCaseTest.php +++ b/tests/lib/Translation/AbstractTranslationCaseTest.php @@ -12,6 +12,7 @@ use JMS\TranslationBundle\Model\Message; use JMS\TranslationBundle\Translation\Comparison\ChangeSet; use PHPUnit\Framework\AssertionFailedError; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; final class AbstractTranslationCaseTest extends TestCase @@ -23,9 +24,7 @@ public function testEmptyChangeSetPasses(): void $this->addToAssertionCount(1); } - /** - * @dataProvider provideChangeSetsWithPendingMessages - */ + #[DataProvider('provideChangeSetsWithPendingMessages')] public function testChangeSetWithPendingMessagesFails( ChangeSet $changeSet, string $expectedMessage