diff --git a/Tests/Dbal/AclProviderTest.php b/Tests/Dbal/AclProviderTest.php index 87ff1bd..63ca85c 100644 --- a/Tests/Dbal/AclProviderTest.php +++ b/Tests/Dbal/AclProviderTest.php @@ -11,7 +11,9 @@ namespace Symfony\Component\Security\Acl\Tests\Dbal; +use Doctrine\DBAL\Configuration; use Doctrine\DBAL\DriverManager; +use Doctrine\DBAL\Schema\DefaultSchemaManagerFactory; use PHPUnit\Framework\TestCase; use Symfony\Component\Security\Acl\Dbal\AclProvider; use Symfony\Component\Security\Acl\Dbal\Schema; @@ -146,10 +148,18 @@ public function testFindAcl() protected function setUp(): void { - $this->connection = DriverManager::getConnection([ + $configuration = new Configuration(); + if (\method_exists($configuration, 'setSchemaManagerFactory')) { + $configuration->setSchemaManagerFactory(new DefaultSchemaManagerFactory()); + } + + $this->connection = DriverManager::getConnection( + [ 'driver' => 'pdo_sqlite', 'memory' => true, - ]); + ], + $configuration + ); // import the schema $schema = new Schema($this->getOptions()); @@ -157,30 +167,84 @@ protected function setUp(): void $this->connection->executeStatement($sql); } - // populate the schema with some test data - $insertClassStmt = $this->connection->prepare('INSERT INTO acl_classes (id, class_type) VALUES (?, ?)'); + $qb = $this->connection->createQueryBuilder(); + foreach ($this->getClassData() as $data) { - $insertClassStmt->executeStatement($data); + $qb + ->insert('acl_classes') + ->values( + [ + 'id' => '?', + 'class_type' => '?', + ] + ) + ->setParameters($data) + ->executeQuery(); } - $insertSidStmt = $this->connection->prepare('INSERT INTO acl_security_identities (id, identifier, username) VALUES (?, ?, ?)'); foreach ($this->getSidData() as $data) { - $insertSidStmt->executeStatement($data); + $qb + ->insert('acl_security_identities') + ->values( + [ + 'id' => '?', + 'identifier' => '?', + 'username' => '?', + ] + ) + ->setParameters($data) + ->executeQuery(); } - $insertOidStmt = $this->connection->prepare('INSERT INTO acl_object_identities (id, class_id, object_identifier, parent_object_identity_id, entries_inheriting) VALUES (?, ?, ?, ?, ?)'); foreach ($this->getOidData() as $data) { - $insertOidStmt->executeStatement($data); + $qb + ->insert('acl_object_identities') + ->values( + [ + 'id' => '?', + 'class_id' => '?', + 'object_identifier' => '?', + 'parent_object_identity_id' => '?', + 'entries_inheriting' => '?', + ] + ) + ->setParameters($data) + ->executeQuery(); } - $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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'); foreach ($this->getEntryData() as $data) { - $insertEntryStmt->executeStatement($data); + $qb + ->insert('acl_entries') + ->values( + [ + 'id' => '?', + 'class_id' => '?', + 'object_identity_id' => '?', + 'field_name' => '?', + 'ace_order' => '?', + 'security_identity_id' => '?', + 'mask' => '?', + 'granting' => '?', + 'granting_strategy' => '?', + 'audit_success' => '?', + 'audit_failure' => '?', + ] + ) + ->setParameters($data) + ->executeQuery(); } - $insertOidAncestorStmt = $this->connection->prepare('INSERT INTO acl_object_identity_ancestors (object_identity_id, ancestor_id) VALUES (?, ?)'); foreach ($this->getOidAncestorData() as $data) { - $insertOidAncestorStmt->executeStatement($data); + $qb + ->insert('acl_object_identity_ancestors') + ->values( + [ + 'object_identity_id' => '?', + 'ancestor_id' => '?', + ] + ) + ->setParameters($data) + ->executeQuery(); } } diff --git a/Tests/Dbal/MutableAclProviderTest.php b/Tests/Dbal/MutableAclProviderTest.php index 2c34c15..47c8a2b 100644 --- a/Tests/Dbal/MutableAclProviderTest.php +++ b/Tests/Dbal/MutableAclProviderTest.php @@ -11,8 +11,10 @@ namespace Symfony\Component\Security\Acl\Tests\Dbal; +use Doctrine\DBAL\Configuration; use Doctrine\DBAL\Connection; use Doctrine\DBAL\DriverManager; +use Doctrine\DBAL\Schema\DefaultSchemaManagerFactory; use PHPUnit\Framework\TestCase; use Symfony\Component\Security\Acl\Dbal\AclProvider; use Symfony\Component\Security\Acl\Dbal\MutableAclProvider; @@ -23,6 +25,7 @@ use Symfony\Component\Security\Acl\Domain\PermissionGrantingStrategy; use Symfony\Component\Security\Acl\Domain\RoleSecurityIdentity; use Symfony\Component\Security\Acl\Domain\UserSecurityIdentity; +use Symfony\Component\Security\Acl\Exception\AclAlreadyExistsException; use Symfony\Component\Security\Acl\Exception\AclNotFoundException; use Symfony\Component\Security\Acl\Exception\ConcurrentModificationException; use Symfony\Component\Security\Acl\Model\AuditableEntryInterface; @@ -59,7 +62,7 @@ public static function assertAceEquals(EntryInterface $a, EntryInterface $b) public function testCreateAclThrowsExceptionWhenAclAlreadyExists() { - $this->expectException(\Symfony\Component\Security\Acl\Exception\AclAlreadyExistsException::class); + $this->expectException(AclAlreadyExistsException::class); $provider = $this->getProvider(); $oid = new ObjectIdentity('123456', 'FOO'); @@ -518,10 +521,19 @@ protected function callMethod($object, $method, array $args) protected function setUp(): void { - $this->connection = DriverManager::getConnection([ - 'driver' => 'pdo_sqlite', - 'memory' => true, - ]); + $configuration = new Configuration(); + if (\method_exists($configuration, 'setSchemaManagerFactory')) { + $configuration->setSchemaManagerFactory(new DefaultSchemaManagerFactory()); + } + + $this->connection = DriverManager::getConnection( + [ + 'driver' => 'pdo_sqlite', + 'memory' => true, + ], + $configuration + ); + $this->connection->setNestTransactionsWithSavepoints(true); // import the schema $schema = new Schema($this->getOptions()); diff --git a/Tests/Domain/SecurityIdentityRetrievalStrategyTest.php b/Tests/Domain/SecurityIdentityRetrievalStrategyTest.php index deebb44..edc56f1 100644 --- a/Tests/Domain/SecurityIdentityRetrievalStrategyTest.php +++ b/Tests/Domain/SecurityIdentityRetrievalStrategyTest.php @@ -284,7 +284,7 @@ public function getRoles(): array return []; } - public function eraseCredentials() + public function eraseCredentials(): void { } diff --git a/Voter/AclVoter.php b/Voter/AclVoter.php index 14c5d56..af86b38 100644 --- a/Voter/AclVoter.php +++ b/Voter/AclVoter.php @@ -22,6 +22,30 @@ use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface; +if (class_exists(\Symfony\Component\Security\Core\Security::class)) { + /** + * @internal + */ + trait AclVoterTrait + { + public function vote(TokenInterface $token, $subject, array $attributes) + { + return $this->doVote($token, $subject, $attributes); + } + } +} else { + /** + * @internal + */ + trait AclVoterTrait + { + public function vote(TokenInterface $token, mixed $subject, array $attributes): int + { + return $this->doVote($token, $subject, $attributes); + } + } +} + /** * This voter can be used as a base class for implementing your own permissions. * @@ -29,6 +53,8 @@ */ class AclVoter implements VoterInterface { + use AclVoterTrait; + private $aclProvider; private $permissionMap; private $objectIdentityRetrievalStrategy; @@ -51,7 +77,7 @@ public function supportsAttribute($attribute) return \is_string($attribute) && $this->permissionMap->contains($attribute); } - public function vote(TokenInterface $token, $subject, array $attributes) + private function doVote(TokenInterface $token, $subject, array $attributes) { foreach ($attributes as $attribute) { if (!$this->supportsAttribute($attribute)) { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 14d4060..01d8c68 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,37 +1,36 @@ - - - - - - - - - ./Tests/ - - - - - - ./ - - ./Resources - ./Tests - ./vendor - - - - - - benchmark - - - - - + + + ./ + + + ./Resources + ./Tests + ./vendor + + + + + + + + ./Tests/ + + + + + benchmark + + + + +