From af88710d17e82ceade1af4589dacbfdae3417511 Mon Sep 17 00:00:00 2001 From: Bert Van Hauwaert Date: Mon, 6 Jun 2022 17:19:32 +0200 Subject: [PATCH] Add support for PHP 8.1 --- src/Collector/RbacCollector.php | 25 +++++++++++++++------ tests/Collector/RbacCollectorTest.php | 32 +++++++++++++-------------- 2 files changed, 34 insertions(+), 23 deletions(-) diff --git a/src/Collector/RbacCollector.php b/src/Collector/RbacCollector.php index 4523d1f6..3a0c645a 100644 --- a/src/Collector/RbacCollector.php +++ b/src/Collector/RbacCollector.php @@ -220,21 +220,32 @@ public function getCollection() */ public function serialize() { - return serialize($this->getCollection()); + return serialize($this->__serialize()); } /** * {@inheritDoc} */ - public function unserialize($serialized) + public function unserialize($data) { - $collection = unserialize($serialized); + $collection = unserialize($data); if (!is_array($collection)) { throw new InvalidArgumentException(__METHOD__ . ": Unserialized data should be an array."); } - $this->collectedGuards = $collection['guards']; - $this->collectedRoles = $collection['roles']; - $this->collectedPermissions = $collection['permissions']; - $this->collectedOptions = $collection['options']; + + $this->__unserialize($collection); + } + + public function __serialize(): array + { + return $this->getCollection(); + } + + public function __unserialize(array $data): void + { + $this->collectedGuards = $data['guards']; + $this->collectedRoles = $data['roles']; + $this->collectedPermissions = $data['permissions']; + $this->collectedOptions = $data['options']; } } diff --git a/tests/Collector/RbacCollectorTest.php b/tests/Collector/RbacCollectorTest.php index 74cb8aeb..f50354f1 100644 --- a/tests/Collector/RbacCollectorTest.php +++ b/tests/Collector/RbacCollectorTest.php @@ -147,14 +147,14 @@ public function testCanCollect() $identity = $this->createMock(IdentityInterface::class); // $identity = $this->getMock('LmcRbacMvc\Identity\IdentityInterface'); $identity->expects($this->once()) - ->method('getRoles') - ->will($this->returnValue($dataToCollect['identity_role'])); + ->method('getRoles') + ->will($this->returnValue($dataToCollect['identity_role'])); // $identityProvider = $this->getMock('LmcRbacMvc\Identity\IdentityProviderInterface'); $identityProvider = $this->createMock(\LmcRbacMvc\Identity\IdentityProviderInterface::class); $identityProvider->expects($this->once()) - ->method('getIdentity') - ->will($this->returnValue($identity)); + ->method('getIdentity') + ->will($this->returnValue($identity)); $roleService = new RoleService($identityProvider, new InMemoryRoleProvider($dataToCollect['role_config']), new RecursiveRoleIteratorStrategy()); @@ -305,19 +305,19 @@ private function collectPermissionsPropertyTestBase(RoleInterface $role) new RecursiveRoleIteratorStrategy() ); $serviceManager->setService('LmcRbacMvc\Service\RoleService', $roleService); -/* - $serviceManager->expects($this->at(0)) - ->method('get') - ->with('LmcRbacMvc\Service\RoleService') - ->will($this->returnValue($roleService)); -*/ + /* + $serviceManager->expects($this->at(0)) + ->method('get') + ->with('LmcRbacMvc\Service\RoleService') + ->will($this->returnValue($roleService)); + */ $serviceManager->setService('LmcRbacMvc\Options\ModuleOptions', new ModuleOptions()); -/* - $serviceManager->expects($this->at(1)) - ->method('get') - ->with('LmcRbacMvc\Options\ModuleOptions') - ->will($this->returnValue(new ModuleOptions())); -*/ + /* + $serviceManager->expects($this->at(1)) + ->method('get') + ->with('LmcRbacMvc\Options\ModuleOptions') + ->will($this->returnValue(new ModuleOptions())); + */ $collector = new RbacCollector(); $collector->collect($mvcEvent);