Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jordisala1991 committed Sep 6, 2024
1 parent 8647e14 commit 1247ccb
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 13 deletions.
52 changes: 43 additions & 9 deletions Tests/Dbal/AclProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -146,10 +148,19 @@ public function testFindAcl()

protected function setUp(): void
{
$this->connection = DriverManager::getConnection([
'driver' => 'pdo_sqlite',
'memory' => true,
]);
$configuration = new Configuration();

if (\method_exists($configuration, 'setSchemaManagerFactory')) {

Check failure on line 153 in Tests/Dbal/AclProviderTest.php

View workflow job for this annotation

GitHub Actions / Psalm

RedundantCondition

Tests/Dbal/AclProviderTest.php:153:13: RedundantCondition: Type Doctrine\DBAL\Configuration for $configuration is always method-exists-setSchemaManagerFactory (see https://psalm.dev/122)
$configuration->setSchemaManagerFactory(new DefaultSchemaManagerFactory());
}

$this->connection = DriverManager::getConnection(
[
'driver' => 'pdo_sqlite',
'memory' => true,
],
$configuration
);

// import the schema
$schema = new Schema($this->getOptions());
Expand All @@ -160,27 +171,50 @@ protected function setUp(): void
// populate the schema with some test data
$insertClassStmt = $this->connection->prepare('INSERT INTO acl_classes (id, class_type) VALUES (?, ?)');
foreach ($this->getClassData() as $data) {
$insertClassStmt->executeStatement($data);
$insertClassStmt->bindValue(1, $data[0]);
$insertClassStmt->bindValue(2, $data[1]);
$insertClassStmt->executeStatement();
}

$insertSidStmt = $this->connection->prepare('INSERT INTO acl_security_identities (id, identifier, username) VALUES (?, ?, ?)');
foreach ($this->getSidData() as $data) {
$insertSidStmt->executeStatement($data);
$insertSidStmt->bindValue(1, $data[0]);
$insertSidStmt->bindValue(2, $data[1]);
$insertSidStmt->bindValue(3, $data[2]);
$insertSidStmt->executeStatement();
}

$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);
$insertOidStmt->bindValue(1, $data[0]);
$insertOidStmt->bindValue(2, $data[1]);
$insertOidStmt->bindValue(3, $data[2]);
$insertOidStmt->bindValue(4, $data[3]);
$insertOidStmt->bindValue(5, $data[4]);
$insertOidStmt->executeStatement();
}

$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);
$insertEntryStmt->bindValue(1, $data[0]);
$insertEntryStmt->bindValue(2, $data[1]);
$insertEntryStmt->bindValue(3, $data[2]);
$insertEntryStmt->bindValue(4, $data[3]);
$insertEntryStmt->bindValue(5, $data[4]);
$insertEntryStmt->bindValue(6, $data[5]);
$insertEntryStmt->bindValue(7, $data[6]);
$insertEntryStmt->bindValue(8, $data[7]);
$insertEntryStmt->bindValue(9, $data[8]);
$insertEntryStmt->bindValue(10, $data[9]);
$insertEntryStmt->bindValue(11, $data[10]);
$insertEntryStmt->executeStatement();
}

$insertOidAncestorStmt = $this->connection->prepare('INSERT INTO acl_object_identity_ancestors (object_identity_id, ancestor_id) VALUES (?, ?)');
foreach ($this->getOidAncestorData() as $data) {
$insertOidAncestorStmt->executeStatement($data);
$insertOidAncestorStmt->bindValue(1, $data[0]);
$insertOidAncestorStmt->bindValue(2, $data[1]);
$insertOidAncestorStmt->executeStatement();
}
}

Expand Down
20 changes: 16 additions & 4 deletions Tests/Dbal/MutableAclProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -518,10 +520,20 @@ 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')) {

Check failure on line 525 in Tests/Dbal/MutableAclProviderTest.php

View workflow job for this annotation

GitHub Actions / Psalm

RedundantCondition

Tests/Dbal/MutableAclProviderTest.php:525:13: RedundantCondition: Type Doctrine\DBAL\Configuration for $configuration is always method-exists-setSchemaManagerFactory (see https://psalm.dev/122)
$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());
Expand Down

0 comments on commit 1247ccb

Please sign in to comment.