Skip to content

Commit

Permalink
Merge pull request #74 from visto9259/master
Browse files Browse the repository at this point in the history
Added support for phpunit v11. Fixed phpunit deprecations and attributes
  • Loading branch information
visto9259 authored Aug 7, 2024
2 parents 962e9c5 + 4d8065c commit 3b476a3
Show file tree
Hide file tree
Showing 20 changed files with 59 additions and 127 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 4 additions & 7 deletions renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
5 changes: 2 additions & 3 deletions test/Assertion/AssertionContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
10 changes: 4 additions & 6 deletions test/Assertion/AssertionSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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();
Expand Down
5 changes: 2 additions & 3 deletions test/ConfigProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 2 additions & 3 deletions test/Container/AssertionContainerFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions test/Container/AuthorizationServiceFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions test/Container/InMemoryRoleProviderFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions test/Container/ModuleOptionsFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions test/Container/ObjectRepositoryRoleProviderFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand Down
5 changes: 2 additions & 3 deletions test/Container/RoleServiceFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions test/ModuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 2 additions & 3 deletions test/Options/ModuleOptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 2 additions & 25 deletions test/RbacTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -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');
Expand Down
21 changes: 2 additions & 19 deletions test/Role/HierarchicalRoleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -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');
Expand Down
5 changes: 2 additions & 3 deletions test/Role/InMemoryRoleProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 3b476a3

Please sign in to comment.