Use local tooling to run PHPUnit tests instead of wp-dev-lib#1124
Conversation
| "repositories": [ | ||
| { | ||
| "type": "git", | ||
| "url": "https://github.com/WordPress/wordpress-develop.git" |
There was a problem hiding this comment.
We use https://github.com/johnpbloch/wordpress now which doesn't require any build steps and is much faster to install, and can be used in combination of wp-phpunit/wp-phpunit to run the unit tests with any version of WP core.
| } | ||
| }, | ||
| "extra": { | ||
| "wordpress-install-dir": "local/public" |
There was a problem hiding this comment.
Previously we were using the WP core files provisioned by the wordpress docker container during the entrypoint setup. We now have full control of the source files used for development which is much more reliable and provisions the container much faster, too.
| }, | ||
| "scripts": { | ||
| "pre-install-cmd": [ | ||
| "Composer\\Config::disableProcessTimeout" |
There was a problem hiding this comment.
Replaced with a 600 second timeout for all commands as a sane default.
There was a problem hiding this comment.
@kasparsd I don't know the original purpose of this timeout.
@kopepasah You implemented this originally. Are you okay with this change?
| WORDPRESS_DB_USER: wordpress | ||
| WORDPRESS_DB_PASSWORD: password | ||
| WP_TESTS_DIR: /var/www/html/wp-content/plugins/stream-src/vendor/wp-phpunit/wp-phpunit | ||
| WP_PHPUNIT__TESTS_CONFIG: /var/www/html/wp-tests-config.php |
There was a problem hiding this comment.
This is required for wp-phpunit/wp-phpunit to find the WP install.
|
|
||
| define( 'ABSPATH', dirname( dirname( __DIR__ ) ) . '/' ); | ||
|
|
||
| define( 'WP_TESTS_MULTISITE', true ); |
There was a problem hiding this comment.
We use the WP_MULTISITE environment variable to control this behaviour now.
| - WP_VERSION=latest WP_MULTISITE=0 | ||
| - WP_VERSION=latest WP_MULTISITE=1 | ||
| - WP_VERSION=trunk WP_MULTISITE=0 | ||
| - WP_VERSION=trunk WP_MULTISITE=1 |
There was a problem hiding this comment.
We now have npm run phpunit-multisite for this.
|
@kidunot89 Could you please code review this? I've left inline comments to explain the changes. This simplifies and unifies the testing approach across environments and we should have much more reliable developer experience going forward. Here are sample Travis runs https://travis-ci.com/github/xwp/stream/builds/174220409 |
| - WP_VERSION=latest WP_MULTISITE=1 | ||
| - WP_VERSION=trunk WP_MULTISITE=0 | ||
| - WP_VERSION=trunk WP_MULTISITE=1 | ||
| php: "7.4" |
There was a problem hiding this comment.
Travis jobs now handle the different types of runs we need.
| env: { | ||
| "DOCKER_COMPOSE_FILE" => "/vagrant/docker-compose.yml" | ||
| } | ||
| inline: "docker-compose -f /vagrant/docker-compose.yml exec -T --user 1000 wordpress xwp_wait mysql:3306 -t 60 -- wp core multisite-install --url=stream.local", |
There was a problem hiding this comment.
Replaced the bash script with an inline command that does the same thing.
| "test": [ | ||
| "phpunit --coverage-text" | ||
| "phpunit --coverage-text", | ||
| "php local/scripts/make-clover-relative.php ./tests/reports/clover.xml" |
There was a problem hiding this comment.
This converts all file paths inside the coverage reports to be relative to the project root instead of absolute paths inside the Docker container which was causing issues to Coveralls reporting.
|
|
||
| FROM wordpress:php${PHP_VERSION}-apache | ||
|
|
||
| ARG XDEBUG_VERSION=2.9.6 |
There was a problem hiding this comment.
PHP 5.6 needs an earlier version so we provide an ARG to override it as needed on Travis.
| "lint": "npm run lint-js && npm run lint-php", | ||
| "cli": "./local/vagrant/cli.sh", | ||
| "compose": "./local/vagrant/docker-compose.sh", | ||
| "stop-all": "docker stop $(docker ps -a -q)", |
There was a problem hiding this comment.
This is a new helper to stop all running containers on a Docker host in case there are port conflicts.
| "phpunit-report": "npm run cli -- composer test-report --working-dir=wp-content/plugins/stream-src", | ||
| "vcli": "vagrant ssh -- DOCKER_COMPOSE_FILE=/vagrant/docker-compose.yml /vagrant/local/vagrant/cli.sh", | ||
| "vcompose": "vagrant ssh -- DOCKER_COMPOSE_FILE=/vagrant/docker-compose.yml /vagrant/local/vagrant/docker-compose.sh", | ||
| "phpunit-multisite": "npm run cli -- composer test-multisite --working-dir=wp-content/plugins/stream-src", |
There was a problem hiding this comment.
This is a new helper for running the same unit tests with a WP multisite.
| }, | ||
| "scripts": { | ||
| "pre-install-cmd": [ | ||
| "Composer\\Config::disableProcessTimeout" |
There was a problem hiding this comment.
@kasparsd I don't know the original purpose of this timeout.
@kopepasah You implemented this originally. Are you okay with this change?
|
Thanks for reviewing the code and testing the changes @kidunot89! Could you please try running composer install after deleting the vendor directory and the local/public directory? I tested both Docker and Vagrant runs locally and they seem to work fine. |
|
@kasparsd Sorry about the delayed response, deleting the |

Follow-up to #1123.
Use
johnpbloch/wordpressandwp-phpunit/wp-phpunitto run PHPunit tests instead ofwp-dev-lib.Introduce the
wait-for-it.shhelper to wait for the MySQL server to come alive in thedb_phpunitcontainer.Simplify helpers and scripts for running tasks in Docker containers and inside the Vagrant wrapper for the Docker.
Add support for running PHPunit tests with different versions of PHP in the
wordpresscontainer. Switch Travis to build those containers instead of using different versions of PHP on the host. Sample run https://travis-ci.com/github/xwp/stream/jobs/357370647Fix coverage reporting on Coveralls https://coveralls.io/github/xwp/stream -- introduce a new helper PHP script to make all file paths in coverage report relative to the project directory instead of absolute since the coverage reportΒ is generated inside Docker container and those paths don't exist outside of Docker.