Commit d729f7bb authored by Benjamin Morel's avatar Benjamin Morel

Reuse existing tests for SQLite FK constraints

parent a2b48485
...@@ -6,7 +6,6 @@ namespace Doctrine\Tests\DBAL\Functional\Driver\PDOSqlite; ...@@ -6,7 +6,6 @@ namespace Doctrine\Tests\DBAL\Functional\Driver\PDOSqlite;
use Doctrine\DBAL\Driver as DriverInterface; use Doctrine\DBAL\Driver as DriverInterface;
use Doctrine\DBAL\Driver\PDOSqlite\Driver; use Doctrine\DBAL\Driver\PDOSqlite\Driver;
use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException;
use Doctrine\Tests\DBAL\Functional\Driver\AbstractDriverTest; use Doctrine\Tests\DBAL\Functional\Driver\AbstractDriverTest;
use function extension_loaded; use function extension_loaded;
...@@ -47,31 +46,4 @@ class DriverTest extends AbstractDriverTest ...@@ -47,31 +46,4 @@ class DriverTest extends AbstractDriverTest
{ {
return ''; return '';
} }
public function testForeignKeyConstraintViolationException() : void
{
$this->connection->exec('PRAGMA foreign_keys = ON');
$this->connection->exec('
CREATE TABLE parent (
id INTEGER PRIMARY KEY
)
');
$this->connection->exec('
CREATE TABLE child (
id INTEGER PRIMARY KEY,
parent_id INTEGER,
FOREIGN KEY (parent_id) REFERENCES parent(id)
);
');
$this->connection->exec('INSERT INTO parent (id) VALUES (1)');
$this->connection->exec('INSERT INTO child (id, parent_id) VALUES (1, 1)');
$this->connection->exec('INSERT INTO child (id, parent_id) VALUES (2, 1)');
$this->expectException(ForeignKeyConstraintViolationException::class);
$this->connection->exec('INSERT INTO child (id, parent_id) VALUES (3, 2)');
}
} }
...@@ -78,7 +78,11 @@ class ExceptionTest extends DbalFunctionalTestCase ...@@ -78,7 +78,11 @@ class ExceptionTest extends DbalFunctionalTestCase
public function testForeignKeyConstraintViolationExceptionOnInsert() : void public function testForeignKeyConstraintViolationExceptionOnInsert() : void
{ {
if (! $this->connection->getDatabasePlatform()->supportsForeignKeyConstraints()) { $platform = $this->connection->getDatabasePlatform();
if ($platform instanceof SqlitePlatform) {
$this->connection->exec('PRAGMA foreign_keys = ON');
} elseif (! $platform->supportsForeignKeyConstraints()) {
$this->markTestSkipped('Only fails on platforms with foreign key constraints.'); $this->markTestSkipped('Only fails on platforms with foreign key constraints.');
} }
...@@ -112,7 +116,11 @@ class ExceptionTest extends DbalFunctionalTestCase ...@@ -112,7 +116,11 @@ class ExceptionTest extends DbalFunctionalTestCase
public function testForeignKeyConstraintViolationExceptionOnUpdate() : void public function testForeignKeyConstraintViolationExceptionOnUpdate() : void
{ {
if (! $this->connection->getDatabasePlatform()->supportsForeignKeyConstraints()) { $platform = $this->connection->getDatabasePlatform();
if ($platform instanceof SqlitePlatform) {
$this->connection->exec('PRAGMA foreign_keys = ON');
} elseif (! $platform->supportsForeignKeyConstraints()) {
$this->markTestSkipped('Only fails on platforms with foreign key constraints.'); $this->markTestSkipped('Only fails on platforms with foreign key constraints.');
} }
...@@ -146,7 +154,11 @@ class ExceptionTest extends DbalFunctionalTestCase ...@@ -146,7 +154,11 @@ class ExceptionTest extends DbalFunctionalTestCase
public function testForeignKeyConstraintViolationExceptionOnDelete() : void public function testForeignKeyConstraintViolationExceptionOnDelete() : void
{ {
if (! $this->connection->getDatabasePlatform()->supportsForeignKeyConstraints()) { $platform = $this->connection->getDatabasePlatform();
if ($platform instanceof SqlitePlatform) {
$this->connection->exec('PRAGMA foreign_keys = ON');
} elseif (! $platform->supportsForeignKeyConstraints()) {
$this->markTestSkipped('Only fails on platforms with foreign key constraints.'); $this->markTestSkipped('Only fails on platforms with foreign key constraints.');
} }
...@@ -182,7 +194,9 @@ class ExceptionTest extends DbalFunctionalTestCase ...@@ -182,7 +194,9 @@ class ExceptionTest extends DbalFunctionalTestCase
{ {
$platform = $this->connection->getDatabasePlatform(); $platform = $this->connection->getDatabasePlatform();
if (! $platform->supportsForeignKeyConstraints()) { if ($platform instanceof SqlitePlatform) {
$this->connection->exec('PRAGMA foreign_keys = ON');
} elseif (! $platform->supportsForeignKeyConstraints()) {
$this->markTestSkipped('Only fails on platforms with foreign key constraints.'); $this->markTestSkipped('Only fails on platforms with foreign key constraints.');
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment