-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WP_Env: tests-cli phpunit executable file not found in $PATH: unknown #54508
WP_Env: tests-cli phpunit executable file not found in $PATH: unknown #54508
Conversation
There is still some work to be done here. Although adding Executes only
Same result with the double-dash
Adding quotes executes the entire command with flags
Without
Related: #42286 |
Hey @jrtashjian, Honestly, I'd really like to avoid ever doing anything like this. In #50559 I reworked the way that commands are passed to If wonder if this failure is a problem with Docker rather than As far as I can tell the problem is that Docker isn't using the Editing the path of |
@ObliviousHarmony Try hardcoding the
Maybe something like this?
I just wonder, if the www-data user does not have its own home directory, maybe you need to pass "--" in the command to inherit environment variables from the current context which I would guess is root by default? |
Thanks, @ObliviousHarmony! This is the feedback I was hoping for. I was sure I was missing some important context about the rework in #50559. During my investigation, I encountered similar issues to those you've outlined. I can undo the modification I made and propose removing the global installation of This approach would completely avoid our current issue. I'll also update the wp-env readme, as I suspect it might have contributed to some confusion, given that phpunit used to work globally with |
… unknown" This reverts commit 4916bec.
Thanks for the suggestion @alexstine, but since we're using custom Docker images with The problem is that the |
Before I started spending a lot of time writing GitHub Workflows I would have 100% agreed with you here. Since initially removing the container, however, I have come across some important use-cases for keeping this feature alive. Assuming that a plugin has a minimum version of PHP they should be setting that as an The caveat here is that by setting the By globally installing the Yoast Polyfills, however, we are guaranteed to get the version of PHPUnit that is associated with the version of PHP the container is currently running. In hindsight, we probably shouldn't be installing the polyfills and should instead just be installing PHPUnit with an appropriate constraint and let Composer resolve it automatically based on the version of PHP running. There's nothing to be gained from installing the Yoast package. In any case, this means you can safely run PHPUnit in the container regardless of PHP version. What do you think of this @jrtashjian:
This would solve the linked bug while better supporting the intended usage. |
Are you guys sure about that? This would probably defeat the purpose of having If you create a test, that uses test case extending
So in 99% of cases I will still be required to require polyfills myself in the project (which has phpunit as dependency). Not to even mention that yoast/phpunit-polyfills now released version 2.0 that supports PHPUnit 10 and testing in PHP version > 8.1, which would be even better to include. EDIT: to know why polyfills are now requirement for Also from the "What has changed?" section:
So having this minimal (required to run your WordPress tests) bootstrap file, is going to throw the above error: <?php
// bootstrap.php
$wp_tests_dir = getenv( 'WP_TESTS_DIR' ) ? getenv( 'WP_TESTS_DIR' ) : sys_get_temp_dir();
require_once $wp_tests_dir . '/includes/bootstrap.php'; This comes from: https://github.com/WordPress/wordpress-develop/blob/8161a8c62a2bfdee02fdbeb4aa7ea773f42e7afa/tests/phpunit/includes/bootstrap.php#L80 |
I'm only talking about the global install. Your project will still need to install the polyfills. The polyfills provide a consistent API that can replace methods in the PHPUnit base class that have breaking changes between versions. The only thing we are talking about here is the global PHPUnit installation. |
Thanks, @ObliviousHarmony! That worked perfectly. I've pushed up the new changes for review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @jrtashjian,
This tests well and looks good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, one thing! It needs a changelog @jrtashjian 😄
On MacOS, I have a bug that looks like it will be fixed with this. Running:
I get:
|
What?
When running commands with
wp-env run container
, use/bin/bash
instead of/bin/sh
(which docker exec defaults to).Why?
Fixes #51686. The
phpunit
command exists in~/.composer/vendor/bin
directory, installed as a dependency ofyoast/phpunit-polyfills
, and the global composer bin directory is added to$PATH
. However, when runningnpx wp-env run tests-cli phpunit
the following error was displayed:The command was failing when executed in a /bin/sh environment but was successful in a /bin/bash environment.
Testing Instructions
To see the failure:
npx wp-env run tests-cli phpunit
To see success
npx wp-env run tests-cli phpunit
⭐ Kudos to @dawidurbanski for their help in this investigation!