Skip to content

Run integration tests on multiple db platforms #105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ jobs:
- name: Install PHPUnit
run: vendor/bin/simple-phpunit install

- name: Run tests
run: vendor/bin/simple-phpunit
- name: Run unit tests
run: vendor/bin/simple-phpunit --exclude-group integration
env:
SYMFONY_DEPRECATIONS_HELPER: '${{ matrix.deprecations }}'

Expand Down
85 changes: 85 additions & 0 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: Integration tests

on:
pull_request:
push:
branches: [main]

jobs:
mysql_postgres:
name: 'Test on SQLite, MySQL and PostgreSQL'
runs-on: ubuntu-latest

services:
mysql:
image: mysql:8
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: acl_test
ports:
- '3306:3306'

postgres:
image: postgres:14
env:
POSTGRES_PASSWORD: postgres
ports:
- '5432:5432'
options: >-
--health-cmd healthcheck.sh
--health-interval 20s
--health-timeout 10s
--health-retries 10

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
coverage: none

- name: Composer install
uses: ramsey/composer-install@v1

- name: Install PHPUnit
run: vendor/bin/simple-phpunit install

- name: Run tests
run: vendor/bin/simple-phpunit --group mysql,pgsql,sqlite

oracle:
name: 'Test on Oracle'
runs-on: ubuntu-latest

services:
oracle:
image: gvenzl/oracle-xe:21-slim
env:
ORACLE_RANDOM_PASSWORD: true
APP_USER: oracle
APP_USER_PASSWORD: oracle
ports:
- '1521:1521'

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
coverage: none
extensions: oci8

- name: Composer install
uses: ramsey/composer-install@v1

- name: Install PHPUnit
run: vendor/bin/simple-phpunit install

- name: Run tests
run: vendor/bin/simple-phpunit --group oracle
11 changes: 10 additions & 1 deletion Dbal/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\Security\Acl\Dbal;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Platforms\SQLServerPlatform;
use Doctrine\DBAL\Schema\Schema as BaseSchema;
use Doctrine\DBAL\Schema\SchemaConfig;

Expand All @@ -23,6 +24,7 @@
final class Schema extends BaseSchema
{
protected $options;
protected $platform;

/**
* @param array $options the names for tables
Expand All @@ -34,6 +36,7 @@ public function __construct(array $options, Connection $connection = null)
parent::__construct([], [], $schemaConfig);

$this->options = $options;
$this->platform = $connection ? $connection->getDatabasePlatform() : null;

$this->addClassTable();
$this->addSecurityIdentitiesTable();
Expand Down Expand Up @@ -128,9 +131,15 @@ protected function addObjectIdentityAncestorsTable()

$table->setPrimaryKey(['object_identity_id', 'ancestor_id']);

$cascade = 'CASCADE';
// MS SQL Server does not support recursive cascading
if ($this->platform instanceof SQLServerPlatform) {
$cascade = 'NO ACTION';
}

$oidTable = $this->getTable($this->options['oid_table_name']);
$table->addForeignKeyConstraint($oidTable, ['object_identity_id'], ['id'], ['onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']);
$table->addForeignKeyConstraint($oidTable, ['ancestor_id'], ['id'], ['onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']);
$table->addForeignKeyConstraint($oidTable, ['ancestor_id'], ['id'], ['onDelete' => $cascade, 'onUpdate' => $cascade]);
}

/**
Expand Down
40 changes: 24 additions & 16 deletions Tests/Dbal/AclProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

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

use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Schema\Identifier;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Security\Acl\Dbal\AclProvider;
use Symfony\Component\Security\Acl\Dbal\Schema;
Expand All @@ -23,12 +24,12 @@
use Symfony\Component\Security\Acl\Exception\AclNotFoundException;
use Symfony\Component\Security\Acl\Exception\NotAllAclsFoundException;

/**
* @requires extension pdo_sqlite
*/
class AclProviderTest extends TestCase
abstract class AclProviderTest extends TestCase
{
private $connection;
protected $connection;

/** @return Connection */
abstract protected function createConnection();

/**
* @expectedMessage There is no ACL for the given object identity.
Expand Down Expand Up @@ -146,15 +147,21 @@ public function testFindAcl()

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

// import the schema
$schema = new Schema($this->getOptions());
foreach ($schema->toSql($this->connection->getDatabasePlatform()) as $sql) {
$this->connection->executeStatement($sql);
$schema = new Schema($options = $this->getOptions());
$platform = $this->connection->getDatabasePlatform();
foreach ($schema->toSql($platform) as $sql) {
try {
$this->connection->executeStatement($sql);
} catch (\Exception $e) {
}
}

// purge database
foreach ($options as $tableName) {
$this->connection->executeStatement('DELETE FROM '.(new Identifier($tableName))->getQuotedName($platform));
}

// populate the schema with some test data
Expand Down Expand Up @@ -261,12 +268,13 @@ protected function getClassData()

protected function getOptions()
{
// ! this list is ordered for usage in the purge process, order must be preserved
return [
'oid_table_name' => 'acl_object_identities',
'entry_table_name' => 'acl_entries',
'oid_ancestors_table_name' => 'acl_object_identity_ancestors',
'class_table_name' => 'acl_classes',
'oid_table_name' => 'acl_object_identities',
'sid_table_name' => 'acl_security_identities',
'entry_table_name' => 'acl_entries',
'class_table_name' => 'acl_classes',
];
}

Expand Down
37 changes: 37 additions & 0 deletions Tests/Dbal/MySQL_AclProviderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

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

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DriverManager;

/**
* @requires extension pdo_mysql
* @group integration
* @group mysql
*/
class MySQL_AclProviderTest extends AclProviderTest
{
/** @return Connection */
protected function createConnection()
{
$connection = DriverManager::getConnection([
'driver' => 'pdo_mysql',
'host' => '127.0.0.1',
'user' => 'root',
'password' => 'root',
'dbname' => 'acl_test',
]);

return $connection;
}
}
43 changes: 43 additions & 0 deletions Tests/Dbal/Oracle_AclProviderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

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

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DriverManager;

/**
* @requires extension oci8
* @group integration
* @group oracle
*/
class Oracle_AclProviderTest extends AclProviderTest
{
/** @return Connection */
protected function createConnection()
{
$connection = DriverManager::getConnection([
'driver' => 'oci8',
'host' => '127.0.0.1',
'user' => 'oracle',
'password' => 'oracle',
'dbname' => 'XEPDB1',
'service' => true,
]);

return $connection;
}

public function testFindAclsWithDifferentTypes()
{
$this->markTestSkipped('TODO: This test fails using OCI8');
}
}
36 changes: 36 additions & 0 deletions Tests/Dbal/Pgsql_AclProviderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

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

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DriverManager;

/**
* @requires extension pdo_pgsql
* @group integration
* @group pgsql
*/
class Pgsql_AclProviderTest extends AclProviderTest
{
/** @return Connection */
protected function createConnection()
{
$connection = DriverManager::getConnection([
'driver' => 'pdo_pgsql',
'host' => '127.0.0.1',
'user' => 'postgres',
'password' => 'postgres',
]);

return $connection;
}
}
32 changes: 32 additions & 0 deletions Tests/Dbal/SQLite_AclProviderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

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

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DriverManager;

/**
* @requires extension pdo_sqlite
* @group integration
* @group sqlite
*/
class SQLite_AclProviderTest extends AclProviderTest
{
/** @return Connection */
protected function createConnection()
{
return DriverManager::getConnection([
'driver' => 'pdo_sqlite',
'memory' => true,
]);
}
}