Skip to content

Commit

Permalink
Added support for phpunit v11. Fixed phpunit deprecations
Browse files Browse the repository at this point in the history
Signed-off-by: Eric Richer [email protected] <[email protected]>
  • Loading branch information
visto9259 committed Aug 7, 2024
1 parent 8428160 commit 10c0eb5
Show file tree
Hide file tree
Showing 22 changed files with 59 additions and 118 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,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"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,17 @@

declare(strict_types=1);

namespace LmcRbacTest\Container;
namespace LmcRbacTest\Assertion;

use Laminas\ServiceManager\ServiceManager;
use Lmc\Rbac\Assertion\AssertionContainer;
use Lmc\Rbac\Assertion\AssertionContainerFactory;
use Lmc\Rbac\Assertion\AssertionPluginManager;
use Lmc\Rbac\Assertion\AssertionPluginManagerFactory;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;

/**
* @covers \Lmc\Rbac\Assertion\AssertionPluginManagerFactory
*/
#[CoversClass('\Lmc\Rbac\Assertion\AssertionPluginManagerFactory')]
class AssertionPluginManagerFactoryTest extends TestCase
{
public function testFactory(): void
Expand Down
5 changes: 2 additions & 3 deletions test/Assertion/AssertionPluginManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@
use Lmc\Rbac\Assertion\AssertionInterface;
use Lmc\Rbac\Assertion\AssertionPluginManager;
use LmcRbacTest\Asset\SimpleAssertion;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;

/**
* @covers \Lmc\Rbac\Assertion\AssertionPluginManager
*/
#[CoversClass('\Lmc\Rbac\Assertion\AssertionPluginManager')]
class AssertionPluginManagerTest 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 @@ -28,11 +28,11 @@
use Lmc\Rbac\Exception\InvalidArgumentException;
use Lmc\Rbac\Identity\IdentityInterface;
use LmcRbacTest\Asset\SimpleAssertion;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

/**
* @covers \Lmc\Rbac\Assertion\AssertionSet
*/
#[CoversClass('\Lmc\Rbac\Assertion\AssertionSet')]
class AssertionSetTest extends TestCase
{
public function testImplementsAssertionInterface()
Expand Down Expand Up @@ -222,9 +222,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(AssertionPluginManagerInterface::class)->getMock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* and is licensed under the MIT license.
*/

namespace LmcRbacTest\Service;
namespace LmcRbacTest\Asset;

/**
* @author Eric Richer <[email protected]>
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 Lmc\Rbac\ConfigProvider;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;

/**
* @covers \Lmc\Rbac\ConfigProvider
*/
#[CoversClass('Lmc\Rbac\ConfigProvider')]
class ConfigProviderTest extends TestCase
{
public function testProvidesExpectedConfiguration()
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 Lmc\Rbac\ConfigProvider;
use Lmc\Rbac\Module;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;

/**
* @covers \Lmc\Rbac\Module
*/
#[CoversClass('\Lmc\Rbac\Module')]
class ModuleTest extends TestCase
{
public function testProvidesExpectedConfiguration()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,15 @@

declare(strict_types=1);

namespace LmcRbacTest\Container;
namespace LmcRbacTest\Options;

use Laminas\ServiceManager\ServiceManager;
use Lmc\Rbac\Options\ModuleOptionsFactory;
use Lmc\Rbac\Options\ModuleOptions;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;

/**
* @covers \Lmc\Rbac\Options\ModuleOptionsFactory
*/
#[CoversClass('\Lmc\Rbac\Options\ModuleOptionsFactory')]
class ModuleOptionsFactoryTest extends TestCase
{
public function testFactory(): void
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 Lmc\Rbac\Options\ModuleOptions;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;

/**
* @covers \Lmc\Rbac\Options\ModuleOptions
*/
#[CoversClass('\Lmc\Rbac\Options\ModuleOptions')]
class ModuleOptionsTest extends TestCase
{
public function testAssertModuleDefaultOptions(): void
Expand Down
27 changes: 2 additions & 25 deletions test/Rbac/RbacTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,12 @@

use Lmc\Rbac\Rbac;
use Lmc\Rbac\Role\Role;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;

/**
* @covers \Lmc\Rbac\Rbac
* @group Coverage
*/
#[CoversClass('\Lmc\Rbac\Rbac')]
class RbacTest extends TestCase
{
/**
* @covers \Lmc\Rbac\Rbac::isGranted
*/
public function testCanConvertSingleRole(): void
{
$role = new Role('Foo');
Expand All @@ -44,18 +39,12 @@ public function testCanConvertSingleRole(): void
$this->assertTrue($rbac->isGranted($role, 'permission'));
}

/**
* @covers \Lmc\Rbac\Rbac::isGranted
*/
public function testCanUseEmptyArray(): void
{
$rbac = new Rbac();
$this->assertFalse($rbac->isGranted([], 'permission'));
}

/**
* @covers \Lmc\Rbac\Rbac::isGranted
*/
public function testCanCheckMultipleRolesWithMatchingPermission(): void
{
$role1 = new Role('Foo');
Expand All @@ -69,9 +58,6 @@ public function testCanCheckMultipleRolesWithMatchingPermission(): void
$this->assertTrue($rbac->isGranted($roles, 'permission'));
}

/**
* @covers \Lmc\Rbac\Rbac::isGranted
*/
public function testReturnFalseIfNoRoleHasPermission(): void
{
$role1 = new Role('Foo');
Expand All @@ -83,9 +69,6 @@ public function testReturnFalseIfNoRoleHasPermission(): void
$this->assertFalse($rbac->isGranted($roles, 'permission'));
}

/**
* @covers \Lmc\Rbac\Rbac::isGranted
*/
public function testCanCheckHierarchicalRole(): void
{
$childRole = new Role('Bar');
Expand All @@ -99,9 +82,6 @@ public function testCanCheckHierarchicalRole(): void
$this->assertTrue($rbac->isGranted($parentRole, 'permission'));
}

/**
* @covers \Lmc\Rbac\Rbac::isGranted
*/
public function testReturnFalseIfNoHierarchicalRoleHasPermission(): void
{
$childRole = new Role('Bar');
Expand All @@ -114,9 +94,6 @@ public function testReturnFalseIfNoHierarchicalRoleHasPermission(): void
$this->assertFalse($rbac->isGranted($parentRole, 'permission'));
}

/**
* @covers \Lmc\Rbac\Rbac::isGranted
*/
public function testCanCheckTraversableAsRolesList(): void
{
$role1 = new Role('Foo');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,16 @@

declare(strict_types=1);

namespace LmcRbacTest\Container;
namespace LmcRbacTest\Role;

use Laminas\ServiceManager\ServiceManager;
use Lmc\Rbac\Role\InMemoryRoleProviderFactory;
use Lmc\Rbac\Options\ModuleOptions;
use Lmc\Rbac\Role\InMemoryRoleProvider;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;

/**
* @covers \Lmc\Rbac\Role\InMemoryRoleProviderFactory
*/
#[CoversClass('\Lmc\Rbac\Role\InMemoryRoleProviderFactory')]
class InMemoryRoleProviderFactoryTest extends TestCase
{
public function testFactoryUsingObjectRepository(): void
Expand Down
5 changes: 2 additions & 3 deletions test/Role/InMemoryRoleProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@

use Lmc\Rbac\Role\InMemoryRoleProvider;
use Lmc\Rbac\Role\RoleInterface;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;

/**
* @covers \Lmc\Rbac\Role\InMemoryRoleProvider
*/
#[CoversClass('\Lmc\Rbac\Role\InMemoryRoleProvider')]
class InMemoryRoleProviderTest extends TestCase
{
public function testInMemoryProvider(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

declare(strict_types=1);

namespace LmcRbacTest\Container;
namespace LmcRbacTest\Role;

use Doctrine\Persistence\ObjectManager;
use Doctrine\Persistence\ObjectRepository;
Expand All @@ -28,11 +28,10 @@
use Lmc\Rbac\Exception\RuntimeException;
use Lmc\Rbac\Options\ModuleOptions;
use Lmc\Rbac\Role\ObjectRepositoryRoleProvider;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;

/**
* @covers \Lmc\Rbac\Role\ObjectRepositoryRoleProviderFactory
*/
#[CoversClass('\Lmc\Rbac\Role\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
10 changes: 4 additions & 6 deletions test/Role/ObjectRepositoryRoleProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
use Lmc\Rbac\Role\ObjectRepositoryRoleProvider;
use Lmc\Rbac\Role\Role;
use Lmc\Rbac\Role\RoleInterface;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

/**
* @covers \Lmc\Rbac\Role\ObjectRepositoryRoleProvider
*/
#[CoversClass('\Lmc\Rbac\Role\ObjectRepositoryRoleProvider')]
class ObjectRepositoryRoleProviderTest extends TestCase
{

Expand Down Expand Up @@ -113,9 +113,7 @@ public function testThrowExceptionIfAskedRoleIsNotFound(): void
$provider->getRoles(['guest', 'admin', 'member']);
}

/**
* @dataProvider roleProvider
*/
#[DataProvider('roleProvider')]
public function testObjectRepositoryProviderForFlatRole(array $rolesConfig, array $rolesToCheck)
{
$objectManager = $this->getObjectManager();
Expand Down
Loading

0 comments on commit 10c0eb5

Please sign in to comment.