8000 bug #121 Fix Symfony 7 compatibility (core23, jordisala1991) · symfony/security-acl@96a1d7e · GitHub
[go: up one dir, main page]

Skip to content

Commit 96a1d7e

Browse files
committed
bug #121 Fix Symfony 7 compatibility (core23, jordisala1991)
This PR was merged into the 3.x-dev branch. Discussion ---------- Fix Symfony 7 compatibility Continuation of #116 I want to see what is failing to fix it. Might close: #112 #115 #114 #121 Commits ------- 17f2255 Actualizar AclVoter.php 29379e6 fix cs issues c4c7ca0 suppress psalm since it is not fixable 1247ccb Fix tests 8647e14 Fix symfony 7 compatibility
2 parents 15b96b5 + 17f2255 commit 96a1d7e

File tree

5 files changed

+94
-15
lines changed

5 files changed

+94
-15
lines changed

.php-cs-fixer.dist.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
'@Symfony' => true,
88
'@Symfony:risky' => true,
99
'protected_to_private' => false,
10+
'phpdoc_to_comment' => ['ignored_tags' => ['psalm-suppress']],
1011
])
1112
->setRiskyAllowed(true)
1213
->setFinder(

Tests/Dbal/AclProviderTest.php

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

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

14+
use Doctrine\DBAL\Configuration;
1415
use Doctrine\DBAL\DriverManager;
16+
use Doctrine\DBAL\Schema\DefaultSchemaManagerFactory;
1517
use PHPUnit\Framework\TestCase;
1618
use Symfony\Component\Security\Acl\Dbal\AclProvider;
1719
use Symfony\Component\Security\Acl\Dbal\Schema;
@@ -146,10 +148,22 @@ public function testFindAcl()
146148

147149
protected function setUp(): void
148150
{
149-
$this->connection = DriverManager::getConnection([
150-
'driver' => 'pdo_sqlite',
151-
'memory' => true,
152-
]);
151+
$configuration = new Configuration();
152+
153+
/**
154+
* @psalm-suppress RedundantCondition Since we are compatibles with DBAL 2 and 3, we need to check if the method exists
155+
*/
156+
if (method_exists($configuration, 'setSchemaManagerFactory')) {
157+
$configuration->setSchemaManagerFactory(new DefaultSchemaManagerFactory());
158+
}
159+
160+
$this->connection = DriverManager::getConnection(
161+
[
162+
'driver' => 'pdo_sqlite',
163+
'memory' => true,
164+
],
165+
$configuration
166+
);
153167

154168
// import the schema
155169
$schema = new Schema($this->getOptions());
@@ -160,27 +174,50 @@ protected function setUp(): void
160174
// populate the schema with some test data
161175
$insertClassStmt = $this->connection->prepare('INSERT INTO acl_classes (id, class_type) VALUES (?, ?)');
162176
foreach ($this->getClassData() as $data) {
163-
$insertClassStmt->executeStatement($data);
177+
$insertClassStmt->bindValue(1, $data[0]);
178+
$insertClassStmt->bindValue(2, $data[1]);
179+
$insertClassStmt->executeStatement();
164180
}
165181

166182
$insertSidStmt = $this->connection->prepare('INSERT INTO acl_security_identities (id, identifier, username) VALUES (?, ?, ?)');
167183
foreach ($this->getSidData() as $data) {
168-
$insertSidStmt->executeStatement($data);
184+
$insertSidStmt->bindValue(1, $data[0]);
185+
$insertSidStmt->bindValue(2, $data[1]);
186+
$insertSidStmt->bindValue(3, $data[2]);
187+
$insertSidStmt->executeStatement();
169188
}
170189

171190
$insertOidStmt = $this->connection->prepare('INSERT INTO acl_object_identities (id, class_id, object_identifier, parent_object_identity_id, entries_inheriting) VALUES (?, ?, ?, ?, ?)');
172191
foreach ($this->getOidData() as $data) {
173-
$insertOidStmt->executeStatement($data);
192+
$insertOidStmt->bindValue(1, $data[0]);
193+
$insertOidStmt->bindValue(2, $data[1]);
194+
$insertOidStmt->bindValue(3, $data[2]);
195+
$insertOidStmt->bindValue(4, $data[3]);
196+
$insertOidStmt->bindValue(5, $data[4]);
197+
$insertOidStmt->executeStatement();
174198
}
175199

176200
$insertEntryStmt = $this->connection->prepare('INSERT INTO acl_entries (id, class_id, object_identity_id, field_name, ace_order, security_identity_id, mask, granting, granting_strategy, audit_success, audit_failure) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
177201
foreach ($this->getEntryData() as $data) {
178-
$insertEntryStmt->executeStatement($data);
202+
$insertEntryStmt->bindValue(1, $data[0]);
203+
$insertEntryStmt->bindValue(2, $data[1]);
204+
$insertEntryStmt->bindValue(3, $data[2]);
205+
$insertEntryStmt->bindValue(4, $data[3]);
206+
$insertEntryStmt->bindValue(5, $data[4]);
207+
$insertEntryStmt->bindValue(6, $data[5]);
208+
$insertEntryStmt->bindValue(7, $data[6]);
209+
$insertEntryStmt->bindValue(8, $data[7]);
210+
$insertEntryStmt->bindValue(9, $data[8]);
211+
$insertEntryStmt->bindValue(10, $data[9]);
212+
$insertEntryStmt->bindValue(11, $data[10]);
213+
$insertEntryStmt->executeStatement();
179214
}
180215

181216
$insertOidAncestorStmt = $this->connection->prepare('INSERT INTO acl_object_identity_ancestors (object_identity_id, ancestor_id) VALUES (?, ?)');
182217
foreach ($this->getOidAncestorData() as $data) {
183-
$insertOidAncestorStmt->executeStatement($data);
218+
$insertOidAncestorStmt->bindValue(1, $data[0]);
219+
$insertOidAncestorStmt->bindValue(2, $data[1]);
220+
$insertOidAncestorStmt->executeStatement();
184221
}
185222
}
186223

Tests/Dbal/MutableAclProviderTest.php

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

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

14+
use Doctrine\DBAL\Configuration;
1415
use Doctrine\DBAL\Connection;
1516
use Doctrine\DBAL\DriverManager;
17+
use Doctrine\DBAL\Schema\DefaultSchemaManagerFactory;
1618
use PHPUnit\Framework\TestCase;
1719
use Symfony\Component\Security\Acl\Dbal\AclProvider;
1820
use Symfony\Component\Security\Acl\Dbal\MutableAclProvider;
@@ -518,10 +520,23 @@ protected function callMethod($object, $method, array $args)
518520

519521
protected function setUp(): void
520522
{
521-
$this->connection = DriverManager::getConnection([
522-
'driver' => 'pdo_sqlite',
523-
'memory' => true,
524-
]);
523+
$configuration = new Configuration();
524+
525+
/**
526+
* @psalm-suppress RedundantCondition Since we are compatibles with DBAL 2 and 3, we need to check if the method exists
527+
*/
528+
if (method_exists($configuration, 'setSchemaManagerFactory')) {
529+
$configuration->setSchemaManagerFactory(new DefaultSchemaManagerFactory());
530+
}
531+
532+
$this->connection = DriverManager::getConnection(
533+
[
534+
'driver' => 'pdo_sqlite',
535+
'memory' => true,
536+
],
537+
$configuration
538+
);
539+
$this->connection->setNestTransactionsWithSavepoints(true);
525540

526541
// import the schema
527542
$schema = new Schema($this->getOptions());

Tests/Domain/SecurityIdentityRetrievalStrategyTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ public function getRoles(): array
284284
return [];
285285
}
286286

287-
public function eraseCredentials()
287+
public function eraseCredentials(): void
288288
{
289289
}
290290

Voter/AclVoter.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,39 @@
2222
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
2323
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
2424

25+
if (class_exists(\Symfony\Component\Security\Core\Security::class)) {
26+
/**
27+
* @internal
28+
*/
29+
trait AclVoterTrait
30+
{
31+
public function vote(TokenInterface $token, $subject, array $attributes)
32+
{
33+
return $this->doVote($token, $subject, $attributes);
34+
}
35+
}
36+
} else {
37+
/**
38+
* @internal
39+
*/
40+
trait AclVoterTrait
41+
{
42+
public function vote(TokenInterface $token, mixed $subject, array $attributes): int
43+
{
44+
return $this->doVote($token, $subject, $attributes);
45+
}
46+
}
47+
}
48+
2549
/**
2650
* This voter can be used as a base class for implementing your own permissions.
2751
*
2852
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
2953
*/
3054
class AclVoter implements VoterInterface
3155
{
56+
use AclVoterTrait;
57+
3258
private $aclProvider;
3359
private $permissionMap;
3460
private $objectIdentityRetrievalStrategy;
@@ -51,7 +77,7 @@ public function supportsAttribute($attribute)
5177
return \is_string($attribute) && $this->permissionMap->contains($attribute);
5278
}
5379

54-
public function vote(TokenInterface $token, $subject, array $attributes)
80+
private function doVote(TokenInterface $token, $subject, array $attributes): int
5581
{
5682
foreach ($attributes as $attribute) {
5783
if (!$this->supportsAttribute($attribute)) {

0 commit comments

Comments
 (0)
0