Let's say I created a module that has it's own setup script that should create a new table. Everything installed fine through command line and when I ran integration tests that table was there (in integration tests database).

I realized I made a mistake in my setup script, so I changed it, deleted the entry in setup_module database table, deleted the table, ran the bin/magento setup:upgrade command, and the table in my main table was recreated well.

The problem is that the table in my integration tests database remains unchanged. I tried deleting tmp and var folders with no luck.

Any way around this?

3 Answers 3


In dev/tests/integration/phpunit.xml.dist there is a setting responsible for clearing cache and DB on each tests execution <const name="TESTS_CLEANUP" value="enabled"/>. Make sure it is set to true in PHPUnit config which is used when you run tests.

Also note, that while it is more reliable to use this option (you get up-to-date environment on each run), it will delay the beginning of tests execution since Magento will be reinstalled in this case (will only affect tests DB).

  • It was already set to enabled, so it seems that that didn't work.
    – LDusan
    Nov 20, 2015 at 9:35
  • Not sure why it does not work for you, because eventually 'bin/magento setup:uninstall' is invoked when this option is enabled. Try to see locally if this method gets executed \Magento\Setup\Model\Installer::cleanupDb() and if this one is invoked $connection->query("DROP DATABASE IF EXISTS {$dbName}"); Do you have correct DB name there? Nov 20, 2015 at 9:51
  • No, that method doesn't get executed at all. Could it be because I run tests with phpunit -c phpunit.xml.dist and not with Magento's command?
    – LDusan
    Nov 21, 2015 at 9:41
  • There is custom integration tests bootstrap specified in phpunit.xml.dist, so it should work. Try to debug from the place where "TESTS_CLEANUP" is processed in dev/tests/integration/framework/bootstrap.php Nov 21, 2015 at 9:47
  • Thanks for the hint. It seems that the part where it drops all the tables is correct, as I stopped execution after that command and the database was empty. To me it looks like the problem is in the command that is executed after that which imports a generated sql file - tmp/sandbox-0-ea0543eebf20233936da0f99664bf3a9/setup_dump_magento_integration_tests.sql. That script contains the old database table definition. Do you maybe know how is this script generated? I cleared all the var and tmp folders.
    – LDusan
    Nov 21, 2015 at 10:12

If you don't want to change the TESTS_CLEANUP setting, you can also:

  • delete the row in the integration tests database:

    delete from magento_integration_tests.setup_module where module = 'MODULE_NAME';
  • delete integration test tmp directory:

    rm -rf dev/tests/integration/tmp/*

The next integration test execution will trigger the install scripts for MODULE_NAME

  • Nice idea, thanks, I'll try that and let you know.
    – LDusan
    Aug 4, 2016 at 13:05

Issued the same problem. The following steps helps at least in my situation:

  • Clear /var/generation
  • Flush cache with magento cache:flush
  • Remove your module entry in testing database table setup_module

Rerun your integration tests.

I guess magento gets something from cache in real database (e.g.) in order to build up the testing environment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.