diff --git a/.gitignore b/.gitignore index b04fa3f..065aaa7 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ /.php_cs.cache composer.lock .php-cs-fixer.cache +.phpunit.cache/ .phpunit.result.cache diff --git a/composer.json b/composer.json index bca0d6c..2143507 100644 --- a/composer.json +++ b/composer.json @@ -50,11 +50,11 @@ "ibexa/rector": "~6.0.x-dev", "ibexa/rest": "~6.0.x-dev", "ibexa/search": "~6.0.x-dev", - "matthiasnoback/symfony-dependency-injection-test": "^5.0", + "matthiasnoback/symfony-dependency-injection-test": "^6.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" }, "scripts": { diff --git a/phpunit.xml b/phpunit.xml index 9258b3b..eed9abd 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,34 +1,31 @@ - - - - src - - - tests/bundle/ - tests/lib/ - - - - - tests/bundle/ - - - tests/lib/ - - - tests/integration - - - - - - - - - - + + + + + + + tests/bundle/ + + + tests/lib/ + + + tests/integration + + + + + + + + + + src + + + tests/bundle/ + tests/lib/ + + diff --git a/tests/integration/SampleTest.php b/tests/integration/SampleTest.php index 6f1bfb6..84feea5 100644 --- a/tests/integration/SampleTest.php +++ b/tests/integration/SampleTest.php @@ -8,11 +8,11 @@ namespace Ibexa\Tests\Integration\User; -/** - * @group integration - * - * @coversNothing - */ +use PHPUnit\Framework\Attributes\CoversNothing; +use PHPUnit\Framework\Attributes\Group; + +#[Group('integration')] +#[CoversNothing] final class SampleTest extends IbexaKernelTestCase { public function testCompilesSuccessfully(): void diff --git a/tests/lib/EventListener/PerformAccessCheckSubscriberTest.php b/tests/lib/EventListener/PerformAccessCheckSubscriberTest.php index dc8160c..4f43d89 100644 --- a/tests/lib/EventListener/PerformAccessCheckSubscriberTest.php +++ b/tests/lib/EventListener/PerformAccessCheckSubscriberTest.php @@ -10,7 +10,7 @@ use Ibexa\Tests\User\Stub\RestrictedControllerStub; use Ibexa\User\EventListener\PerformAccessCheckSubscriber; -use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\MockObject\Stub; use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Event\ControllerEvent; @@ -20,13 +20,13 @@ final class PerformAccessCheckSubscriberTest extends TestCase { private PerformAccessCheckSubscriber $subscriber; - private HttpKernelInterface&MockObject $kernel; + private HttpKernelInterface&Stub $kernel; private Request $request; protected function setUp(): void { - $this->kernel = $this->createMock(HttpKernelInterface::class); + $this->kernel = $this->createStub(HttpKernelInterface::class); $this->request = new Request(); $this->subscriber = new PerformAccessCheckSubscriber([]); } diff --git a/tests/lib/Form/Type/ChoiceList/Loader/AvailableLocaleChoiceLoaderTest.php b/tests/lib/Form/Type/ChoiceList/Loader/AvailableLocaleChoiceLoaderTest.php index dbcba44..d657e2b 100644 --- a/tests/lib/Form/Type/ChoiceList/Loader/AvailableLocaleChoiceLoaderTest.php +++ b/tests/lib/Form/Type/ChoiceList/Loader/AvailableLocaleChoiceLoaderTest.php @@ -10,7 +10,9 @@ use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface; use Ibexa\User\Form\ChoiceList\Loader\AvailableLocaleChoiceLoader; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\MockObject\Stub; use PHPUnit\Framework\TestCase; use Symfony\Component\Validator\ConstraintViolationInterface; use Symfony\Component\Validator\ConstraintViolationList; @@ -20,7 +22,7 @@ class AvailableLocaleChoiceLoaderTest extends TestCase { private ValidatorInterface&MockObject $validator; - private ConstraintViolationInterface&MockObject $constraintViolation; + private ConstraintViolationInterface&Stub $constraintViolation; private ConfigResolverInterface&MockObject $configResolver; @@ -29,7 +31,7 @@ protected function setUp(): void parent::setUp(); $this->validator = $this->createMock(ValidatorInterface::class); - $this->constraintViolation = $this->createMock(ConstraintViolationInterface::class); + $this->constraintViolation = $this->createStub(ConstraintViolationInterface::class); $this->configResolver = $this->createMock(ConfigResolverInterface::class); } @@ -37,9 +39,8 @@ protected function setUp(): void * @param array $availableTranslations * @param array $additionalTranslations * @param array $expectedLocales - * - * @dataProvider providerForGetChoiceList */ + #[DataProvider('providerForGetChoiceList')] public function testGetChoiceList( array $availableTranslations, array $additionalTranslations, @@ -70,7 +71,7 @@ public function testGetChoiceList( * 2: array * }> */ - public function providerForGetChoiceList(): array + public static function providerForGetChoiceList(): array { return [ 'available_translations' => [ diff --git a/tests/lib/Invitation/InvitationServiceTest.php b/tests/lib/Invitation/InvitationServiceTest.php index 3f9a174..55bb2a3 100644 --- a/tests/lib/Invitation/InvitationServiceTest.php +++ b/tests/lib/Invitation/InvitationServiceTest.php @@ -22,6 +22,7 @@ use Ibexa\Core\MVC\Symfony\SiteAccess\SiteAccessServiceInterface; use Ibexa\User\Invitation\InvitationService; use Ibexa\User\Invitation\Persistence\Handler; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -39,20 +40,18 @@ protected function setUp(): void $this->configResolver = $this->createMock(ConfigResolverInterface::class); $this->invitationService = new InvitationService( - $this->createMock(PermissionResolver::class), - $this->createMock(Handler::class), - $this->createMock(HashGenerator::class), - $this->createMock(UserService::class), + $this->createStub(PermissionResolver::class), + $this->createStub(Handler::class), + $this->createStub(HashGenerator::class), + $this->createStub(UserService::class), $this->siteAccessService, - $this->createMock(TransactionHandler::class), + $this->createStub(TransactionHandler::class), $this->configResolver, - $this->createMock(DomainMapper::class) + $this->createStub(DomainMapper::class) ); } - /** - * @dataProvider invitationProvider - */ + #[DataProvider('invitationProvider')] public function testIsValid( InvitationContract $invitation, string $usedInSiteAccessName, @@ -83,7 +82,7 @@ public function testIsValid( * 2: bool * }> */ - public function invitationProvider(): array + public static function invitationProvider(): array { return [ 'valid' => [ diff --git a/tests/lib/Password/PasswordRequirementsResolverTest.php b/tests/lib/Password/PasswordRequirementsResolverTest.php index de7e70f..ba11f78 100644 --- a/tests/lib/Password/PasswordRequirementsResolverTest.php +++ b/tests/lib/Password/PasswordRequirementsResolverTest.php @@ -16,6 +16,7 @@ use Ibexa\Core\Repository\User\PasswordValidatorInterface; use Ibexa\User\Password\PasswordRequirement; use Ibexa\User\Password\PasswordRequirementsResolver; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; final class PasswordRequirementsResolverTest extends TestCase @@ -40,12 +41,11 @@ public function testContentTypeWithoutUserFieldDefinition(): void } /** - * @dataProvider dataProviderForGetRequirements - * * @param array $constraints * @param array $fieldSettings * @param string[] $expectedIdentifiers */ + #[DataProvider('dataProviderForGetRequirements')] public function testGetRequirements( array $constraints, array $fieldSettings, @@ -71,7 +71,7 @@ public function testGetRequirements( * 2: string[], * }> */ - public function dataProviderForGetRequirements(): array + public static function dataProviderForGetRequirements(): array { return [ 'all rules disabled' => [ @@ -133,9 +133,9 @@ public function dataProviderForGetRequirements(): array public function testCoversEveryCoreValidatorSchemaRule(): void { $schema = (new UserType( - $this->createMock(UserHandler::class), - $this->createMock(PasswordHashService::class), - $this->createMock(PasswordValidatorInterface::class) + $this->createStub(UserHandler::class), + $this->createStub(PasswordHashService::class), + $this->createStub(PasswordValidatorInterface::class) ))->getValidatorConfigurationSchema()['PasswordValueValidator']; $allRulesEnabled = array_map( diff --git a/tests/lib/Permission/UserPermissionsLimitationTypeTest.php b/tests/lib/Permission/UserPermissionsLimitationTypeTest.php index 1059eb4..0c2608a 100644 --- a/tests/lib/Permission/UserPermissionsLimitationTypeTest.php +++ b/tests/lib/Permission/UserPermissionsLimitationTypeTest.php @@ -12,6 +12,7 @@ use Ibexa\Contracts\Core\Persistence\Content\Handler as ContentHandlerInterface; use Ibexa\Contracts\Core\Persistence\User\Handler as UserHandlerInterface; use Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo; +use Ibexa\Contracts\Core\Repository\Values\User\User as APIUser; use Ibexa\Contracts\Core\Repository\Values\ValueObject; use Ibexa\Core\Base\Exceptions\NotFoundException; use Ibexa\Core\Repository\Values\Content\Content; @@ -21,12 +22,11 @@ use Ibexa\Tests\Core\Limitation\Base; use Ibexa\User\Permission\UserPermissionsLimitation; use Ibexa\User\Permission\UserPermissionsLimitationType; +use PHPUnit\Framework\Attributes\DataProvider; class UserPermissionsLimitationTypeTest extends Base { - /** - * @dataProvider providerForTestAcceptValue - */ + #[DataProvider('providerForTestAcceptValue')] public function testAcceptValue(UserPermissionsLimitation $limitation): void { $this->expectNotToPerformAssertions(); @@ -38,7 +38,7 @@ public function testAcceptValue(UserPermissionsLimitation $limitation): void * 0: \Ibexa\User\Permission\UserPermissionsLimitation * }> */ - public function providerForTestAcceptValue(): array + public static function providerForTestAcceptValue(): array { return [ [ @@ -74,9 +74,7 @@ public function providerForTestAcceptValue(): array ]; } - /** - * @dataProvider providerForTestAcceptValueException - */ + #[DataProvider('providerForTestAcceptValueException')] public function testAcceptValueException(UserPermissionsLimitation $limitation): void { $this->expectException(InvalidArgumentType::class); @@ -88,7 +86,7 @@ public function testAcceptValueException(UserPermissionsLimitation $limitation): * 0: \Ibexa\User\Permission\UserPermissionsLimitation * }> */ - public function providerForTestAcceptValueException(): array + public static function providerForTestAcceptValueException(): array { return [ [ @@ -115,18 +113,28 @@ public function providerForTestAcceptValueException(): array ]; } - /** - * @dataProvider providerForTestAcceptValue - */ + #[DataProvider('providerForTestAcceptValue')] public function testValidatePass(UserPermissionsLimitation $limitation): void { $userHandlerMock = $this->createMock(UserHandlerInterface::class); $contentHandlerMock = $this->createMock(ContentHandlerInterface::class); if ($limitation->limitationValues['roles'] !== null) { - $userHandlerMock + // Original test never asserted an invocation count here (bare ->method(), no + // ->expects()), only the per-call arguments via withConsecutive - some data sets + // (e.g. empty 'roles' arrays) legitimately invoke loadRole() zero times. + $roleMatcher = self::any(); + $userHandlerMock->expects($roleMatcher) ->method('loadRole') - ->withConsecutive([4, Role::STATUS_DEFINED], [8, Role::STATUS_DEFINED]); + ->willReturnCallback(static function (int $roleId, int $status) use ($roleMatcher): ?Role { + if ($roleMatcher->numberOfInvocations() === 1) { + self::assertSame([4, Role::STATUS_DEFINED], [$roleId, $status]); + } else { + self::assertSame([8, Role::STATUS_DEFINED], [$roleId, $status]); + } + + return null; + }); $this->getPersistenceMock() ->method('userHandler') @@ -134,9 +142,18 @@ public function testValidatePass(UserPermissionsLimitation $limitation): void } if ($limitation->limitationValues['roles'] !== null) { - $contentHandlerMock + $contentMatcher = self::any(); + $contentHandlerMock->expects($contentMatcher) ->method('loadContentInfo') - ->withConsecutive([14], [21]); + ->willReturnCallback(static function (int $contentId) use ($contentMatcher): ?ContentInfo { + if ($contentMatcher->numberOfInvocations() === 1) { + self::assertSame(14, $contentId); + } else { + self::assertSame(21, $contentId); + } + + return null; + }); $this->getPersistenceMock() ->method('contentHandler') @@ -148,22 +165,27 @@ public function testValidatePass(UserPermissionsLimitation $limitation): void self::assertEmpty($validationErrors); } - /** - * @dataProvider providerForTestValidateError - */ + #[DataProvider('providerForTestValidateError')] public function testValidateError(UserPermissionsLimitation $limitation, int $errorCount): void { $userHandlerMock = $this->createMock(UserHandlerInterface::class); $contentHandlerMock = $this->createMock(ContentHandlerInterface::class); if ($limitation->limitationValues['roles'] !== null) { - $userHandlerMock + $roleMatcher = self::exactly(2); + $userHandlerMock->expects($roleMatcher) ->method('loadRole') - ->withConsecutive([4, Role::STATUS_DEFINED], [8, Role::STATUS_DEFINED]) - ->willReturnOnConsecutiveCalls( - self::throwException(new NotFoundException('Role', 4)), - new Role() - ); + ->willReturnCallback(static function (int $roleId, int $status) use ($roleMatcher): Role { + if ($roleMatcher->numberOfInvocations() === 1) { + self::assertSame([4, Role::STATUS_DEFINED], [$roleId, $status]); + + throw new NotFoundException('Role', 4); + } + + self::assertSame([8, Role::STATUS_DEFINED], [$roleId, $status]); + + return new Role(); + }); $this->getPersistenceMock() ->method('userHandler') @@ -171,13 +193,20 @@ public function testValidateError(UserPermissionsLimitation $limitation, int $er } if ($limitation->limitationValues['user_groups'] !== null) { - $contentHandlerMock + $contentMatcher = self::exactly(2); + $contentHandlerMock->expects($contentMatcher) ->method('loadContentInfo') - ->withConsecutive([14], [18]) - ->willReturnOnConsecutiveCalls( - self::throwException(new NotFoundException('Role', 4)), - new ContentInfo() - ); + ->willReturnCallback(static function (int $contentId) use ($contentMatcher): ContentInfo { + if ($contentMatcher->numberOfInvocations() === 1) { + self::assertSame(14, $contentId); + + throw new NotFoundException('Role', 4); + } + + self::assertSame(18, $contentId); + + return new ContentInfo(); + }); $this->getPersistenceMock() ->method('contentHandler') @@ -194,7 +223,7 @@ public function testValidateError(UserPermissionsLimitation $limitation, int $er * 1: int * }> */ - public function providerForTestValidateError(): array + public static function providerForTestValidateError(): array { return [ 'roles_limitation_only' => [ @@ -229,9 +258,7 @@ public function providerForTestValidateError(): array ]; } - /** - * @dataProvider providerForTestEvaluate - */ + #[DataProvider('providerForTestEvaluate')] public function testEvaluate( UserPermissionsLimitation $limitation, ValueObject $object, @@ -239,7 +266,7 @@ public function testEvaluate( ): void { $value = (new UserPermissionsLimitationType($this->getPersistenceMock()))->evaluate( $limitation, - $this->getUserMock(), + $this->createStub(APIUser::class), $object, ); @@ -253,7 +280,7 @@ public function testEvaluate( * expected: bool|null * }> */ - public function providerForTestEvaluate(): array + public static function providerForTestEvaluate(): array { return [ 'valid_role_limitation' => [ diff --git a/tests/lib/Security/Authentication/DefaultAuthenticationFailureHandlerTest.php b/tests/lib/Security/Authentication/DefaultAuthenticationFailureHandlerTest.php index 1a34b6c..6d20281 100644 --- a/tests/lib/Security/Authentication/DefaultAuthenticationFailureHandlerTest.php +++ b/tests/lib/Security/Authentication/DefaultAuthenticationFailureHandlerTest.php @@ -29,7 +29,7 @@ protected function setUp(): void { $this->httpUtils = $this->createMock(HttpUtils::class); $this->handler = new DefaultAuthenticationFailureHandler( - $this->createMock(HttpKernelInterface::class), + $this->createStub(HttpKernelInterface::class), $this->httpUtils ); } diff --git a/tests/lib/UserSetting/Setting/LanguageTest.php b/tests/lib/UserSetting/Setting/LanguageTest.php index 243b5ea..aba54b3 100644 --- a/tests/lib/UserSetting/Setting/LanguageTest.php +++ b/tests/lib/UserSetting/Setting/LanguageTest.php @@ -11,6 +11,7 @@ use Ibexa\Core\MVC\Symfony\Locale\UserLanguagePreferenceProviderInterface; use Ibexa\User\Form\ChoiceList\Loader\AvailableLocaleChoiceLoader; use Ibexa\User\UserSetting\Setting\Language; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Contracts\Translation\TranslatorInterface; @@ -32,11 +33,10 @@ protected function setUp(): void } /** - * @dataProvider providerForDefaultValue - * * @param string[] $availableLocales * @param string[] $preferredLocales */ + #[DataProvider('providerForDefaultValue')] public function testGetDefaultValue( array $preferredLocales, array $availableLocales, @@ -46,7 +46,7 @@ public function testGetDefaultValue( $this->availableLocaleChoiceLoader->method('getChoiceList')->willReturn($availableLocales); $language = new Language( - $this->createMock(TranslatorInterface::class), + $this->createStub(TranslatorInterface::class), $this->userLanguagePreferenceProvider, $this->availableLocaleChoiceLoader, ); @@ -57,7 +57,7 @@ public function testGetDefaultValue( /** * @return iterable> */ - public function providerForDefaultValue(): iterable + public static function providerForDefaultValue(): iterable { yield 'intersection' => [['en_GB', 'en'], ['en', 'de', 'el', 'en_US'], 'en']; yield 'no available locale' => [['en_GB', 'en'], ['de', 'el', 'en_US'], '']; diff --git a/tests/lib/UserSetting/UserSettingServiceTest.php b/tests/lib/UserSetting/UserSettingServiceTest.php index a2070ff..a2152ca 100644 --- a/tests/lib/UserSetting/UserSettingServiceTest.php +++ b/tests/lib/UserSetting/UserSettingServiceTest.php @@ -20,7 +20,7 @@ class UserSettingServiceTest extends TestCase { public function testCountUserSettings(): void { - $userPreferenceService = $this->createMock(UserPreferenceService::class); + $userPreferenceService = $this->createStub(UserPreferenceService::class); $valueRegistry = $this->createMock(ValueDefinitionRegistry::class); $valueRegistry->method('countValueDefinitions')->willReturn(2); $userSettingService = new UserSettingService($userPreferenceService, $valueRegistry); diff --git a/tests/lib/UserSetting/ValueDefinitionRegistryTest.php b/tests/lib/UserSetting/ValueDefinitionRegistryTest.php index 101e981..23fb7b2 100644 --- a/tests/lib/UserSetting/ValueDefinitionRegistryTest.php +++ b/tests/lib/UserSetting/ValueDefinitionRegistryTest.php @@ -17,9 +17,9 @@ class ValueDefinitionRegistryTest extends TestCase public function testGetValueDefinitions(): void { $definitions = [ - 'foo' => $this->createMock(ValueDefinitionInterface::class), - 'bar' => $this->createMock(ValueDefinitionInterface::class), - 'baz' => $this->createMock(ValueDefinitionInterface::class), + 'foo' => $this->createStub(ValueDefinitionInterface::class), + 'bar' => $this->createStub(ValueDefinitionInterface::class), + 'baz' => $this->createStub(ValueDefinitionInterface::class), ]; $registry = new ValueDefinitionRegistry($definitions); @@ -29,7 +29,7 @@ public function testGetValueDefinitions(): void public function testAddValueDefinition(): void { - $foo = $this->createMock(ValueDefinitionInterface::class); + $foo = $this->createStub(ValueDefinitionInterface::class); $registry = new ValueDefinitionRegistry([]); $registry->addValueDefinition('foo', $foo); @@ -40,7 +40,7 @@ public function testAddValueDefinition(): void public function testHasValueDefinition(): void { $registry = new ValueDefinitionRegistry([ - 'foo' => $this->createMock(ValueDefinitionInterface::class), + 'foo' => $this->createStub(ValueDefinitionInterface::class), ]); self::assertTrue($registry->hasValueDefinition('foo')); @@ -49,7 +49,7 @@ public function testHasValueDefinition(): void public function testGetValueDefinition(): void { - $foo = $this->createMock(ValueDefinitionInterface::class); + $foo = $this->createStub(ValueDefinitionInterface::class); $registry = new ValueDefinitionRegistry([ 'foo' => $foo, @@ -61,8 +61,8 @@ public function testGetValueDefinition(): void public function testCountValueDefinitions(): void { $definitions = [ - 'foo' => $this->createMock(ValueDefinitionInterface::class), - 'bar' => $this->createMock(ValueDefinitionInterface::class), + 'foo' => $this->createStub(ValueDefinitionInterface::class), + 'bar' => $this->createStub(ValueDefinitionInterface::class), ]; $registry = new ValueDefinitionRegistry($definitions); diff --git a/tests/lib/Validator/Constraint/PasswordValidatorTest.php b/tests/lib/Validator/Constraint/PasswordValidatorTest.php index cce89c3..501f2a1 100644 --- a/tests/lib/Validator/Constraint/PasswordValidatorTest.php +++ b/tests/lib/Validator/Constraint/PasswordValidatorTest.php @@ -17,6 +17,7 @@ use Ibexa\User\Password\PasswordRequirement; use Ibexa\User\Validator\Constraints\Password; use Ibexa\User\Validator\Constraints\PasswordValidator; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use stdClass; @@ -39,9 +40,7 @@ protected function setUp(): void $this->validator->initialize($this->executionContext); } - /** - * @dataProvider dataProviderForValidateNotSupportedValueType - */ + #[DataProvider('dataProviderForValidateNotSupportedValueType')] public function testValidateShouldBeSkipped(\stdClass|string|null $value): void { $this->userService @@ -58,8 +57,8 @@ public function testValidateShouldBeSkipped(\stdClass|string|null $value): void public function testValid(): void { $password = 'pass'; - $contentType = $this->createMock(ContentType::class); - $user = $this->createMock(User::class); + $contentType = $this->createStub(ContentType::class); + $user = $this->createStub(User::class); $this->userService ->expects(self::once()) @@ -94,7 +93,7 @@ static function (string $actualPassword, PasswordValidationContext $actualContex public function testInvalid(): void { - $contentType = $this->createMock(ContentType::class); + $contentType = $this->createStub(ContentType::class); $password = 'pass'; $errorParameter = 'foo'; $errorMessage = 'error'; @@ -147,7 +146,7 @@ public function testInvalid(): void public function testPluralValidationErrorUsesPluralMessageTemplate(): void { - $contentType = $this->createMock(ContentType::class); + $contentType = $this->createStub(ContentType::class); $this->userService ->method('validatePassword') @@ -179,14 +178,12 @@ public function testPluralValidationErrorUsesPluralMessageTemplate(): void )); } - /** - * @dataProvider dataProviderForKnownValidationErrorsGetRequirementCode - */ + #[DataProvider('dataProviderForKnownValidationErrorsGetRequirementCode')] public function testKnownValidationErrorsGetRequirementCode( string $errorMessage, string $expectedCode ): void { - $contentType = $this->createMock(ContentType::class); + $contentType = $this->createStub(ContentType::class); $this->userService ->method('validatePassword') @@ -220,7 +217,7 @@ public function testKnownValidationErrorsGetRequirementCode( /** * @return array */ - public function dataProviderForKnownValidationErrorsGetRequirementCode(): array + public static function dataProviderForKnownValidationErrorsGetRequirementCode(): array { return [ 'min length' => [ @@ -294,14 +291,14 @@ public function testEveryCoreCharacterRuleErrorProducesRequirementCode(): void ->willReturn($constraintViolationBuilder); $this->validator->validate('pass', new Password( - contentType: $this->createMock(ContentType::class), + contentType: $this->createStub(ContentType::class), )); } /** * @return array */ - public function dataProviderForValidateNotSupportedValueType(): array + public static function dataProviderForValidateNotSupportedValueType(): array { return [ [new stdClass()], diff --git a/tests/lib/Validator/Constraint/UserPasswordValidatorTest.php b/tests/lib/Validator/Constraint/UserPasswordValidatorTest.php index 3b9d377..c92bebf 100644 --- a/tests/lib/Validator/Constraint/UserPasswordValidatorTest.php +++ b/tests/lib/Validator/Constraint/UserPasswordValidatorTest.php @@ -13,6 +13,7 @@ use Ibexa\Core\MVC\Symfony\Security\ReferenceUserInterface; use Ibexa\User\Validator\Constraints\UserPassword; use Ibexa\User\Validator\Constraints\UserPasswordValidator; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; @@ -39,9 +40,7 @@ protected function setUp(): void $this->validator->initialize($this->executionContext); } - /** - * @dataProvider emptyDataProvider - */ + #[DataProvider('emptyDataProvider')] public function testEmptyValueType(?string $value): void { $this->userService @@ -60,7 +59,7 @@ public function testEmptyValueType(?string $value): void /** * @return array */ - public function emptyDataProvider(): array + public static function emptyDataProvider(): array { return [ 'empty_string' => [''], @@ -102,7 +101,7 @@ public function testInvalid(): void ->with($apiUser, 'password') ->willReturn(false); $constraint = new UserPassword(); - $constraintViolationBuilder = $this->createMock(ConstraintViolationBuilderInterface::class); + $constraintViolationBuilder = $this->createStub(ConstraintViolationBuilderInterface::class); $this->executionContext ->expects(self::once()) ->method('buildViolation')