Magento – Recreate the table in integration tests database

integration-testmagento2moduleupgrade

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?

Best Answer

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).

Related Topic