From 4d8065ca7ff3018c770d0d75a215a53eeed27696 Mon Sep 17 00:00:00 2001 From: "Eric Richer eric.richer@vistoconsulting.com" Date: Wed, 7 Aug 2024 15:07:32 -0400 Subject: [PATCH] Added support for phpunit v11. Fixed phpunit deprecations and attributes Signed-off-by: Eric Richer eric.richer@vistoconsulting.com --- composer.json | 2 +- renovate.json | 11 +++----- test/Assertion/AssertionContainerTest.php | 5 ++-- test/Assertion/AssertionSetTest.php | 10 +++---- test/ConfigProviderTest.php | 5 ++-- .../AssertionContainerFactoryTest.php | 5 ++-- .../AuthorizationServiceFactoryTest.php | 5 ++-- .../InMemoryRoleProviderFactoryTest.php | 5 ++-- test/Container/ModuleOptionsFactoryTest.php | 5 ++-- ...bjectRepositoryRoleProviderFactoryTest.php | 7 ++--- test/Container/RoleServiceFactoryTest.php | 5 ++-- test/ModuleTest.php | 5 ++-- test/Options/ModuleOptionsTest.php | 5 ++-- test/RbacTest.php | 27 ++---------------- test/Role/HierarchicalRoleTest.php | 21 ++------------ test/Role/InMemoryRoleProviderTest.php | 5 ++-- .../Role/ObjectRepositoryRoleProviderTest.php | 13 ++++----- test/Role/RoleTest.php | 12 ++------ test/Service/AuthorizationServiceTest.php | 28 +++++++++---------- test/Service/RoleServiceTest.php | 5 ++-- 20 files changed, 59 insertions(+), 127 deletions(-) diff --git a/composer.json b/composer.json index ec1c03b5..82316d8a 100644 --- a/composer.json +++ b/composer.json @@ -42,7 +42,7 @@ }, "require-dev": { "malukenho/docheader": "^1.0.0", - "phpunit/phpunit": "^10.0", + "phpunit/phpunit": "^10.0 || ^11.0", "phpspec/prophecy": "^1.10", "phpspec/prophecy-phpunit": "^2.0", "friendsofphp/php-cs-fixer": "^3.43", diff --git a/renovate.json b/renovate.json index 8f151a8e..328a80f6 100644 --- a/renovate.json +++ b/renovate.json @@ -3,11 +3,8 @@ "extends": [ "config:recommended" ], - "baseBranches": ["master", "2.x"], - "packageRules": [ - { - "matchPackageNames": ["phpunit/phpunit"], - "allowedVersions": "<11.0" - } - ] + "major": { + "dependencyDashboardApproval": true + }, + "baseBranches": ["master", "2.x"] } diff --git a/test/Assertion/AssertionContainerTest.php b/test/Assertion/AssertionContainerTest.php index d542c1d1..da3487cf 100644 --- a/test/Assertion/AssertionContainerTest.php +++ b/test/Assertion/AssertionContainerTest.php @@ -26,12 +26,11 @@ use LmcRbac\Assertion\AssertionContainer; use LmcRbac\Assertion\AssertionInterface; use LmcRbacTest\Asset\SimpleAssertion; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerExceptionInterface; -/** - * @covers \LmcRbac\Assertion\AssertionContainer - */ +#[CoversClass('\LmcRbac\Assertion\AssertionContainer')] class AssertionContainerTest extends TestCase { public function testValidationOfPluginSucceedsIfAssertionInterfaceIsImplemented() diff --git a/test/Assertion/AssertionSetTest.php b/test/Assertion/AssertionSetTest.php index a783ac07..ca1e41ca 100644 --- a/test/Assertion/AssertionSetTest.php +++ b/test/Assertion/AssertionSetTest.php @@ -26,11 +26,11 @@ use LmcRbac\Exception\InvalidArgumentException; use LmcRbac\Identity\IdentityInterface; use LmcRbacTest\Asset\SimpleAssertion; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; -/** - * @covers \LmcRbac\Assertion\AssertionSet - */ +#[CoversClass('\LmcRbac\Assertion\AssertionSet')] class AssertionSetTest extends TestCase { public function testImplementsAssertionInterface() @@ -220,9 +220,7 @@ public function testThrowExceptionForInvalidAssertion() $this->assertTrue($assertionSet->assert('permission')); } - /** - * @dataProvider dpMatrix - */ + #[DataProvider('dpMatrix')] public function testMatrix(array $assertions, bool $expectedResult, array $assertionCalledCount) { $assertionContainer = $this->getMockBuilder(AssertionContainerInterface::class)->getMock(); diff --git a/test/ConfigProviderTest.php b/test/ConfigProviderTest.php index 627770c0..005b6918 100644 --- a/test/ConfigProviderTest.php +++ b/test/ConfigProviderTest.php @@ -22,11 +22,10 @@ namespace LmcRbacTest; use LmcRbac\ConfigProvider; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \LmcRbac\ConfigProvider - */ +#[CoversClass('\LmcRbac\ConfigProvider')] class ConfigProviderTest extends TestCase { public function testProvidesExpectedConfiguration() diff --git a/test/Container/AssertionContainerFactoryTest.php b/test/Container/AssertionContainerFactoryTest.php index 0b0c032c..98c4408b 100644 --- a/test/Container/AssertionContainerFactoryTest.php +++ b/test/Container/AssertionContainerFactoryTest.php @@ -24,11 +24,10 @@ use Laminas\ServiceManager\ServiceManager; use LmcRbac\Assertion\AssertionContainer; use LmcRbac\Container\AssertionContainerFactory; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \LmcRbac\Container\AssertionContainerFactory - */ +#[CoversClass('\LmcRbac\Container\AssertionContainerFactory')] class AssertionContainerFactoryTest extends TestCase { public function testFactory(): void diff --git a/test/Container/AuthorizationServiceFactoryTest.php b/test/Container/AuthorizationServiceFactoryTest.php index 7af870e1..e682d456 100644 --- a/test/Container/AuthorizationServiceFactoryTest.php +++ b/test/Container/AuthorizationServiceFactoryTest.php @@ -27,13 +27,12 @@ use LmcRbac\Rbac; use LmcRbac\Service\AuthorizationService; use LmcRbac\Service\RoleServiceInterface; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Prophecy\PhpUnit\ProphecyTrait; use Psr\Container\ContainerInterface; -/** - * @covers \LmcRbac\Container\AuthorizationServiceFactory - */ +#[CoversClass('\LmcRbac\Container\AuthorizationServiceFactory')] class AuthorizationServiceFactoryTest extends TestCase { use ProphecyTrait; diff --git a/test/Container/InMemoryRoleProviderFactoryTest.php b/test/Container/InMemoryRoleProviderFactoryTest.php index a5915142..a80276cc 100644 --- a/test/Container/InMemoryRoleProviderFactoryTest.php +++ b/test/Container/InMemoryRoleProviderFactoryTest.php @@ -25,11 +25,10 @@ use LmcRbac\Container\InMemoryRoleProviderFactory; use LmcRbac\Options\ModuleOptions; use LmcRbac\Role\InMemoryRoleProvider; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \LmcRbac\Container\InMemoryRoleProviderFactory - */ +#[CoversClass('\LmcRbac\Container\InMemoryRoleProviderFactory')] class InMemoryRoleProviderFactoryTest extends TestCase { public function testFactoryUsingObjectRepository(): void diff --git a/test/Container/ModuleOptionsFactoryTest.php b/test/Container/ModuleOptionsFactoryTest.php index a127a910..93834cf3 100644 --- a/test/Container/ModuleOptionsFactoryTest.php +++ b/test/Container/ModuleOptionsFactoryTest.php @@ -24,11 +24,10 @@ use Laminas\ServiceManager\ServiceManager; use LmcRbac\Container\ModuleOptionsFactory; use LmcRbac\Options\ModuleOptions; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \LmcRbac\Container\ModuleOptionsFactory - */ +#[CoversClass('\LmcRbac\Container\ModuleOptionsFactory')] class ModuleOptionsFactoryTest extends TestCase { public function testFactory(): void diff --git a/test/Container/ObjectRepositoryRoleProviderFactoryTest.php b/test/Container/ObjectRepositoryRoleProviderFactoryTest.php index 7fbff9f6..6e94058a 100644 --- a/test/Container/ObjectRepositoryRoleProviderFactoryTest.php +++ b/test/Container/ObjectRepositoryRoleProviderFactoryTest.php @@ -28,11 +28,10 @@ use LmcRbac\Exception\RuntimeException; use LmcRbac\Options\ModuleOptions; use LmcRbac\Role\ObjectRepositoryRoleProvider; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \LmcRbac\Container\ObjectRepositoryRoleProviderFactory - */ +#[CoversClass('\LmcRbac\Container\ObjectRepositoryRoleProviderFactory')] class ObjectRepositoryRoleProviderFactoryTest extends TestCase { public function testFactoryUsingObjectRepository(): void @@ -68,7 +67,7 @@ public function testFactoryUsingObjectManager(): void $objectManager->expects($this->once()) ->method('getRepository') ->with('Role') - ->will($this->returnValue($this->getMockBuilder(ObjectRepository::class)->getMock())); + ->willReturn($this->getMockBuilder(ObjectRepository::class)->getMock()); $container->setService('ObjectManager', $objectManager); diff --git a/test/Container/RoleServiceFactoryTest.php b/test/Container/RoleServiceFactoryTest.php index 5f0163a9..467f1708 100644 --- a/test/Container/RoleServiceFactoryTest.php +++ b/test/Container/RoleServiceFactoryTest.php @@ -25,11 +25,10 @@ use LmcRbac\Container\RoleServiceFactory; use LmcRbac\Options\ModuleOptions; use LmcRbac\Role\InMemoryRoleProvider; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \LmcRbac\Container\RoleServiceFactory - */ +#[CoversClass('\LmcRbac\Container\RoleServiceFactory')] class RoleServiceFactoryTest extends TestCase { public function testCanCreateRoleService(): void diff --git a/test/ModuleTest.php b/test/ModuleTest.php index 90bb7d37..72358d50 100644 --- a/test/ModuleTest.php +++ b/test/ModuleTest.php @@ -23,11 +23,10 @@ use LmcRbac\ConfigProvider; use LmcRbac\Module; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \LmcRbac\Module - */ +#[CoversClass('\LmcRbac\Module')] class ModuleTest extends TestCase { public function testProvidesExpectedConfiguration() diff --git a/test/Options/ModuleOptionsTest.php b/test/Options/ModuleOptionsTest.php index a4367458..3d7628ff 100644 --- a/test/Options/ModuleOptionsTest.php +++ b/test/Options/ModuleOptionsTest.php @@ -22,11 +22,10 @@ namespace LmcRbacTest\Options; use LmcRbac\Options\ModuleOptions; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \LmcRbac\Options\ModuleOptions - */ +#[CoversClass('\LmcRbac\Options\ModuleOptions')] class ModuleOptionsTest extends TestCase { public function testAssertModuleDefaultOptions(): void diff --git a/test/RbacTest.php b/test/RbacTest.php index 50a78571..f5c5eb81 100644 --- a/test/RbacTest.php +++ b/test/RbacTest.php @@ -24,17 +24,12 @@ use LmcRbac\Rbac; use LmcRbac\Role\HierarchicalRole; use LmcRbac\Role\Role; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \LmcRbac\Rbac - * @group Coverage - */ +#[CoversClass('\LmcRbac\Rbac')] class RbacTest extends TestCase { - /** - * @covers \LmcRbac\Rbac::isGranted - */ public function testCanConvertSingleRole(): void { $role = new Role('Foo'); @@ -45,18 +40,12 @@ public function testCanConvertSingleRole(): void $this->assertTrue($rbac->isGranted($role, 'permission')); } - /** - * @covers \LmcRbac\Rbac::isGranted - */ public function testCanUseEmptyArray(): void { $rbac = new Rbac(); $this->assertFalse($rbac->isGranted([], 'permission')); } - /** - * @covers \LmcRbac\Rbac::isGranted - */ public function testCanCheckMultipleRolesWithMatchingPermission(): void { $role1 = new Role('Foo'); @@ -70,9 +59,6 @@ public function testCanCheckMultipleRolesWithMatchingPermission(): void $this->assertTrue($rbac->isGranted($roles, 'permission')); } - /** - * @covers \LmcRbac\Rbac::isGranted - */ public function testReturnFalseIfNoRoleHasPermission(): void { $role1 = new Role('Foo'); @@ -84,9 +70,6 @@ public function testReturnFalseIfNoRoleHasPermission(): void $this->assertFalse($rbac->isGranted($roles, 'permission')); } - /** - * @covers \LmcRbac\Rbac::isGranted - */ public function testCanCheckHierarchicalRole(): void { $childRole = new Role('Bar'); @@ -100,9 +83,6 @@ public function testCanCheckHierarchicalRole(): void $this->assertTrue($rbac->isGranted($parentRole, 'permission')); } - /** - * @covers \LmcRbac\Rbac::isGranted - */ public function testReturnFalseIfNoHierarchicalRoleHasPermission(): void { $childRole = new Role('Bar'); @@ -115,9 +95,6 @@ public function testReturnFalseIfNoHierarchicalRoleHasPermission(): void $this->assertFalse($rbac->isGranted($parentRole, 'permission')); } - /** - * @covers \LmcRbac\Rbac::isGranted - */ public function testCanCheckTraversableAsRolesList(): void { $role1 = new Role('Foo'); diff --git a/test/Role/HierarchicalRoleTest.php b/test/Role/HierarchicalRoleTest.php index 54bc7087..1fbfbb5d 100644 --- a/test/Role/HierarchicalRoleTest.php +++ b/test/Role/HierarchicalRoleTest.php @@ -23,17 +23,12 @@ use LmcRbac\Role\HierarchicalRole; use LmcRbac\Role\HierarchicalRoleInterface; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \LmcRbac\Role\HierarchicalRole - * @group Coverage - */ +#[CoversClass('\LmcRbac\Role\HierarchicalRole')] class HierarchicalRoleTest extends TestCase { - /** - * @covers \LmcRbac\Role\HierarchicalRole::addChild - */ public function testCanAddChild(): void { $role = new HierarchicalRole('role'); @@ -44,9 +39,6 @@ public function testCanAddChild(): void $this->assertCount(1, $role->getChildren()); } - /** - * @covers \LmcRbac\Role\HierarchicalRole::hasChildren - */ public function testHasChildren(): void { $role = new HierarchicalRole('role'); @@ -58,9 +50,6 @@ public function testHasChildren(): void $this->assertTrue($role->hasChildren()); } - /** - * @covers \LmcRbac\Role\HierarchicalRole::getChildren - */ public function testCanGetChildren(): void { $role = new HierarchicalRole('role'); @@ -76,9 +65,6 @@ public function testCanGetChildren(): void $this->assertContainsOnlyInstancesOf(HierarchicalRoleInterface::class, $children); } - /** - * @covers \LmcRbac\Role\HierarchicalRole::addPermission - */ public function testRoleCanAddPermission(): void { $role = new HierarchicalRole('php'); @@ -88,9 +74,6 @@ public function testRoleCanAddPermission(): void $this->assertTrue($role->hasPermission('delete')); } - /** - * @covers \LmcRbac\Role\HierarchicalRole::getPermissions - */ public function testRoleCanGetPermissions(): void { $role = new HierarchicalRole('php'); diff --git a/test/Role/InMemoryRoleProviderTest.php b/test/Role/InMemoryRoleProviderTest.php index eec80f38..6f4406c9 100644 --- a/test/Role/InMemoryRoleProviderTest.php +++ b/test/Role/InMemoryRoleProviderTest.php @@ -24,11 +24,10 @@ use LmcRbac\Role\HierarchicalRoleInterface; use LmcRbac\Role\InMemoryRoleProvider; use LmcRbac\Role\RoleInterface; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \LmcRbac\Role\InMemoryRoleProvider - */ +#[CoversClass('\LmcRbac\Role\InMemoryRoleProvider')] class InMemoryRoleProviderTest extends TestCase { public function testInMemoryProvider(): void diff --git a/test/Role/ObjectRepositoryRoleProviderTest.php b/test/Role/ObjectRepositoryRoleProviderTest.php index c130065a..d7b65caf 100644 --- a/test/Role/ObjectRepositoryRoleProviderTest.php +++ b/test/Role/ObjectRepositoryRoleProviderTest.php @@ -24,11 +24,10 @@ use Doctrine\Persistence\ObjectRepository; use LmcRbac\Role\ObjectRepositoryRoleProvider; use LmcRbacTest\Asset\FlatRole; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \LmcRbac\Role\ObjectRepositoryRoleProvider - */ +#[CoversClass('\LmcRbac\Role\ObjectRepositoryRoleProvider')] class ObjectRepositoryRoleProviderTest extends TestCase { public function testObjectRepositoryProviderGetRoles(): void @@ -38,7 +37,7 @@ public function testObjectRepositoryProviderGetRoles(): void $provider = new ObjectRepositoryRoleProvider($objectRepository, 'name'); $result = [$memberRole]; - $objectRepository->expects($this->once())->method('findBy')->will($this->returnValue($result)); + $objectRepository->expects($this->once())->method('findBy')->willReturn($result); $this->assertEquals($result, $provider->getRoles(['member'])); } @@ -51,7 +50,7 @@ public function testRoleCacheOnConsecutiveCalls(): void $result = [$memberRole]; // note exactly once, consecutive call come from cache - $objectRepository->expects($this->exactly(1))->method('findBy')->will($this->returnValue($result)); + $objectRepository->expects($this->exactly(1))->method('findBy')->willReturn($result); $provider->getRoles(['member']); $provider->getRoles(['member']); @@ -65,7 +64,7 @@ public function testClearRoleCache(): void $result = [$memberRole]; // note exactly twice, as cache is cleared - $objectRepository->expects($this->exactly(2))->method('findBy')->will($this->returnValue($result)); + $objectRepository->expects($this->exactly(2))->method('findBy')->willReturn($result); $provider->getRoles(['member']); $provider->clearRoleCache(); @@ -79,7 +78,7 @@ public function testThrowExceptionIfAskedRoleIsNotFound(): void $provider = new ObjectRepositoryRoleProvider($objectRepository, 'name'); $result = [$memberRole]; - $objectRepository->expects($this->once())->method('findBy')->will($this->returnValue($result)); + $objectRepository->expects($this->once())->method('findBy')->willReturn($result); $this->expectException('LmcRbac\Exception\RoleNotFoundException'); $this->expectExceptionMessage('Some roles were asked but could not be loaded from database: guest, admin'); diff --git a/test/Role/RoleTest.php b/test/Role/RoleTest.php index 59d4eeb9..eadcfd51 100644 --- a/test/Role/RoleTest.php +++ b/test/Role/RoleTest.php @@ -22,12 +22,10 @@ namespace LmcRbacTest\Role; use LmcRbac\Role\Role; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \LmcRbac\Role\Role - * @group Coverage - */ +#[CoversClass('\LmcRbac\Role\Role')] class RoleTest extends TestCase { public function testSetNameByConstructor(): void @@ -36,9 +34,6 @@ public function testSetNameByConstructor(): void $this->assertEquals('phpIsHell', $role->getName()); } - /** - * @covers \LmcRbac\Role\Role::addPermission - */ public function testRoleCanAddPermission(): void { $role = new Role('php'); @@ -51,9 +46,6 @@ public function testRoleCanAddPermission(): void $this->assertTrue($role->hasPermission('delete')); } - /** - * @covers \LmcRbac\Role\Role::getPermissions - */ public function testRoleCanGetPermissions(): void { $role = new Role('php'); diff --git a/test/Service/AuthorizationServiceTest.php b/test/Service/AuthorizationServiceTest.php index 5a11039e..858d5d7d 100644 --- a/test/Service/AuthorizationServiceTest.php +++ b/test/Service/AuthorizationServiceTest.php @@ -36,11 +36,11 @@ use LmcRbacTest\Asset\FlatRole; use LmcRbacTest\Asset\Identity; use LmcRbacTest\Asset\SimpleAssertion; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; -/** - * @covers \LmcRbac\Service\AuthorizationService - */ +#[CoversClass('\LmcRbac\Service\AuthorizationService')] class AuthorizationServiceTest extends TestCase { public static function grantedProvider(): array @@ -155,9 +155,7 @@ public static function grantedProvider(): array ]; } - /** - * @dataProvider grantedProvider - */ + #[DataProvider('grantedProvider')] public function testGranted($role, $permission, $context, bool $isGranted, array $assertions = []): void { $roleConfig = [ @@ -195,7 +193,7 @@ public function testDoNotCallAssertionIfThePermissionIsNotGranted(): void $rbac = $this->getMockBuilder(Rbac::class)->disableOriginalConstructor()->getMock(); $roleService = $this->getMockBuilder(RoleServiceInterface::class)->getMock(); - $roleService->expects($this->once())->method('getIdentityRoles')->will($this->returnValue([$role])); + $roleService->expects($this->once())->method('getIdentityRoles')->willReturn([$role]); $assertionContainer = $this->getMockBuilder(AssertionContainerInterface::class)->getMock(); $assertionContainer->expects($this->never())->method('get'); @@ -213,7 +211,7 @@ public function testReturnsFalseForIdentityWithoutRoles(): void $rbac->expects($this->never())->method('isGranted'); $roleService = $this->getMockBuilder(RoleServiceInterface::class)->getMock(); - $roleService->expects($this->once())->method('getIdentityRoles')->will($this->returnValue($identity->getRoles())); + $roleService->expects($this->once())->method('getIdentityRoles')->willReturn($identity->getRoles()); $assertionContainer = $this->getMockBuilder(AssertionContainerInterface::class)->getMock(); $assertionContainer->expects($this->never())->method('get'); @@ -229,7 +227,7 @@ public function testReturnsTrueForIdentityWhenHasPermissionButNoAssertionsExists $identity = new Identity([$role]); $roleService = $this->getMockBuilder(RoleServiceInterface::class)->getMock(); - $roleService->expects($this->once())->method('getIdentityRoles')->will($this->returnValue($identity->getRoles())); + $roleService->expects($this->once())->method('getIdentityRoles')->willReturn($identity->getRoles()); $rbac = $this->getMockBuilder(Rbac::class)->disableOriginalConstructor()->getMock(); $rbac->expects($this->once())->method('isGranted')->willReturn(true); @@ -249,7 +247,7 @@ public function testUsesAssertionsAsInstances(): void $assertion = new SimpleAssertion(); $roleService = $this->getMockBuilder(RoleServiceInterface::class)->getMock(); - $roleService->expects($this->once())->method('getIdentityRoles')->will($this->returnValue($identity->getRoles())); + $roleService->expects($this->once())->method('getIdentityRoles')->willReturn($identity->getRoles()); $rbac = $this->getMockBuilder(Rbac::class)->disableOriginalConstructor()->getMock(); $rbac->expects($this->once())->method('isGranted')->willReturn(true); @@ -271,7 +269,7 @@ public function testUsesAssertionsAsStrings(): void $assertion = new SimpleAssertion(); $roleService = $this->getMockBuilder(RoleServiceInterface::class)->getMock(); - $roleService->expects($this->once())->method('getIdentityRoles')->will($this->returnValue($identity->getRoles())); + $roleService->expects($this->once())->method('getIdentityRoles')->willReturn($identity->getRoles()); $rbac = $this->getMockBuilder(Rbac::class)->disableOriginalConstructor()->getMock(); $rbac->expects($this->once())->method('isGranted')->willReturn(true); @@ -292,7 +290,7 @@ public function testUsesAssertionsAsCallable(): void $identity = new Identity([$role]); $roleService = $this->getMockBuilder(RoleServiceInterface::class)->getMock(); - $roleService->expects($this->once())->method('getIdentityRoles')->will($this->returnValue($identity->getRoles())); + $roleService->expects($this->once())->method('getIdentityRoles')->willReturn($identity->getRoles()); $rbac = $this->getMockBuilder(Rbac::class)->disableOriginalConstructor()->getMock(); $rbac->expects($this->once())->method('isGranted')->willReturn(true); @@ -326,7 +324,7 @@ public function testUsesAssertionsAsArrays(): void $identity = new Identity([$role]); $roleService = $this->getMockBuilder(RoleServiceInterface::class)->getMock(); - $roleService->expects($this->once())->method('getIdentityRoles')->will($this->returnValue($identity->getRoles())); + $roleService->expects($this->once())->method('getIdentityRoles')->willReturn($identity->getRoles()); $rbac = $this->getMockBuilder(Rbac::class)->disableOriginalConstructor()->getMock(); $rbac->expects($this->once())->method('isGranted')->willReturn(true); @@ -363,10 +361,10 @@ public function testThrowExceptionForInvalidAssertion(): void $role = $this->getMockBuilder(RoleInterface::class)->getMock(); $rbac = $this->getMockBuilder(Rbac::class)->disableOriginalConstructor()->getMock(); - $rbac->expects($this->once())->method('isGranted')->will($this->returnValue(true)); + $rbac->expects($this->once())->method('isGranted')->willReturn(true); $roleService = $this->getMockBuilder(RoleServiceInterface::class)->getMock(); - $roleService->expects($this->once())->method('getIdentityRoles')->will($this->returnValue([$role])); + $roleService->expects($this->once())->method('getIdentityRoles')->willReturn([$role]); $assertionContainer = $this->getMockBuilder(AssertionContainerInterface::class)->disableOriginalConstructor()->getMock(); $authorizationService = new AuthorizationService($rbac, $roleService, $assertionContainer, ['foo' => new \stdClass()]); diff --git a/test/Service/RoleServiceTest.php b/test/Service/RoleServiceTest.php index 1ebb29aa..d253a487 100644 --- a/test/Service/RoleServiceTest.php +++ b/test/Service/RoleServiceTest.php @@ -29,13 +29,12 @@ use LmcRbac\Role\RoleProviderInterface; use LmcRbac\Service\RoleService; use LmcRbacTest\Asset\Identity; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Prophecy\Argument; use Prophecy\PhpUnit\ProphecyTrait; -/** - * @covers \LmcRbac\Service\RoleService - */ +#[CoversClass('\LmcRbac\Service\RoleService')] class RoleServiceTest extends TestCase { use ProphecyTrait;