Skip to content

Commit

Permalink
Fix deprecations triggered by PHP 8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabus committed Jan 19, 2022
1 parent 49bbad0 commit 2d25fbc
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 46 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['7.2.5', '7.3', '7.4', '8.0']
php: ['7.2.5', '7.3', '7.4', '8.0', '8.1']
include:
- php: '7.4'
deps: lowest
Expand Down Expand Up @@ -56,6 +56,6 @@ jobs:
- name: Checkout code
uses: actions/checkout@v2
- name: PHP-CS-Fixer
uses: docker://oskarstark/php-cs-fixer-ga:3.0.0
uses: docker://oskarstark/php-cs-fixer-ga:3.2.1
with:
args: --diff --dry-run
10 changes: 4 additions & 6 deletions Domain/Acl.php
Original file line number Diff line number Diff line change
Expand Up @@ -499,17 +499,16 @@ private function insertAce($property, $index, $mask, SecurityIdentityInterface $
*
* @param string $property
* @param int $index
* @param string $field
* @param int $mask
* @param bool $granting
* @param string $strategy
*
* @throws \InvalidArgumentException
* @throws \OutOfBoundsException
*/
private function insertFieldAce($property, $index, $field, $mask, SecurityIdentityInterface $sid, $granting, $strategy = null)
private function insertFieldAce($property, $index, string $field, $mask, SecurityIdentityInterface $sid, $granting, $strategy = null)
{
if (0 === \strlen($field)) {
if ('' === $field) {
throw new \InvalidArgumentException('$field cannot be empty.');
}

Expand Down Expand Up @@ -611,16 +610,15 @@ private function updateAuditing(array &$aces, $index, $auditSuccess, $auditFailu
*
* @param string $property
* @param int $index
* @param string $field
* @param int $mask
* @param string $strategy
*
* @throws \InvalidArgumentException
* @throws \OutOfBoundsException
*/
private function updateFieldAce($property, $index, $field, $mask, $strategy = null)
private function updateFieldAce($property, $index, string $field, $mask, $strategy = null)
{
if (0 === \strlen($field)) {
if ('' === $field) {
throw new \InvalidArgumentException('$field cannot be empty.');
}

Expand Down
8 changes: 2 additions & 6 deletions Domain/DoctrineAclCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,11 @@ class DoctrineAclCache implements AclCacheInterface
private $cache;

/**
* Constructor.
*
* @param string $prefix
*
* @throws \InvalidArgumentException
*/
public function __construct(Cache $cache, PermissionGrantingStrategyInterface $permissionGrantingStrategy, $prefix = self::PREFIX)
public function __construct(Cache $cache, PermissionGrantingStrategyInterface $permissionGrantingStrategy, string $prefix = self::PREFIX)
{
if (0 === \strlen($prefix)) {
if ('' === $prefix) {
throw new \InvalidArgumentException('$prefix cannot be empty.');
}

Expand Down
2 changes: 1 addition & 1 deletion Domain/PsrAclCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class PsrAclCache implements AclCacheInterface
*/
public function __construct(CacheItemPoolInterface $cache, PermissionGrantingStrategyInterface $permissionGrantingStrategy, string $prefix = self::PREFIX)
{
if (0 === \strlen($prefix)) {
if ('' === $prefix) {
throw new \InvalidArgumentException('$prefix cannot be empty.');
}

Expand Down
10 changes: 7 additions & 3 deletions Tests/Domain/AuditLoggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@

namespace Symfony\Component\Security\Acl\Tests\Domain;

class AuditLoggerTest extends \PHPUnit\Framework\TestCase
use PHPUnit\Framework\TestCase;
use Symfony\Component\Security\Acl\Domain\AuditLogger;
use Symfony\Component\Security\Acl\Tests\Fixtures\SerializableAuditableEntryInterface;

class AuditLoggerTest extends TestCase
{
/**
* @dataProvider getTestLogData
Expand Down Expand Up @@ -73,11 +77,11 @@ public function getTestLogData()

protected function getEntry()
{
return $this->createMock('Symfony\Component\Security\Acl\Model\AuditableEntryInterface');
return $this->createMock(SerializableAuditableEntryInterface::class);
}

protected function getLogger()
{
return $this->getMockForAbstractClass('Symfony\Component\Security\Acl\Domain\AuditLogger');
return $this->getMockForAbstractClass(AuditLogger::class);
}
}
16 changes: 2 additions & 14 deletions Tests/Domain/DoctrineAclCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,11 @@ class DoctrineAclCacheTest extends TestCase
{
protected $permissionGrantingStrategy;

/**
* @dataProvider getEmptyValue
*/
public function testConstructorDoesNotAcceptEmptyPrefix($empty)
public function testConstructorDoesNotAcceptEmptyPrefix()
{
$this->expectException(\InvalidArgumentException::class);

new DoctrineAclCache(DoctrineProvider::wrap(new ArrayAdapter()), $this->getPermissionGrantingStrategy(), $empty);
}

public function getEmptyValue()
{
return [
[null],
[false],
[''],
];
new DoctrineAclCache(DoctrineProvider::wrap(new ArrayAdapter()), $this->getPermissionGrantingStrategy(), '');
}

public function test()
Expand Down
11 changes: 7 additions & 4 deletions Tests/Domain/EntryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@

namespace Symfony\Component\Security\Acl\Tests\Domain;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Security\Acl\Domain\Entry;
use Symfony\Component\Security\Acl\Model\SecurityIdentityInterface;
use Symfony\Component\Security\Acl\Tests\Fixtures\SerializableAclInterface;

class EntryTest extends \PHPUnit\Framework\TestCase
class EntryTest extends TestCase
{
public function testConstructor()
{
Expand Down Expand Up @@ -77,7 +80,7 @@ public function testSerializeUnserialize()
$uAce = unserialize($serialized);

$this->assertNull($uAce->getAcl());
$this->assertInstanceOf('Symfony\Component\Security\Acl\Model\SecurityIdentityInterface', $uAce->getSecurityIdentity());
$this->assertInstanceOf(SecurityIdentityInterface::class, $uAce->getSecurityIdentity());
$this->assertEquals($ace->getId(), $uAce->getId());
$this->assertEquals($ace->getMask(), $uAce->getMask());
$this->assertEquals($ace->getStrategy(), $uAce->getStrategy());
Expand Down Expand Up @@ -109,11 +112,11 @@ protected function getAce($acl = null, $sid = null)

protected function getAcl()
{
return $this->createMock('Symfony\Component\Security\Acl\Model\AclInterface');
return $this->createMock(SerializableAclInterface::class);
}

protected function getSid()
{
return $this->createMock('Symfony\Component\Security\Acl\Model\SecurityIdentityInterface');
return $this->createMock(SecurityIdentityInterface::class);
}
}
10 changes: 6 additions & 4 deletions Tests/Domain/FieldEntryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@

namespace Symfony\Component\Security\Acl\Tests\Domain;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Security\Acl\Domain\FieldEntry;
use Symfony\Component\Security\Acl\Model\SecurityIdentityInterface;
use Symfony\Component\Security\Acl\Tests\Fixtures\SerializableAclInterface;

class FieldEntryTest extends \PHPUnit\Framework\TestCase
class FieldEntryTest extends TestCase
{
public function testConstructor()
{
Expand All @@ -31,7 +33,7 @@ public function testSerializeUnserialize()
$uAce = unserialize($serialized);

$this->assertNull($uAce->getAcl());
$this->assertInstanceOf('Symfony\Component\Security\Acl\Model\SecurityIdentityInterface', $uAce->getSecurityIdentity());
$this->assertInstanceOf(SecurityIdentityInterface::class, $uAce->getSecurityIdentity());
$this->assertEquals($ace->getId(), $uAce->getId());
$this->assertEquals($ace->getField(), $uAce->getField());
$this->assertEquals($ace->getMask(), $uAce->getMask());
Expand Down Expand Up @@ -86,11 +88,11 @@ protected function getAce($acl = null, $sid = null)

protected function getAcl()
{
return $this->createMock('Symfony\Component\Security\Acl\Model\AclInterface');
return $this->createMock(SerializableAclInterface::class);
}

protected function getSid()
{
return $this->createMock('Symfony\Component\Security\Acl\Model\SecurityIdentityInterface');
return $this->createMock(SecurityIdentityInterface::class);
}
}
12 changes: 12 additions & 0 deletions Tests/Fixtures/SerializableAclInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Symfony\Component\Security\Acl\Tests\Fixtures;

use Symfony\Component\Security\Acl\Model\AclInterface;

interface SerializableAclInterface extends AclInterface
{
public function __serialize(): array;

public function __unserialize(array $data): void;
}
12 changes: 12 additions & 0 deletions Tests/Fixtures/SerializableAuditableEntryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Symfony\Component\Security\Acl\Tests\Fixtures;

use Symfony\Component\Security\Acl\Model\AuditableEntryInterface;

interface SerializableAuditableEntryInterface extends AuditableEntryInterface
{
public function __serialize(): array;

public function __unserialize(array $data): void;
}
12 changes: 6 additions & 6 deletions Tests/Voter/AclVoterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
use Symfony\Component\Security\Acl\Domain\UserSecurityIdentity;
use Symfony\Component\Security\Acl\Exception\AclNotFoundException;
use Symfony\Component\Security\Acl\Exception\NoAceFoundException;
use Symfony\Component\Security\Acl\Model\AclInterface;
use Symfony\Component\Security\Acl\Model\AclProviderInterface;
use Symfony\Component\Security\Acl\Model\ObjectIdentityRetrievalStrategyInterface;
use Symfony\Component\Security\Acl\Model\SecurityIdentityRetrievalStrategyInterface;
use Symfony\Component\Security\Acl\Permission\PermissionMapInterface;
use Symfony\Component\Security\Acl\Tests\Fixtures\SerializableAclInterface;
use Symfony\Component\Security\Acl\Voter\AclVoter;
use Symfony\Component\Security\Acl\Voter\FieldVote;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
Expand Down Expand Up @@ -220,7 +220,7 @@ public function testVoteGrantsAccess($grant)
->expects($this->once())
->method('findAcl')
->with($this->equalTo($oid), $this->equalTo($sids))
->willReturn($acl = $this->createMock(AclInterface::class))
->willReturn($acl = $this->createMock(SerializableAclInterface::class))
;

$acl
Expand Down Expand Up @@ -266,7 +266,7 @@ public function testVoteNoAceFound()
->expects($this->once())
->method('findAcl')
->with($this->equalTo($oid), $this->equalTo($sids))
->willReturn($acl = $this->createMock(AclInterface::class))
->willReturn($acl = $this->createMock(SerializableAclInterface::class))
;

$acl
Expand Down Expand Up @@ -309,7 +309,7 @@ public function testVoteGrantsFieldAccess($grant)
->expects($this->once())
->method('findAcl')
->with($this->equalTo($oid), $this->equalTo($sids))
->willReturn($acl = $this->createMock(AclInterface::class))
->willReturn($acl = $this->createMock(SerializableAclInterface::class))
;

$acl
Expand Down Expand Up @@ -355,7 +355,7 @@ public function testVoteNoFieldAceFound()
->expects($this->once())
->method('findAcl')
->with($this->equalTo($oid), $this->equalTo($sids))
->willReturn($acl = $this->createMock(AclInterface::class))
->willReturn($acl = $this->createMock(SerializableAclInterface::class))
;

$acl
Expand Down Expand Up @@ -396,7 +396,7 @@ public function testWhenReceivingAnObjectIdentityInterfaceWeDontRetrieveANewObje
->expects($this->once())
->method('findAcl')
->with($this->equalTo($oid), $this->equalTo($sids))
->willReturn($acl = $this->createMock(AclInterface::class))
->willReturn($acl = $this->createMock(SerializableAclInterface::class))
;

$acl
Expand Down

0 comments on commit 2d25fbc

Please sign in to comment.