Skip to content

Commit c25e4bf

Browse files
committed
Fix deprecations triggered by PHP 8.1
1 parent 324ce98 commit c25e4bf

File tree

11 files changed

+61
-46
lines changed

11 files changed

+61
-46
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
strategy:
1414
fail-fast: false
1515
matrix:
16-
php: ['7.2.5', '7.3', '7.4', '8.0']
16+
php: ['7.2.5', '7.3', '7.4', '8.0', '8.1']
1717
include:
1818
- php: '7.4'
1919
deps: lowest
@@ -56,6 +56,6 @@ jobs:
5656
- name: Checkout code
5757
uses: actions/checkout@v2
5858
- name: PHP-CS-Fixer
59-
uses: docker://oskarstark/php-cs-fixer-ga:3.0.0
59+
uses: docker://oskarstark/php-cs-fixer-ga:3.2.1
6060
with:
6161
args: --diff --dry-run

Domain/Acl.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -499,17 +499,16 @@ private function insertAce($property, $index, $mask, SecurityIdentityInterface $
499499
*
500500
* @param string $property
501501
* @param int $index
502-
* @param string $field
503502
* @param int $mask
504503
* @param bool $granting
505504
* @param string $strategy
506505
*
507506
* @throws \InvalidArgumentException
508507
* @throws \OutOfBoundsException
509508
*/
510-
private function insertFieldAce($property, $index, $field, $mask, SecurityIdentityInterface $sid, $granting, $strategy = null)
509+
private function insertFieldAce($property, $index, string $field, $mask, SecurityIdentityInterface $sid, $granting, $strategy = null)
511510
{
512-
if (0 === \strlen($field)) {
511+
if ('' === $field) {
513512
throw new \InvalidArgumentException('$field cannot be empty.');
514513
}
515514

@@ -611,16 +610,15 @@ private function updateAuditing(array &$aces, $index, $auditSuccess, $auditFailu
611610
*
612611
* @param string $property
613612
* @param int $index
614-
* @param string $field
615613
* @param int $mask
616614
* @param string $strategy
617615
*
618616
* @throws \InvalidArgumentException
619617
* @throws \OutOfBoundsException
620618
*/
621-
private function updateFieldAce($property, $index, $field, $mask, $strategy = null)
619+
private function updateFieldAce($property, $index, string $field, $mask, $strategy = null)
622620
{
623-
if (0 === \strlen($field)) {
621+
if ('' === $field) {
624622
throw new \InvalidArgumentException('$field cannot be empty.');
625623
}
626624

Domain/DoctrineAclCache.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,11 @@ class DoctrineAclCache implements AclCacheInterface
3232
private $cache;
3333

3434
/**
35-
* Constructor.
36-
*
37-
* @param string $prefix
38-
*
3935
* @throws \InvalidArgumentException
4036
*/
41-
public function __construct(Cache $cache, PermissionGrantingStrategyInterface $permissionGrantingStrategy, $prefix = self::PREFIX)
37+
public function __construct(Cache $cache, PermissionGrantingStrategyInterface $permissionGrantingStrategy, string $prefix = self::PREFIX)
4238
{
43-
if (0 === \strlen($prefix)) {
39+
if ('' === $prefix) {
4440
throw new \InvalidArgumentException('$prefix cannot be empty.');
4541
}
4642

Domain/PsrAclCache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class PsrAclCache implements AclCacheInterface
3535
*/
3636
public function __construct(CacheItemPoolInterface $cache, PermissionGrantingStrategyInterface $permissionGrantingStrategy, string $prefix = self::PREFIX)
3737
{
38-
if (0 === \strlen($prefix)) {
38+
if ('' === $prefix) {
3939
throw new \InvalidArgumentException('$prefix cannot be empty.');
4040
}
4141

Tests/Domain/AuditLoggerTest.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111

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

14-
class AuditLoggerTest extends \PHPUnit\Framework\TestCase
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Security\Acl\Domain\AuditLogger;
16+
use Symfony\Component\Security\Acl\Tests\Fixtures\SerializableAuditableEntryInterface;
17+
18+
class AuditLoggerTest extends TestCase
1519
{
1620
/**
1721
* @dataProvider getTestLogData
@@ -73,11 +77,11 @@ public function getTestLogData()
7377

7478
protected function getEntry()
7579
{
76-
return $this->createMock('Symfony\Component\Security\Acl\Model\AuditableEntryInterface');
80+
return $this->createMock(SerializableAuditableEntryInterface::class);
7781
}
7882

7983
protected function getLogger()
8084
{
81-
return $this->getMockForAbstractClass('Symfony\Component\Security\Acl\Domain\AuditLogger');
85+
return $this->getMockForAbstractClass(AuditLogger::class);
8286
}
8387
}

Tests/Domain/DoctrineAclCacheTest.php

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,11 @@ class DoctrineAclCacheTest extends TestCase
2424
{
2525
protected $permissionGrantingStrategy;
2626

27-
/**
28-
* @dataProvider getEmptyValue
29-
*/
30-
public function testConstructorDoesNotAcceptEmptyPrefix($empty)
27+
public function testConstructorDoesNotAcceptEmptyPrefix()
3128
{
3229
$this->expectException(\InvalidArgumentException::class);
3330

34-
new DoctrineAclCache(DoctrineProvider::wrap(new ArrayAdapter()), $this->getPermissionGrantingStrategy(), $empty);
35-
}
36-
37-
public function getEmptyValue()
38-
{
39-
return [
40-
[null],
41-
[false],
42-
[''],
43-
];
31+
new DoctrineAclCache(DoctrineProvider::wrap(new ArrayAdapter()), $this->getPermissionGrantingStrategy(), '');
4432
}
4533

4634
public function test()

Tests/Domain/EntryTest.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@
1111

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

14+
use PHPUnit\Framework\TestCase;
1415
use Symfony\Component\Security\Acl\Domain\Entry;
16+
use Symfony\Component\Security\Acl\Model\SecurityIdentityInterface;
17+
use Symfony\Component\Security\Acl\Tests\Fixtures\SerializableAclInterface;
1518

16-
class EntryTest extends \PHPUnit\Framework\TestCase
19+
class EntryTest extends TestCase
1720
{
1821
public function testConstructor()
1922
{
@@ -77,7 +80,7 @@ public function testSerializeUnserialize()
7780
$uAce = unserialize($serialized);
7881

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

110113
protected function getAcl()
111114
{
112-
return $this->createMock('Symfony\Component\Security\Acl\Model\AclInterface');
115+
return $this->createMock(SerializableAclInterface::class);
113116
}
114117

115118
protected function getSid()
116119
{
117-
return $this->createMock('Symfony\Component\Security\Acl\Model\SecurityIdentityInterface');
120+
return $this->createMock(SecurityIdentityInterface::class);
118121
}
119122
}

Tests/Domain/FieldEntryTest.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111

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

14+
use PHPUnit\Framework\TestCase;
1415
use Symfony\Component\Security\Acl\Domain\FieldEntry;
1516
use Symfony\Component\Security\Acl\Model\SecurityIdentityInterface;
17+
use Symfony\Component\Security\Acl\Tests\Fixtures\SerializableAclInterface;
1618

17-
class FieldEntryTest extends \PHPUnit\Framework\TestCase
19+
class FieldEntryTest extends TestCase
1820
{
1921
public function testConstructor()
2022
{
@@ -31,7 +33,7 @@ public function testSerializeUnserialize()
3133
$uAce = unserialize($serialized);
3234

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

8789
protected function getAcl()
8890
{
89-
return $this->createMock('Symfony\Component\Security\Acl\Model\AclInterface');
91+
return $this->createMock(SerializableAclInterface::class);
9092
}
9193

9294
protected function getSid()
9395
{
94-
return $this->createMock('Symfony\Component\Security\Acl\Model\SecurityIdentityInterface');
96+
return $this->createMock(SecurityIdentityInterface::class);
9597
}
9698
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Symfony\Component\Security\Acl\Tests\Fixtures;
4+
5+
use Symfony\Component\Security\Acl\Model\AclInterface;
6+
7+
interface SerializableAclInterface extends AclInterface
8+
{
9+
public function __serialize(): array;
10+
11+
public function __unserialize(array $data): void;
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Symfony\Component\Security\Acl\Tests\Fixtures;
4+
5+
use Symfony\Component\Security\Acl\Model\AuditableEntryInterface;
6+
7+
interface SerializableAuditableEntryInterface extends AuditableEntryInterface
8+
{
9+
public function __serialize(): array;
10+
11+
public function __unserialize(array $data): void;
12+
}

0 commit comments

Comments
 (0)