Skip to content

Env: Fix PHP unit tests for "non-standard" cloned directories - #39362

Merged
gziolo merged 2 commits into
WordPress:trunkfrom
xknown:fix/phpunit-tests
Mar 14, 2022
Merged

gziolo merged 2 commits into
WordPress:trunkfrom
xknown:fix/phpunit-tests

Conversation

@xknown

@xknown xknown commented Mar 10, 2022

Copy link
Copy Markdown
Member

What?

It updates the wp-env config file so the PHP unit tests work as expected on a non-standard cloned directory.

Why?

The PHP unit tests fail if our local copy is cloned into a "non-standard" directory.

For example:

$ git clone https://github.com/WordPress/gutenberg wp-gutenberg
$ npm ci; npm run build
$ npm run test-unit-php

Could not read "/var/www/html/wp-content/plugins/gutenberg/phpunit.xml.dist".
ERROR: 1

How?

It updates the .wp-env.json config file to map the volume wp-content/plugins/gutenberg to the current directory.

This is required because we have a few hardcoded paths in the package.json file.

"test-unit-php": "wp-env run phpunit 'phpunit -c /var/www/html/wp-content/plugins/gutenberg/phpunit.xml.dist --verbose'",

Testing Instructions

Run the PHP unit tests.

npm run wp-env destroy
npm run wp-env start
npm run prelint-php
npm run test-unit-php

Screenshots or screencast

xknown added 2 commits March 10, 2022 22:17
The PHP unit tests fail if the local copy is cloned into a "non-standard" directory.

For example:
```
$ git clone https://github.com/WordPress/gutenberg wp-gutenberg
$ npm ci; npm run build
$ npm run test-unit-php

Could not read "/var/www/html/wp-content/plugins/gutenberg/phpunit.xml.dist".
ERROR: 1
```

To avoid this, we add a new mapping so the hardcoded path on the npm "test-unit-php" script (https://github.com/WordPress/gutenberg/blob/2396f3a095d2dcf6248d60eae262a0564d13e2d9/package.json#L286) works as expected.
docker-compose fails to start if there are duplicate volumes.
@xknown
xknown requested a review from noahtallen as a code owner March 10, 2022 22:32

@noahtallen noahtallen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, this approach makes sense to me.

@alexstine

Copy link
Copy Markdown
Contributor

@carolinan You might want to give this a test on Windows to make sure all is still good? I don't use it primarily for dev or I would. I feel like a Windows sign off could be good for this as well.

@carolinan

Copy link
Copy Markdown
Contributor

Unfortunately, running any wp-env commands has not worked for me on Windows for many months and the errors are unrelated to the PHP unit test. It started with the destroy command not working, but after that was solved, eventually it escalated to not working at all.

I gave it a good try, but I am not able to test the PR.

@ajlende ajlende left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on Linux where I was having issues with the same thing, and it worked for me

@gziolo gziolo added [Tool] Env /packages/env [Type] Bug An existing feature does not function as intended labels Mar 14, 2022
@gziolo gziolo changed the title Fix PHP unit tests for "non-standard" cloned directories Env: Fix PHP unit tests for "non-standard" cloned directories Mar 14, 2022
@gziolo
gziolo merged commit 936ce3a into WordPress:trunk Mar 14, 2022
@github-actions github-actions Bot added this to the Gutenberg 12.9 milestone Mar 14, 2022
@xknown
xknown deleted the fix/phpunit-tests branch March 14, 2022 13:11
@getdave

getdave commented Mar 6, 2023

Copy link
Copy Markdown
Contributor

Strangle I've recountered something similar today.

Test failure:

Class phpunit.xml.dist could not be found in /var/www/html/wp-content/plugins/gutenberg/phpunit.xml.dist

desrosj added a commit that referenced this pull request Oct 27, 2026
….9) (#85712)

* Env: Don't add duplicate volumes to the generated docker-compose.yml file.

docker-compose fails to start if a volume is listed more than once. That
happens when a directory mapping and a plugin source resolve to the same
path, such as mapping `wp-content/plugins/gutenberg` to `.` while `.` is
also loaded as a plugin from a checkout named `gutenberg`.

Backports the `packages/env` part of #39362.

(cherry picked from commit 936ce3a)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* Env: Mount the plugin at `wp-content/plugins/gutenberg` in the tests environment.

The PHP unit test commands use the hardcoded path
`/var/www/html/wp-content/plugins/gutenberg`, but wp-env mounts the plugin
under the name of the directory it was checked out into. In a checkout with
any other name, PHPUnit fails with:

    Could not read "/var/www/html/wp-content/plugins/gutenberg/phpunit.xml.dist".

Map `wp-content/plugins/gutenberg` to the repository root so the path always
exists.

Backports the `.wp-env.json` part of #39362.

(cherry picked from commit 936ce3a)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Alex Concha <xknown@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-authored-by: desrosj <desrosj@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
desrosj added a commit that referenced this pull request Oct 27, 2026
….8) (#85711)

* Env: Don't add duplicate volumes to the generated docker-compose.yml file.

docker-compose fails to start if a volume is listed more than once. That
happens when a directory mapping and a plugin source resolve to the same
path, such as mapping `wp-content/plugins/gutenberg` to `.` while `.` is
also loaded as a plugin from a checkout named `gutenberg`.

Backports the `packages/env` part of #39362.

(cherry picked from commit 936ce3a)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* Env: Mount the plugin at `wp-content/plugins/gutenberg` in the tests environment.

The PHP unit test commands use the hardcoded path
`/var/www/html/wp-content/plugins/gutenberg`, but wp-env mounts the plugin
under the name of the directory it was checked out into. In a checkout with
any other name, PHPUnit fails with:

    Could not read "/var/www/html/wp-content/plugins/gutenberg/phpunit.xml.dist".

Map `wp-content/plugins/gutenberg` to the repository root so the path always
exists.

Backports the `.wp-env.json` part of #39362.

(cherry picked from commit 936ce3a)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Alex Concha <xknown@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-authored-by: desrosj <desrosj@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
desrosj added a commit that referenced this pull request Oct 27, 2026
….7) (#85710)

* Env: Don't add duplicate volumes to the generated docker-compose.yml file.

docker-compose fails to start if a volume is listed more than once. That
happens when a directory mapping and a plugin source resolve to the same
path, such as mapping `wp-content/plugins/gutenberg` to `.` while `.` is
also loaded as a plugin from a checkout named `gutenberg`.

Backports the `packages/env` part of #39362.

(cherry picked from commit 936ce3a)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* Env: Mount the plugin at `wp-content/plugins/gutenberg` in the tests environment.

The PHP unit test commands use the hardcoded path
`/var/www/html/wp-content/plugins/gutenberg`, but wp-env mounts the plugin
under the name of the directory it was checked out into. In a checkout with
any other name, PHPUnit fails with:

    Could not read "/var/www/html/wp-content/plugins/gutenberg/phpunit.xml.dist".

Map `wp-content/plugins/gutenberg` to the repository root so the path always
exists.

Backports the `.wp-env.json` part of #39362.

(cherry picked from commit 936ce3a)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Alex Concha <xknown@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-authored-by: desrosj <desrosj@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
desrosj added a commit that referenced this pull request Oct 27, 2026
….6) (#85709)

* Env: Don't add duplicate volumes to the generated docker-compose.yml file.

docker-compose fails to start if a volume is listed more than once. That
happens when a directory mapping and a plugin source resolve to the same
path, such as mapping `wp-content/plugins/gutenberg` to `.` while `.` is
also loaded as a plugin from a checkout named `gutenberg`.

Backports the `packages/env` part of #39362.

(cherry picked from commit 936ce3a)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* Env: Mount the plugin at `wp-content/plugins/gutenberg` in the tests environment.

The PHP unit test commands use the hardcoded path
`/var/www/html/wp-content/plugins/gutenberg`, but wp-env mounts the plugin
under the name of the directory it was checked out into. In a checkout with
any other name, PHPUnit fails with:

    Could not read "/var/www/html/wp-content/plugins/gutenberg/phpunit.xml.dist".

Map `wp-content/plugins/gutenberg` to the repository root so the path always
exists.

Backports the `.wp-env.json` part of #39362.

(cherry picked from commit 936ce3a)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Alex Concha <xknown@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-authored-by: desrosj <desrosj@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
desrosj added a commit that referenced this pull request Oct 27, 2026
….5) (#85708)

* Env: Don't add duplicate volumes to the generated docker-compose.yml file.

docker-compose fails to start if a volume is listed more than once. That
happens when a directory mapping and a plugin source resolve to the same
path, such as mapping `wp-content/plugins/gutenberg` to `.` while `.` is
also loaded as a plugin from a checkout named `gutenberg`.

Adapted from the `packages/env` part of #39362 for this branch's version of
wp-env, which builds a single list of local mounts for every service.

Co-authored-by: Alex Concha <xknown@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* Env: Mount the plugin at `wp-content/plugins/gutenberg`.

The PHP unit test commands use the hardcoded path
`/var/www/html/wp-content/plugins/gutenberg`, but wp-env mounts the plugin
under the name of the directory it was checked out into. In a checkout with
any other name, PHPUnit fails with:

    Could not read "/var/www/html/wp-content/plugins/gutenberg/phpunit.xml.dist".

Map `wp-content/plugins/gutenberg` to the repository root so the path always
exists. This branch's version of wp-env does not support per-environment
mappings, so the mapping is added at the top level.

Adapted from the `.wp-env.json` part of #39362.

Co-authored-by: Alex Concha <xknown@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Alex Concha <xknown@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-authored-by: desrosj <desrosj@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Tool] Env /packages/env [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants