Note that there are some explanatory texts on larger screens.

plurals
  1. POSet foreign key constraints off in PHPUnit/DBUnit
    primarykey
    data
    text
    <p>I am developing Unit tests for testing model functions.</p> <p>I am using PHP PDO with DBUnit 1.1.2 and PHPUnit 3.6.10 and my dataset is a yml file. </p> <p>I need to turn off foreign key checks while the fixtures are being loaded in the database. After that I need to turn it on again so that I can run my tests under those constraints.</p> <p>Below is a snippet (not the entire class file) of code in my generalized Testcase file which I will include for any new test case I develop.</p> <p>When I run a test case under these settings these settings i found that $pdo->exec() is not executing.</p> <p>What is wrong with my approach? Is there a better alternative?</p> <pre><code>class MyTestCase extends PHPUnit_Extensions_Database_TestCase { public function getConnection() { $this-&gt;pdo = $this-&gt;getPDO(); echo "BEFORE FOREIGN KEY QUERY\n"; $conn = $this-&gt;createDefaultDBConnection($this-&gt;pdo, 'my-schema'); $this-&gt;pdo-&gt;exec("set foreign_key_checks=0"); return $conn; } private function getPDO() { include BASEPATH . '/application/config/database.php'; $dbt = $db['testing']; $conn_string = sprintf("%s:host=%s;dbname=%s", $dbt['dbdriver'], $dbt['hostname'], $dbt['database']); $pdo = new PDO($conn_string, $dbt['username'], $dbt['password']); return $pdo; } public function getDataSet() { echo "BEFORE FOREIGN KEY QUERY in getDataSet\n"; $this-&gt;pdo-&gt;exec("set foreign_key_checks=1"); return new PHPUnit_Extensions_Database_DataSet_YamlDataSet(ROOTPATH."/application/tests/data/my-dataset.yml"); } public function setUp() { parent::setUp(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload