Skip to content

Commit 552c2e4

Browse files
committed
Fixing connection and tests for Oracle
1 parent 196d5ec commit 552c2e4

File tree

3 files changed

+12
-23
lines changed

3 files changed

+12
-23
lines changed

tests/ConnectionFactory.php

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,33 +25,19 @@ public static function resetDatabase(
2525
): Connection {
2626
$config = new \Doctrine\DBAL\Configuration();
2727

28-
$dbDriver = $dbDriver;
29-
3028
if ($dbDriver === 'pdo_sqlite') {
3129
$dbConnection = self::getConnection();
3230
$dbConnection->exec('PRAGMA foreign_keys = ON;');
3331
} elseif ($dbDriver === 'oci8') {
34-
$connectionParams = array(
35-
'servicename' => 'XE',
36-
'user' => $dbAdminUserName,
37-
// Because of issues in DBAL, admin and normal user password have to be the same.
38-
'password' => $dbPassword,
39-
'host' => $dbHost,
40-
'port' => $dbPort,
41-
'driver' => $dbDriver,
42-
'dbname' => $dbAdminUserName,
43-
'charset' => 'AL32UTF8',
44-
);
45-
46-
$adminConn = DriverManager::getConnection($connectionParams, $config);
32+
$adminConn = self::createConnection($dbDriver, $dbHost, $dbPort, $dbAdminUserName, $dbPassword, $dbAdminUserName);
4733

4834
// When dropAndCreateDatabase is run several times, Oracle can have some issues releasing the TDBM user.
4935
// Let's forcefully delete the connection!
5036
$adminConn->exec("select 'alter system kill session ''' || sid || ',' || serial# || ''';' from v\$session where username = '".strtoupper($dbName)."'");
5137

5238
$adminConn->getSchemaManager()->dropAndCreateDatabase($dbName);
5339

54-
$dbConnection = $adminConn;
40+
$dbConnection = self::createConnection($dbDriver, $dbHost, $dbPort, $dbName, $dbPassword, $dbName);
5541
} else {
5642
$connectionParams = array(
5743
'user' => $dbUserName,

tests/TDBMAbstractServiceTest.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
use TheCodingMachine\TDBM\Utils\DefaultNamingStrategy;
4545
use TheCodingMachine\TDBM\Utils\PathFinder\PathFinder;
4646
use function stripos;
47+
use const PHP_EOL;
4748

4849
abstract class TDBMAbstractServiceTest extends TestCase
4950
{
@@ -380,12 +381,14 @@ private static function initSchema(Connection $connection): void
380381

381382
$db->junctionTable('person', 'boats');
382383

383-
$db->table('base_objects')
384-
->column('id')->integer()->primaryKey()->autoIncrement()
385-
->column('label')->string();
386-
$db->table('inherited_objects')
387-
->column('id')->integer()->primaryKey()->autoIncrement()
388-
->column('base_object_id')->references('base_objects')->unique()->comment('@JsonCollection');
384+
if (!$connection->getDatabasePlatform() instanceof OraclePlatform) {
385+
$db->table('base_objects')
386+
->column('id')->integer()->primaryKey()->autoIncrement()
387+
->column('label')->string();
388+
$db->table('inherited_objects')
389+
->column('id')->integer()->primaryKey()->autoIncrement()
390+
->column('base_object_id')->references('base_objects')->unique()->comment('@JsonCollection');
391+
}
389392

390393
$targetTable = $db->table('composite_fk_target')
391394
->column('id_1')->integer()
@@ -395,7 +398,7 @@ private static function initSchema(Connection $connection): void
395398
->column('id')->integer()->primaryKey()->autoIncrement()
396399
->column('fk_1')->integer()
397400
->column('fk_2')->integer()
398-
->then()->getDbalTable()->addForeignKeyConstraint($targetTable->getDbalTable(), ['fk_1', 'fk_2'], ['id_1', 'id_2']);
401+
->then()->getDbalTable()->addForeignKeyConstraint($targetTable->getDbalTable(), [$connection->quoteIdentifier('fk_1'), $connection->quoteIdentifier('fk_2')], [$connection->quoteIdentifier('id_1'), $connection->quoteIdentifier('id_2')]);
399402

400403
// Test case, the problem here is:
401404
// - `inheritance_agency` have an FK to `inheritance_society.**id_entity**`

tests/oracle/Dockerfile

Whitespace-only changes.

0 commit comments

Comments
 (0)