wp-phpunit / issues

Central issues repository for wp-phpunit
0 stars 0 forks source link

Tests don't run if database is not previously "installed" #7

Closed andrewmclagan closed 4 years ago

andrewmclagan commented 5 years ago

If my test database has not previously been installed through the Wordpress web-ui the tests silently fail.

If I install through the web ui they run perfectly.

Seems that the install script needs to be run BEFORE or INITIALLY?

andrewmclagan commented 5 years ago

Makes CI/CD very hard.

aaemnnosttv commented 5 years ago

Correct, although this is easy to set up. You can refer to the working examples which include this configuration in the .travis.yml.

For local development, you probably already have a DB created, and WP PHPUnit can use the same one; it uses a different table prefix to avoid conflicting with your normal tables.

andrewmclagan commented 5 years ago

Ah ok, that makes sense. Although from the Travis config in the https://github.com/wp-phpunit/example-plugin/blob/master/.travis.yml repo I cant seem to see where the database is installed?

- mysql -u root -e "CREATE DATABASE $WP_DB_NAME;"

Would simply create an empty database, not install the wordpress tables?

Side note, in the example-plugin repo, I noticed you upgraded the composer wordpress to "roots/wordpress": "^5.0", is that what you would reccomend over the previous wordpress composer package?

andrewmclagan commented 5 years ago

Sorry I still cannot workout how the database is being populated in Travis? @aaemnnosttv

aaemnnosttv commented 5 years ago

WP runs includes/install.php during its internal bootstrap.php which installs/resets the WP core tables. It happens right before the test runs; it isn't specific to Travis.