Commit b3364c4f authored by Karamel's avatar Karamel
Browse files

Add foreign keys for sqlite connection and fix some tests.

parent 16d0368b
......@@ -74,6 +74,10 @@ class DoctrineDAO implements DAO
$this->roEm = EntityManager::create($dbParams, $setup);
$this->inTransaction = false;
$this->deletedIds = [];
// Enable foreign keys for sqlite
if ($dbInfo['type'] == 'sqlite') {
$this->em->getConnection()->query('PRAGMA foreign_keys = ON;');
}
}
/** Get a full ID string for delete/read to use with deletedIds.
......
......@@ -193,6 +193,8 @@ class CategoryAPITest extends TestCase
$this->api->delete($parentId);
} catch (\Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException $e) {
$foundException = true;
} catch (\Doctrine\DBAL\Exception\DriverException $e) { // With Sqlite
$foundException = true;
}
// Clean dao for the expected error not to propagate on teardown
$this->dao->getEntityManager()->clear();
......
......@@ -176,8 +176,7 @@ class PaymentModeAPITest extends TestCase
}
/** @depends testValues
* @depends testOtherReturn
* @expectedException \Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException */
* @depends testOtherReturn */
public function testDeleteCascadeReferenced() {
// $pm return references $pm2
// Try to delete $pm2: should fail.
......@@ -196,7 +195,15 @@ class PaymentModeAPITest extends TestCase
$value->setValue(10.0);
$pm->addValue($value);
$this->api->write(array($pm, $pm2));
$this->api->delete($pm2->getId());
$foundException = false;
try {
$this->api->delete($pm2->getId());
} catch (\Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException $e) {
$foundException = true;
} catch (\Doctrine\DBAL\Exception\DriverException $e) { // With Sqlite
$foundException = true;
}
$this->assertTrue($foundException, 'Expected exception was not thrown.');
}
public function testDeleteCascadeReferencee() {
......
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