sebastianbergmann / dbunit

DbUnit port for PHP/PHPUnit.
https://phpunit.de/
Other
224 stars 190 forks source link

Don't loose mysql FOREIGN_KEY_CHECKS status #191

Closed gsouf closed 6 years ago

gsouf commented 7 years ago

Hi,

When truncate operation occurs on mysql database the FOREIGN_KEY_CHECKS is modified and when restored, it is set to an arbitrary ("1") value and the previous value is lost.

In some case we use this trick to allow phpunit to populate database from dataset without foreign key errors:

protected function setUp()
    {
        $conn=$this->getConnection();
        $conn->getConnection()->query('set FOREIGN_KEY_CHECKS=0;');
        parent::setUp();
        $conn->getConnection()->query('set FOREIGN_KEY_CHECKS=1;');
    }

The truncate operations conflicts with this and this PR aims to fix that.

gsouf commented 7 years ago

See #37

sebastianbergmann commented 6 years ago

I merged this pull request without testing it. I do not use DbUnit myself and trust the existing tests as well comments on the pull requests that this does not break anything and solves a problem.