I'm using phpunit with Symfony2.
I decided to use sqlite for my tests.
The issue I'm having is that the foreign keys constraints are ignored.
I know I have to execute the following query in order to use foreign keys : PRAGMA foreign_keys = ON
).
My question is : is there a way to always use foreign keys when creating the database schema with sqlite ?
Thanks !
Unfortunately it is impossible. Accordingly to SQLite documentation:
Assuming the library is compiled with foreign key constraints enabled, it must still be enabled by the application at runtime, using the PRAGMA foreign_keys command.
I would suggest to create your own test case class and use setUp() method to enable foreign keys.
class SQLiteTestCase extends \PHPUnit_Framework_TestCase
{
protected function setUp()
{
parent::setUp();
// Here add your code to enable foreign keys
}
}
class MyTest extends SQLiteTestCase
{
protected function setUp()
{
// Setup your test data-set here
parent::setUp();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With