gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

wp-env: Failing to run PHPUnit tests using wp-env in GitLab CI

Open Antonin06 opened this issue 1 year ago • 1 comments

What problem does this address?

Hey,

I’m encountering issues running PHPUnit tests for my WordPress plugin using wp-env inside a GitLab CI pipeline. Despite several attempts and command variations, the tests are not executing properly.

Project: example-plugin-env-ci

Problem Summary

I’m using wp-env to spin up the environment and run tests via vendor/bin/phpunit with a phpunit.xml.dist config file located at the plugin root.

All my attempts to run tests inside the tests-cli container are failing with errors like:

  • stat vendor/bin/phpunit: no such file or directory
  • or Could not read "phpunit.xml.dist"
  • or simply outputting PHPUnit usage info without running any test.
  • Could not find /wordpress-phpunit/includes/functions.php, have you run bin/install-wp-tests.sh ?

When I run the following inside the container: wp-env run tests-cli bash cd / ls -lah

I noticed that the wordpress-phpunit directory is not present inside the container like it is when running wp-env locally. This could potentially explain why some files like /wordpress-phpunit/includes/functions.php are missing and cause errors during PHPUnit runs.

If anyone has:

  • A working CI setup with wp-env + PHPUnit in GitLab
  • Faced and solved similar missing directory issues in CI

Please share your solution or insights!

Thanks in advance

Antonin06 avatar Apr 03 '25 12:04 Antonin06

Two separate causes here:

  1. vendor/bin/phpunit not found, phpunit.xml.dist unreadable, or PHPUnit usage output: wp-env run starts in the WordPress root, not your plugin. Pass --env-cwd=wp-content/plugins/<your-plugin>.

  2. Missing /wordpress-phpunit/includes/functions.php: with docker:dind, the daemon is a separate container, so the host paths wp-env bind-mounts (the PHPUnit suite and your plugin) don't exist there and Docker mounts empty directories. I reproduced this with @wordpress/env 12.1.0: both /wordpress-phpunit and the plugin directory were empty inside the container. Having the project and WP_ENV_HOME at the same path on both the job and the daemon should avoid it, though I haven't tested that yet.

Running as root is a separate problem, tracked in #76564.

vedant-ere avatar Nov 08 '26 11:11 vedant-ere