Skip to content

Commit

Permalink
Merge pull request #25 from becoded/avoid-deprecation-warning-serialize
Browse files Browse the repository at this point in the history
Implement __serialize and __unserialize in RbacCollector
  • Loading branch information
visto9259 authored Jun 10, 2022
2 parents 8fce78f + af88710 commit df3b5d5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 23 deletions.
25 changes: 18 additions & 7 deletions src/Collector/RbacCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}
}
32 changes: 16 additions & 16 deletions tests/Collector/RbacCollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit df3b5d5

Please sign in to comment.