Skip to content

Commit 059d904

Browse files
alongoszViniTou
authored andcommitted
[Tests] Fixed SqliteDbPlatformTest after adding configure contract
1 parent 2aaa154 commit 059d904

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

tests/lib/Database/DbPlatform/SqliteDbPlatformTest.php

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,19 @@
88

99
namespace Ibexa\Tests\DoctrineSchema\Database\DbPlatform;
1010

11+
use Doctrine\DBAL\Configuration;
12+
use Doctrine\DBAL\DriverManager;
1113
use Doctrine\DBAL\Exception;
1214
use Doctrine\DBAL\ParameterType;
1315
use Ibexa\DoctrineSchema\Database\DbPlatform\SqliteDbPlatform;
1416
use Ibexa\Tests\DoctrineSchema\Database\TestDatabaseFactory;
1517
use PHPUnit\Framework\TestCase;
1618

17-
class SqliteDbPlatformTest extends TestCase
19+
/**
20+
* @covers \Ibexa\DoctrineSchema\Database\DbPlatform\SqliteDbPlatform
21+
* @covers \Ibexa\Tests\DoctrineSchema\Database\TestDatabaseFactory
22+
*/
23+
final class SqliteDbPlatformTest extends TestCase
1824
{
1925
private TestDatabaseFactory $testDatabaseFactory;
2026

@@ -30,7 +36,7 @@ public function setUp(): void
3036
* @throws \Doctrine\DBAL\Exception
3137
* @throws \Ibexa\Tests\DoctrineSchema\Database\TestDatabaseConfigurationException
3238
*/
33-
public function testForeignKeys(): void
39+
public function testDatabaseFactoryEnablesForeignKeys(): void
3440
{
3541
$connection = $this->testDatabaseFactory->prepareAndConnect($this->sqliteDbPlatform);
3642
$schema = $connection->createSchemaManager()->introspectSchema();
@@ -52,9 +58,32 @@ public function testForeignKeys(): void
5258
$connection->insert($primaryTable->getName(), ['id' => 1], [ParameterType::INTEGER]);
5359
$connection->insert($secondaryTable->getName(), ['id' => 1], [ParameterType::INTEGER]);
5460

55-
// insert broken record
61+
// insert a broken record
5662
$this->expectException(Exception::class);
5763
$this->expectExceptionMessage('FOREIGN KEY constraint failed');
5864
$connection->insert($secondaryTable->getName(), ['id' => 2], [ParameterType::INTEGER]);
5965
}
66+
67+
/**
68+
* For external usage (e.g.: by ibexa/core, a configure method needs to be called to enable foreign keys).
69+
*
70+
* @throws \Doctrine\DBAL\Exception
71+
*/
72+
public function testConfigureEnablesForeignKeys(): void
73+
{
74+
$configuration = new Configuration();
75+
$this->sqliteDbPlatform->configure($configuration);
76+
77+
$connection = DriverManager::getConnection(
78+
[
79+
'url' => 'sqlite:///:memory:',
80+
'platform' => $this->sqliteDbPlatform,
81+
],
82+
$configuration
83+
);
84+
self::assertTrue(
85+
(bool)$connection->executeQuery('PRAGMA foreign_keys')->fetchOne(),
86+
'Foreign keys are not enabled'
87+
);
88+
}
6089
}

0 commit comments

Comments
 (0)