Skip to content

Commit d55c07f

Browse files
committed
Run functional tests on multiple platforms
1 parent faf9ede commit d55c07f

File tree

8 files changed

+338
-16
lines changed

8 files changed

+338
-16
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ jobs:
4343
- name: Install PHPUnit
4444
run: vendor/bin/simple-phpunit install
4545

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

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
name: Integration tests
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [main]
7+
8+
jobs:
9+
mysql_postgres:
10+
name: 'Test on SQLite, MySQL and PostgreSQL'
11+
runs-on: ubuntu-latest
12+
13+
services:
14+
mysql:
15+
image: mysql:8
16+
env:
17+
MYSQL_ROOT_PASSWORD: root
18+
MYSQL_DATABASE: acl_test
19+
ports:
20+
- '3306:3306'
21+
22+
postgres:
23+
image: postgres:14
24+
env:
25+
POSTGRES_PASSWORD: postgres
26+
ports:
27+
- '5432:5432'
28+
options: >-
29+
--health-cmd healthcheck.sh
30+
--health-interval 20s
31+
--health-timeout 10s
32+
--health-retries 10
33+
34+
steps:
35+
- name: Checkout code
36+
uses: actions/checkout@v2
37+
38+
- name: Setup PHP
39+
uses: shivammathur/setup-php@v2
40+
with:
41+
php-version: '8.0'
42+
coverage: none
43+
44+
- name: Composer install
45+
uses: ramsey/composer-install@v1
46+
47+
- name: Install PHPUnit
48+
run: vendor/bin/simple-phpunit install
49+
50+
- name: Run tests
51+
run: vendor/bin/simple-phpunit --group mysql,pgsql,sqlite
52+
53+
mssql:
54+
name: 'Test on MSSQL'
55+
runs-on: ubuntu-latest
56+
57+
services:
58+
mssql:
59+
image: mcr.microsoft.com/mssql/server:2019-latest
60+
env:
61+
ACCEPT_EULA: Y
62+
SA_PASSWORD: Symfony123
63+
ports:
64+
- '1433:1433'
65+
66+
steps:
67+
- name: Checkout code
68+
uses: actions/checkout@v2
69+
70+
- name: Setup PHP
71+
uses: shivammathur/setup-php@v2
72+
with:
73+
php-version: '8.0'
74+
coverage: none
75+
extensions: pdo_sqlsrv
76+
77+
- name: Composer install
78+
uses: ramsey/composer-install@v1
79+
80+
- name: Install PHPUnit
81+
run: vendor/bin/simple-phpunit install
82+
83+
- name: Create MSSQL database
84+
run: 'docker exec ${{ job.services.mssql.id }} /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P Symfony123 -Q "CREATE DATABASE acl_test"'
85+
86+
- name: Run tests
87+
run: vendor/bin/simple-phpunit --group mssql
88+
89+
oracle:
90+
name: 'Test on Oracle'
91+
runs-on: ubuntu-latest
92+
93+
services:
94+
oracle:
95+
image: gvenzl/oracle-xe:21-slim
96+
env:
97+
ORACLE_RANDOM_PASSWORD: true
98+
APP_USER: oracle
99+
APP_USER_PASSWORD: oracle
100+
ports:
101+
- '1521:1521'
102+
103+
steps:
104+
- name: Checkout code
105+
uses: actions/checkout@v2
106+
107+
- name: Setup PHP
108+
uses: shivammathur/setup-php@v2
109+
with:
110+
php-version: '8.0'
111+
coverage: none
112+
extensions: oci8
113+
114+
- name: Composer install
115+
uses: ramsey/composer-install@v1
116+
117+
- name: Install PHPUnit
118+
run: vendor/bin/simple-phpunit install
119+
120+
- name: Run tests
121+
run: vendor/bin/simple-phpunit --group oracle

Tests/Dbal/AclProviderTest.php

Lines changed: 30 additions & 14 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\DriverManager;
14+
use Doctrine\DBAL\Connection;
15+
use Doctrine\DBAL\Exception\TableNotFoundException;
16+
use Doctrine\DBAL\Platforms\SQLServerPlatform;
1517
use PHPUnit\Framework\TestCase;
1618
use Symfony\Component\Security\Acl\Dbal\AclProvider;
1719
use Symfony\Component\Security\Acl\Dbal\Schema;
@@ -23,13 +25,13 @@
2325
use Symfony\Component\Security\Acl\Exception\AclNotFoundException;
2426
use Symfony\Component\Security\Acl\Exception\NotAllAclsFoundException;
2527

26-
/**
27-
* @requires extension pdo_sqlite
28-
*/
29-
class AclProviderTest extends TestCase
28+
abstract class AclProviderTest extends TestCase
3029
{
3130
private $connection;
3231

32+
/** @return Connection */
33+
abstract protected function createConnection();
34+
3335
/**
3436
* @expectedMessage There is no ACL for the given object identity.
3537
*/
@@ -146,16 +148,29 @@ public function testFindAcl()
146148

147149
protected function setUp(): void
148150
{
149-
$this->connection = DriverManager::getConnection([
150-
'driver' => 'pdo_sqlite',
151-
'memory' => true,
152-
]);
151+
$this->connection = $this->createConnection();
153152

154153
// import the schema
155-
$schema = new Schema($this->getOptions());
156-
foreach ($schema->toSql($this->connection->getDatabasePlatform()) as $sql) {
154+
$schema = new Schema($options = $this->getOptions());
155+
$platform = $this->connection->getDatabasePlatform();
156+
foreach ($schema->toSql($platform) as $sql) {
157+
try {
158+
$this->connection->executeStatement($sql);
159+
} catch (\Exception $e) {
160+
}
161+
}
162+
163+
// purge database
164+
if ($platform instanceof SQLServerPlatform) {
165+
$this->connection->executeStatement('ALTER TABLE '.$options['oid_table_name'].' NOCHECK CONSTRAINT ALL');
166+
}
167+
foreach ($options as $tableName) {
168+
$sql = $platform->getTruncateTableSQL($tableName, true);
157169
$this->connection->executeStatement($sql);
158170
}
171+
if ($platform instanceof SQLServerPlatform) {
172+
$this->connection->executeStatement('ALTER TABLE '.$options['oid_table_name'].' WITH CHECK CHECK CONSTRAINT ALL');
173+
}
159174

160175
// populate the schema with some test data
161176
$insertClassStmt = $this->connection->prepare('INSERT INTO acl_classes (id, class_type) VALUES (?, ?)');
@@ -261,12 +276,13 @@ protected function getClassData()
261276

262277
protected function getOptions()
263278
{
279+
// ! this list is ordered for usage in the purge process, order must be preserved
264280
return [
265-
'oid_table_name' => 'acl_object_identities',
281+
'entry_table_name' => 'acl_entries',
266282
'oid_ancestors_table_name' => 'acl_object_identity_ancestors',
267-
'class_table_name' => 'acl_classes',
283+
'oid_table_name' => 'acl_object_identities',
268284
'sid_table_name' => 'acl_security_identities',
269-
'entry_table_name' => 'acl_entries',
285+
'class_table_name' => 'acl_classes',
270286
];
271287
}
272288

Tests/Dbal/MSSQL_AclProviderTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Security\Acl\Tests\Dbal;
13+
14+
use Doctrine\DBAL\Connection;
15+
use Doctrine\DBAL\DriverManager;
16+
17+
/**
18+
* @requires extension pdo_sqlsrv
19+
* @group integration
20+
* @group mssql
21+
*/
22+
class MSSQL_AclProviderTest extends AclProviderTest
23+
{
24+
/** @return Connection */
25+
protected function createConnection()
26+
{
27+
$connection = DriverManager::getConnection([
28+
'driver' => 'pdo_sqlsrv',
29+
'host' => '127.0.0.1',
30+
'user' => 'sa',
31+
'password' => 'Symfony123',
32+
'dbname' => 'acl_test',
33+
]);
34+
35+
return $connection;
36+
}
37+
}

Tests/Dbal/MySQL_AclProviderTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Security\Acl\Tests\Dbal;
13+
14+
use Doctrine\DBAL\Connection;
15+
use Doctrine\DBAL\DriverManager;
16+
17+
/**
18+
* @requires extension pdo_mysql
19+
* @group integration
20+
* @group mysql
21+
*/
22+
class MySQL_AclProviderTest extends AclProviderTest
23+
{
24+
/** @return Connection */
25+
protected function createConnection()
26+
{
27+
$connection = DriverManager::getConnection([
28+
'driver' => 'pdo_mysql',
29+
'host' => '127.0.0.1',
30+
'user' => 'root',
31+
'password' => 'root',
32+
'dbname' => 'acl_test',
33+
]);
34+
35+
return $connection;
36+
}
37+
}

Tests/Dbal/Oracle_AclProviderTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Security\Acl\Tests\Dbal;
13+
14+
use Doctrine\DBAL\Connection;
15+
use Doctrine\DBAL\DriverManager;
16+
17+
/**
18+
* @requires extension oci8
19+
* @group integration
20+
* @group oracle
21+
*/
22+
class Oracle_AclProviderTest extends AclProviderTest
23+
{
24+
/** @return Connection */
25+
protected function createConnection()
26+
{
27+
$connection = DriverManager::getConnection([
28+
'driver' => 'oci8',
29+
'host' => '127.0.0.1',
30+
'user' => 'oracle',
31+
'password' => 'oracle',
32+
'dbname' => 'XEPDB1',
33+
'service' => true,
34+
]);
35+
36+
return $connection;
37+
}
38+
39+
public function testFindAclsWithDifferentTypes()
40+
{
41+
$this->markTestSkipped('TODO: This test fails using OCI8');
42+
}
43+
}

Tests/Dbal/Pgsql_AclProviderTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Security\Acl\Tests\Dbal;
13+
14+
use Doctrine\DBAL\Connection;
15+
use Doctrine\DBAL\DriverManager;
16+
17+
/**
18+
* @requires extension pdo_pgsql
19+
* @group integration
20+
* @group pgsql
21+
*/
22+
class Pgsql_AclProviderTest extends AclProviderTest
23+
{
24+
/** @return Connection */
25+
protected function createConnection()
26+
{
27+
$connection = DriverManager::getConnection([
28+
'driver' => 'pdo_pgsql',
29+
'host' => '127.0.0.1',
30+
'user' => 'postgres',
31+
'password' => 'postgres',
32+
]);
33+
34+
return $connection;
35+
}
36+
}

0 commit comments

Comments
 (0)