Commit a2b48485 authored by Benjamin Morel's avatar Benjamin Morel

Functional test for ForeignKeyConstraintViolationException

parent 716f3b30
......@@ -6,6 +6,7 @@ namespace Doctrine\Tests\DBAL\Functional\Driver\PDOSqlite;
use Doctrine\DBAL\Driver as DriverInterface;
use Doctrine\DBAL\Driver\PDOSqlite\Driver;
use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException;
use Doctrine\Tests\DBAL\Functional\Driver\AbstractDriverTest;
use function extension_loaded;
......@@ -46,4 +47,31 @@ class DriverTest extends AbstractDriverTest
{
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)');
}
}
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