Skip to content

Commit

Permalink
Functional test for ForeignKeyConstraintViolationException
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMorel committed Dec 30, 2019
1 parent 716f3b3 commit a2b4848
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

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;

Expand Down Expand Up @@ -46,4 +47,31 @@ protected static function getDatabaseNameForConnectionWithoutDatabaseNameParamet
{
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)');
}
}

0 comments on commit a2b4848

Please sign in to comment.