diff --git a/.gitignore b/.gitignore index 5fe01ebd..2b7cb20f 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +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 c6108aa4..ac53d17f 100644 --- a/composer.json +++ b/composer.json @@ -34,11 +34,11 @@ "ibexa/rector": "~6.0.x-dev", "ibexa/rest": "~6.0.x-dev", "ibexa/test-core": "~6.0.x-dev", - "matthiasnoback/symfony-dependency-injection-test": "^5.0", + "matthiasnoback/symfony-dependency-injection-test": "^6.0", "phpstan/phpstan": "^2.1", "phpstan/phpstan-phpunit": "^2.0", "phpstan/phpstan-symfony": "^2.0", - "phpunit/phpunit": "^9.6", + "phpunit/phpunit": "^11.5", "webmozart/assert": "^2.3" }, "autoload": { diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 128adc04..1b920f72 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -637,16 +637,16 @@ parameters: path: src/lib/Validator/ValidationErrorsProcessor.php - - message: '#^Method Ibexa\\Tests\\ContentForms\\Content\\Form\\Provider\\AbstractGroupedContentFormFieldsProviderTest\:\:getFormMockWithFieldData\(\) return type with generic interface Symfony\\Component\\Form\\FormInterface does not specify its types\: TData$#' + message: '#^Method Ibexa\\Tests\\ContentForms\\Content\\Form\\Provider\\AbstractGroupedContentFormFieldsProviderTestCase\:\:getFormMockWithFieldData\(\) return type with generic interface Symfony\\Component\\Form\\FormInterface does not specify its types\: TData$#' identifier: missingType.generics count: 1 - path: tests/lib/Content/Form/Provider/AbstractGroupedContentFormFieldsProviderTest.php + path: tests/lib/Content/Form/Provider/AbstractGroupedContentFormFieldsProviderTestCase.php - - message: '#^Method Ibexa\\Tests\\ContentForms\\Content\\Form\\Provider\\AbstractGroupedContentFormFieldsProviderTest\:\:getTestForms\(\) return type has no value type specified in iterable type array\.$#' + message: '#^Method Ibexa\\Tests\\ContentForms\\Content\\Form\\Provider\\AbstractGroupedContentFormFieldsProviderTestCase\:\:getTestForms\(\) return type has no value type specified in iterable type array\.$#' identifier: missingType.iterableValue count: 1 - path: tests/lib/Content/Form/Provider/AbstractGroupedContentFormFieldsProviderTest.php + path: tests/lib/Content/Form/Provider/AbstractGroupedContentFormFieldsProviderTestCase.php - message: '#^Method Ibexa\\Tests\\ContentForms\\FieldType\\DataTransformer\\RelationListValueTransformerTest\:\:dataProviderForTestReverseTransform\(\) return type has no value type specified in iterable type iterable\.$#' diff --git a/phpunit.integration.xml.dist b/phpunit.integration.xml.dist index b9a31236..3e796c18 100644 --- a/phpunit.integration.xml.dist +++ b/phpunit.integration.xml.dist @@ -1,10 +1,10 @@ + + cacheDirectory=".phpunit.cache"> diff --git a/phpunit.xml.dist b/phpunit.xml.dist index b118bb7c..1e37cc32 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,9 +1,10 @@ diff --git a/tests/bundle/DependencyInjection/Compiler/FieldTypeFormMapperDispatcherPassTest.php b/tests/bundle/DependencyInjection/Compiler/FieldTypeFormMapperDispatcherPassTest.php index 52c32127..17eb5aa0 100644 --- a/tests/bundle/DependencyInjection/Compiler/FieldTypeFormMapperDispatcherPassTest.php +++ b/tests/bundle/DependencyInjection/Compiler/FieldTypeFormMapperDispatcherPassTest.php @@ -10,6 +10,7 @@ use Ibexa\Bundle\ContentForms\DependencyInjection\Compiler\FieldTypeFormMapperDispatcherPass; use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase; +use PHPUnit\Framework\Attributes\DataProvider; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Reference; @@ -31,9 +32,7 @@ protected function registerCompilerPass(ContainerBuilder $container): void $container->addCompilerPass(new FieldTypeFormMapperDispatcherPass()); } - /** - * @dataProvider tagsProvider - */ + #[DataProvider('tagsProvider')] public function testRegisterMappers(string $tag): void { $fieldTypeIdentifier = 'field_type_identifier'; @@ -54,7 +53,7 @@ public function testRegisterMappers(string $tag): void /** * @return array */ - public function tagsProvider(): array + public static function tagsProvider(): array { return [ [FieldTypeFormMapperDispatcherPass::FIELD_TYPE_FORM_MAPPER_VALUE_SERVICE_TAG], diff --git a/tests/lib/Content/Form/Provider/AbstractGroupedContentFormFieldsProviderTest.php b/tests/lib/Content/Form/Provider/AbstractGroupedContentFormFieldsProviderTestCase.php similarity index 93% rename from tests/lib/Content/Form/Provider/AbstractGroupedContentFormFieldsProviderTest.php rename to tests/lib/Content/Form/Provider/AbstractGroupedContentFormFieldsProviderTestCase.php index 2ab94345..852e18ef 100644 --- a/tests/lib/Content/Form/Provider/AbstractGroupedContentFormFieldsProviderTest.php +++ b/tests/lib/Content/Form/Provider/AbstractGroupedContentFormFieldsProviderTestCase.php @@ -17,7 +17,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\Form\FormInterface; -abstract class AbstractGroupedContentFormFieldsProviderTest extends TestCase +abstract class AbstractGroupedContentFormFieldsProviderTestCase extends TestCase { final protected function getFieldsGroupsListMock(): FieldsGroupsList&MockObject { @@ -29,7 +29,7 @@ final protected function getFieldsGroupsListMock(): FieldsGroupsList&MockObject ->expects($matcher) ->method('getFieldGroup') ->willReturnCallback(static function () use ($matcher, $expectedGroups): string { - return $expectedGroups[$matcher->getInvocationCount()]; + return $expectedGroups[$matcher->numberOfInvocations()]; }); return $mock; diff --git a/tests/lib/Content/Form/Provider/GroupedContentFormFieldsProviderTest.php b/tests/lib/Content/Form/Provider/GroupedContentFormFieldsProviderTest.php index 443a4cc4..27e2af96 100644 --- a/tests/lib/Content/Form/Provider/GroupedContentFormFieldsProviderTest.php +++ b/tests/lib/Content/Form/Provider/GroupedContentFormFieldsProviderTest.php @@ -10,7 +10,7 @@ use Ibexa\ContentForms\Content\Form\Provider\GroupedContentFormFieldsProvider; -final class GroupedContentFormFieldsProviderTest extends AbstractGroupedContentFormFieldsProviderTest +final class GroupedContentFormFieldsProviderTest extends AbstractGroupedContentFormFieldsProviderTestCase { public function testGetGroupedFields(): void { diff --git a/tests/lib/Content/Form/Provider/IdentifiedGroupedContentFormFieldsProviderTest.php b/tests/lib/Content/Form/Provider/IdentifiedGroupedContentFormFieldsProviderTest.php index 22693459..839c2b5a 100644 --- a/tests/lib/Content/Form/Provider/IdentifiedGroupedContentFormFieldsProviderTest.php +++ b/tests/lib/Content/Form/Provider/IdentifiedGroupedContentFormFieldsProviderTest.php @@ -10,7 +10,7 @@ use Ibexa\ContentForms\Content\Form\Provider\IdentifiedGroupedContentFormFieldsProvider; -final class IdentifiedGroupedContentFormFieldsProviderTest extends AbstractGroupedContentFormFieldsProviderTest +final class IdentifiedGroupedContentFormFieldsProviderTest extends AbstractGroupedContentFormFieldsProviderTestCase { public function testGetGroupedFields(): void { diff --git a/tests/lib/Event/FormActionEventTest.php b/tests/lib/Event/FormActionEventTest.php index c48d79ec..8d608e63 100644 --- a/tests/lib/Event/FormActionEventTest.php +++ b/tests/lib/Event/FormActionEventTest.php @@ -18,7 +18,7 @@ final class FormActionEventTest extends TestCase { public function testConstruct(): void { - $form = $this->createMock(FormInterface::class); + $form = $this->createStub(FormInterface::class); $data = new stdClass(); $clickedButton = 'fooButton'; $options = ['languageCode' => 'eng-GB', 'foo' => 'bar']; @@ -33,7 +33,7 @@ public function testConstruct(): void public function testEventDoesntHaveResponse(): void { $event = new FormActionEvent( - $this->createMock(FormInterface::class), + $this->createStub(FormInterface::class), new stdClass(), 'fooButton' ); @@ -44,7 +44,7 @@ public function testEventDoesntHaveResponse(): void public function testEventSetResponse(): void { $event = new FormActionEvent( - $this->createMock(FormInterface::class), + $this->createStub(FormInterface::class), new stdClass(), 'fooButton' ); @@ -63,7 +63,7 @@ public function testGetOption(): void $options = ['languageCode' => 'eng-GB', 'foo' => 'bar', 'obj' => $objectOption]; $event = new FormActionEvent( - $this->createMock(FormInterface::class), + $this->createStub(FormInterface::class), new stdClass(), 'fooButton', $options diff --git a/tests/lib/FieldType/DataTransformer/FieldValueTransformerTest.php b/tests/lib/FieldType/DataTransformer/FieldValueTransformerTest.php index 857653dc..94c6d591 100644 --- a/tests/lib/FieldType/DataTransformer/FieldValueTransformerTest.php +++ b/tests/lib/FieldType/DataTransformer/FieldValueTransformerTest.php @@ -32,7 +32,7 @@ public function testTransformNull(): void public function testTransform(): void { - $value = $this->createMock(Value::class); + $value = $this->createStub(Value::class); $valueHash = ['lorem' => 'Lorem ipsum dolor...']; $fieldType = $this->createMock(FieldType::class); @@ -49,7 +49,7 @@ public function testTransform(): void public function testReverseTransformNull(): void { - $emptyValue = $this->createMock(Value::class); + $emptyValue = $this->createStub(Value::class); $fieldType = $this->createMock(FieldType::class); $fieldType @@ -68,7 +68,7 @@ public function testReverseTransformNull(): void public function testReverseTransform(): void { $value = 'Lorem ipsum dolor...'; - $expected = $this->createMock(Value::class); + $expected = $this->createStub(Value::class); $fieldType = $this->createMock(FieldType::class); $fieldType diff --git a/tests/lib/FieldType/DataTransformer/MultiSelectionValueTransformerTest.php b/tests/lib/FieldType/DataTransformer/MultiSelectionValueTransformerTest.php index 2744767a..bc26bf85 100644 --- a/tests/lib/FieldType/DataTransformer/MultiSelectionValueTransformerTest.php +++ b/tests/lib/FieldType/DataTransformer/MultiSelectionValueTransformerTest.php @@ -10,6 +10,7 @@ use Ibexa\ContentForms\FieldType\DataTransformer\MultiSelectionValueTransformer; use Ibexa\Core\FieldType\Selection\Value; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; final class MultiSelectionValueTransformerTest extends TestCase @@ -17,7 +18,7 @@ final class MultiSelectionValueTransformerTest extends TestCase /** * @phpstan-return list}> */ - public function transformProvider(): array + public static function transformProvider(): array { return [ [[0]], @@ -27,10 +28,9 @@ public function transformProvider(): array } /** - * @dataProvider transformProvider - * * @param array $valueAsArray */ + #[DataProvider('transformProvider')] public function testTransform(array $valueAsArray): void { $transformer = new MultiSelectionValueTransformer(); @@ -39,10 +39,9 @@ public function testTransform(array $valueAsArray): void } /** - * @dataProvider transformProvider - * * @param array $valueAsArray */ + #[DataProvider('transformProvider')] public function testReverseTransform(array $valueAsArray): void { $transformer = new MultiSelectionValueTransformer(); @@ -53,7 +52,7 @@ public function testReverseTransform(array $valueAsArray): void /** * @phpstan-return list */ - public function transformNullProvider(): array + public static function transformNullProvider(): array { return [ [new Value()], @@ -64,9 +63,7 @@ public function transformNullProvider(): array ]; } - /** - * @dataProvider transformNullProvider - */ + #[DataProvider('transformNullProvider')] public function testTransformNull(mixed $value): void { $transformer = new MultiSelectionValueTransformer(); diff --git a/tests/lib/FieldType/DataTransformer/MultipleCountryValueTransformerTest.php b/tests/lib/FieldType/DataTransformer/MultipleCountryValueTransformerTest.php index db639b7a..9a0d7aa2 100644 --- a/tests/lib/FieldType/DataTransformer/MultipleCountryValueTransformerTest.php +++ b/tests/lib/FieldType/DataTransformer/MultipleCountryValueTransformerTest.php @@ -10,6 +10,7 @@ use Ibexa\ContentForms\FieldType\DataTransformer\MultipleCountryValueTransformer; use Ibexa\Core\FieldType\Country\Value; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; /** @@ -52,7 +53,7 @@ final class MultipleCountryValueTransformerTest extends TestCase /** * @phpstan-return list}> */ - public function transformProvider(): array + public static function transformProvider(): array { return [ [ @@ -71,10 +72,9 @@ public function transformProvider(): array } /** - * @dataProvider transformProvider - * * @phpstan-param array $valueAsArray */ + #[DataProvider('transformProvider')] public function testTransform(array $valueAsArray): void { $transformer = new MultipleCountryValueTransformer($this->countriesInfo); @@ -83,10 +83,9 @@ public function testTransform(array $valueAsArray): void } /** - * @dataProvider transformProvider - * * @phpstan-param array $valueAsArray */ + #[DataProvider('transformProvider')] public function testReverseTransform(array $valueAsArray): void { $transformer = new MultipleCountryValueTransformer($this->countriesInfo); @@ -97,7 +96,7 @@ public function testReverseTransform(array $valueAsArray): void /** * @phpstan-return list|null}> */ - public function transformNullProvider(): array + public static function transformNullProvider(): array { return [ [42], @@ -107,9 +106,7 @@ public function transformNullProvider(): array ]; } - /** - * @dataProvider transformNullProvider - */ + #[DataProvider('transformNullProvider')] public function testTransformNull(mixed $value): void { $transformer = new MultipleCountryValueTransformer($this->countriesInfo); @@ -119,7 +116,7 @@ public function testTransformNull(mixed $value): void /** * @phpstan-return list */ - public function reverseTransformNullProvider(): array + public static function reverseTransformNullProvider(): array { return [ [42], @@ -129,9 +126,7 @@ public function reverseTransformNullProvider(): array ]; } - /** - * @dataProvider reverseTransformNullProvider - */ + #[DataProvider('reverseTransformNullProvider')] public function testReverseTransformNull(mixed $value): void { $transformer = new MultipleCountryValueTransformer($this->countriesInfo); diff --git a/tests/lib/FieldType/DataTransformer/RelationListValueTransformerTest.php b/tests/lib/FieldType/DataTransformer/RelationListValueTransformerTest.php index dc99899a..07618665 100644 --- a/tests/lib/FieldType/DataTransformer/RelationListValueTransformerTest.php +++ b/tests/lib/FieldType/DataTransformer/RelationListValueTransformerTest.php @@ -10,13 +10,12 @@ use Ibexa\ContentForms\FieldType\DataTransformer\RelationListValueTransformer; use Ibexa\Core\FieldType\RelationList\Value; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; final class RelationListValueTransformerTest extends TestCase { - /** - * @dataProvider dataProviderForTestReverseTransform - */ + #[DataProvider('dataProviderForTestReverseTransform')] public function testReverseTransform(?string $value, ?Value $expectedValue): void { $transformer = new RelationListValueTransformer(); @@ -27,7 +26,7 @@ public function testReverseTransform(?string $value, ?Value $expectedValue): voi ); } - public function dataProviderForTestReverseTransform(): iterable + public static function dataProviderForTestReverseTransform(): iterable { yield 'null' => [ null, diff --git a/tests/lib/FieldType/DataTransformer/SingleSelectionValueTransformerTest.php b/tests/lib/FieldType/DataTransformer/SingleSelectionValueTransformerTest.php index af4fe410..98fa5112 100644 --- a/tests/lib/FieldType/DataTransformer/SingleSelectionValueTransformerTest.php +++ b/tests/lib/FieldType/DataTransformer/SingleSelectionValueTransformerTest.php @@ -10,6 +10,7 @@ use Ibexa\ContentForms\FieldType\DataTransformer\SingleSelectionValueTransformer; use Ibexa\Core\FieldType\Selection\Value; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class SingleSelectionValueTransformerTest extends TestCase @@ -17,7 +18,7 @@ class SingleSelectionValueTransformerTest extends TestCase /** * @phpstan-return list */ - public function transformProvider(): array + public static function transformProvider(): array { return [ [0], @@ -26,18 +27,14 @@ public function transformProvider(): array ]; } - /** - * @dataProvider transformProvider - */ + #[DataProvider('transformProvider')] public function testTransform(int $value): void { $transformer = new SingleSelectionValueTransformer(); self::assertSame($value, $transformer->transform(new Value([$value]))); } - /** - * @dataProvider transformProvider - */ + #[DataProvider('transformProvider')] public function testReverseTransform(int $value): void { $transformer = new SingleSelectionValueTransformer(); @@ -48,7 +45,7 @@ public function testReverseTransform(int $value): void /** * @phpstan-return list */ - public function transformNullProvider(): array + public static function transformNullProvider(): array { return [ [new Value()], @@ -58,9 +55,7 @@ public function transformNullProvider(): array ]; } - /** - * @dataProvider transformNullProvider - */ + #[DataProvider('transformNullProvider')] public function testTransformNull(mixed $value): void { $transformer = new SingleSelectionValueTransformer(); diff --git a/tests/lib/FieldType/FieldTypeFormMapperDispatcherTest.php b/tests/lib/FieldType/FieldTypeFormMapperDispatcherTest.php index dad567d6..b239e0f1 100644 --- a/tests/lib/FieldType/FieldTypeFormMapperDispatcherTest.php +++ b/tests/lib/FieldType/FieldTypeFormMapperDispatcherTest.php @@ -42,7 +42,7 @@ public function testMapFieldValue(): void 'fieldDefinition' => new FieldDefinition(['fieldTypeIdentifier' => 'first_type']), ]); - $formMock = $this->createMock(FormInterface::class); + $formMock = $this->createStub(FormInterface::class); $this->fieldTypeAliasResolverMock ->method('resolveIdentifier') diff --git a/tests/lib/FieldType/Mapper/BaseMapperTest.php b/tests/lib/FieldType/Mapper/BaseMapperTestCase.php similarity index 90% rename from tests/lib/FieldType/Mapper/BaseMapperTest.php rename to tests/lib/FieldType/Mapper/BaseMapperTestCase.php index 7e2baa82..6a3e71c7 100644 --- a/tests/lib/FieldType/Mapper/BaseMapperTest.php +++ b/tests/lib/FieldType/Mapper/BaseMapperTestCase.php @@ -18,7 +18,7 @@ use Symfony\Component\Form\FormFactoryInterface; use Symfony\Component\Form\FormInterface; -abstract class BaseMapperTest extends TestCase +abstract class BaseMapperTestCase extends TestCase { protected FieldTypeService&MockObject $fieldTypeService; @@ -35,17 +35,15 @@ protected function setUp(): void $this->fieldTypeService = $this->createMock(FieldTypeService::class); $this->fieldTypeService ->method('getFieldType') - ->willReturn($this->createMock(FieldType::class)); + ->willReturn($this->createStub(FieldType::class)); $this->config = $this->createMock(FormConfigInterface::class); $this->fieldForm = $this->createMock(FormInterface::class); - - $formBuilder = $this->createMock(FormBuilder::class); $formFactory = $this->createMock(FormFactoryInterface::class); $formFactory ->expects(self::once()) ->method('createBuilder') - ->willReturn($formBuilder); + ->willReturn($this->createStub(FormBuilder::class)); $this->config ->expects(self::once()) diff --git a/tests/lib/FieldType/Mapper/FormTypeBasedFieldValueFormMapperTest.php b/tests/lib/FieldType/Mapper/FormTypeBasedFieldValueFormMapperTest.php index 2a100fcc..74149285 100644 --- a/tests/lib/FieldType/Mapper/FormTypeBasedFieldValueFormMapperTest.php +++ b/tests/lib/FieldType/Mapper/FormTypeBasedFieldValueFormMapperTest.php @@ -12,7 +12,7 @@ use Ibexa\Core\Repository\Values\ContentType\FieldDefinition; use Symfony\Component\Form\Extension\Core\Type\TextType; -final class FormTypeBasedFieldValueFormMapperTest extends BaseMapperTest +final class FormTypeBasedFieldValueFormMapperTest extends BaseMapperTestCase { public function testMapFieldValueFormNoLanguageCode(): void { diff --git a/tests/lib/FieldType/Mapper/UserAccountFieldValueFormMapperTest.php b/tests/lib/FieldType/Mapper/UserAccountFieldValueFormMapperTest.php index f5ca9d7b..29d70297 100644 --- a/tests/lib/FieldType/Mapper/UserAccountFieldValueFormMapperTest.php +++ b/tests/lib/FieldType/Mapper/UserAccountFieldValueFormMapperTest.php @@ -15,7 +15,7 @@ use Symfony\Component\Form\FormConfigInterface; use Symfony\Component\Form\FormInterface; -final class UserAccountFieldValueFormMapperTest extends BaseMapperTest +final class UserAccountFieldValueFormMapperTest extends BaseMapperTestCase { protected function setUp(): void { diff --git a/tests/lib/Form/EventSubscriber/FixUrlProtocolListenerTest.php b/tests/lib/Form/EventSubscriber/FixUrlProtocolListenerTest.php index 5f3b2caf..ece42b95 100644 --- a/tests/lib/Form/EventSubscriber/FixUrlProtocolListenerTest.php +++ b/tests/lib/Form/EventSubscriber/FixUrlProtocolListenerTest.php @@ -9,6 +9,7 @@ namespace Ibexa\Tests\ContentForms\Form\EventSubscriber; use Ibexa\ContentForms\Form\EventSubscriber\FixUrlProtocolListener; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Symfony\Component\Form\FormEvent; use Symfony\Component\Form\FormInterface; @@ -25,12 +26,10 @@ final class FixUrlProtocolListenerTest extends TestCase private const URL_SFTP = 'sftp://' . self::DOMAIN; private const URL_TEL = 'tel:' . self::TEL; - /** - * @dataProvider provideUrlCases - */ + #[DataProvider('provideUrlCases')] public function testUrlProtocolHandling(?string $inputData, ?string $expectedData, string $defaultProtocol = 'https'): void { - $form = $this->createMock(FormInterface::class); + $form = $this->createStub(FormInterface::class); $listener = new FixUrlProtocolListener($defaultProtocol); $event = new FormEvent($form, $inputData); diff --git a/tests/lib/Form/Processor/ContentFormProcessorTest.php b/tests/lib/Form/Processor/ContentFormProcessorTest.php index eadd4523..aabb3682 100644 --- a/tests/lib/Form/Processor/ContentFormProcessorTest.php +++ b/tests/lib/Form/Processor/ContentFormProcessorTest.php @@ -23,15 +23,15 @@ use Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType; use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface; use Ibexa\Core\Repository\Values\Content\Location; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Symfony\Component\Form\FormConfigInterface; use Symfony\Component\Form\FormInterface; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\Routing\RouterInterface; -/** - * @covers \Ibexa\ContentForms\Form\Processor\ContentFormProcessor - */ +#[CoversClass(\Ibexa\ContentForms\Form\Processor\ContentFormProcessor::class)] final class ContentFormProcessorTest extends TestCase { private const int CONTENT_ID = 123; @@ -43,12 +43,11 @@ final class ContentFormProcessorTest extends TestCase private const string GENERATED_URL = 'generated-url'; /** - * @dataProvider provideProcessPublishCases - * * @param array|null $expectedRouteParameters route parameters the redirect * is expected to be generated with, or null when a custom redirect URL is provided and * the router must not be invoked at all */ + #[DataProvider('provideProcessPublishCases')] public function testProcessPublish( bool $isNewContent, bool $publishedSynchronously, diff --git a/tests/lib/Validator/Constraints/PasswordTest.php b/tests/lib/Validator/Constraints/PasswordTest.php index 736f6981..f7607ef3 100644 --- a/tests/lib/Validator/Constraints/PasswordTest.php +++ b/tests/lib/Validator/Constraints/PasswordTest.php @@ -11,11 +11,10 @@ use Ibexa\ContentForms\Validator\Constraints\Password; use Ibexa\ContentForms\Validator\Constraints\PasswordValidator; use Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \Ibexa\ContentForms\Validator\Constraints\Password - */ +#[CoversClass(\Ibexa\ContentForms\Validator\Constraints\Password::class)] final class PasswordTest extends TestCase { private Password $constraint; @@ -48,7 +47,7 @@ public function testGetTargets(): void public function testNamedArguments(): void { - $contentType = $this->createMock(ContentType::class); + $contentType = $this->createStub(ContentType::class); $payload = new \stdClass(); $constraint = new Password( diff --git a/tests/lib/Validator/Constraints/PasswordValidatorTest.php b/tests/lib/Validator/Constraints/PasswordValidatorTest.php index 65fde0cd..8971bf83 100644 --- a/tests/lib/Validator/Constraints/PasswordValidatorTest.php +++ b/tests/lib/Validator/Constraints/PasswordValidatorTest.php @@ -14,6 +14,7 @@ use Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType; use Ibexa\Contracts\Core\Repository\Values\User\PasswordValidationContext; use Ibexa\Core\FieldType\ValidationError; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use stdClass; @@ -36,9 +37,7 @@ protected function setUp(): void $this->validator->initialize($this->executionContext); } - /** - * @dataProvider dataProviderForValidateNotSupportedValueType - */ + #[DataProvider('dataProviderForValidateNotSupportedValueType')] public function testValidateShouldBeSkipped(mixed $value): void { $this->userService @@ -55,7 +54,7 @@ public function testValidateShouldBeSkipped(mixed $value): void public function testValid(): void { $password = 'pass'; - $contentType = $this->createMock(ContentType::class); + $contentType = $this->createStub(ContentType::class); $this->userService ->expects(self::once()) @@ -77,7 +76,7 @@ public function testValid(): void public function testInvalid(): void { - $contentType = $this->createMock(ContentType::class); + $contentType = $this->createStub(ContentType::class); $password = 'pass'; $errorParameter = 'foo'; $errorMessage = 'error'; @@ -118,7 +117,7 @@ public function testInvalid(): void $this->validator->validate('pass', new Password(contentType: $contentType)); } - public function dataProviderForValidateNotSupportedValueType(): array + public static function dataProviderForValidateNotSupportedValueType(): array { return [ [new stdClass()], diff --git a/tests/lib/Validator/Constraints/UserAccountPasswordTest.php b/tests/lib/Validator/Constraints/UserAccountPasswordTest.php index a100cf2b..7fa71007 100644 --- a/tests/lib/Validator/Constraints/UserAccountPasswordTest.php +++ b/tests/lib/Validator/Constraints/UserAccountPasswordTest.php @@ -40,7 +40,7 @@ public function testGetTargets(): void public function testNamedArguments(): void { - $contentType = $this->createMock(ContentType::class); + $contentType = $this->createStub(ContentType::class); $constraint = new UserAccountPassword(contentType: $contentType); diff --git a/tests/lib/Validator/Constraints/UserAccountPasswordValidatorTest.php b/tests/lib/Validator/Constraints/UserAccountPasswordValidatorTest.php index 7bd31a7b..73633125 100644 --- a/tests/lib/Validator/Constraints/UserAccountPasswordValidatorTest.php +++ b/tests/lib/Validator/Constraints/UserAccountPasswordValidatorTest.php @@ -15,6 +15,7 @@ use Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType; use Ibexa\Contracts\Core\Repository\Values\User\PasswordValidationContext; use Ibexa\Core\FieldType\ValidationError; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Component\Validator\Context\ExecutionContextInterface; @@ -28,9 +29,7 @@ final class UserAccountPasswordValidatorTest extends TestCase private UserAccountPasswordValidator $validator; - /** - * @dataProvider dataProviderForValidateNotSupportedValueType - */ + #[DataProvider('dataProviderForValidateNotSupportedValueType')] public function testValidateShouldBeSkipped(mixed $value): void { $this->userService @@ -52,7 +51,7 @@ protected function setUp(): void $this->validator->initialize($this->executionContext); } - public function dataProviderForValidateNotSupportedValueType(): array + public static function dataProviderForValidateNotSupportedValueType(): array { return [ [new \stdClass()], @@ -64,7 +63,7 @@ public function dataProviderForValidateNotSupportedValueType(): array public function testValid(): void { $userAccount = new UserAccountFieldData('user', 'pass', 'user@ibexa.co'); - $contentType = $this->createMock(ContentType::class); + $contentType = $this->createStub(ContentType::class); $this->userService ->expects(self::once()) @@ -86,7 +85,7 @@ public function testValid(): void public function testInvalid(): void { - $contentType = $this->createMock(ContentType::class); + $contentType = $this->createStub(ContentType::class); $userAccount = new UserAccountFieldData('user', 'pass', 'user@ibexa.co'); $errorParameter = 'foo'; $errorMessage = 'error';