-
Notifications
You must be signed in to change notification settings - Fork 998
Fix unstable package override tests #6069
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
Conversation
So it doesn't clash with an earlier autoloaded `Eval_Command`
Codecov ReportAll modified and coverable lines are covered by tests ✅ 📢 Thoughts on this report? Let us know! |
@schlessera wrote down the details now and would appreciate some extra eyes. |
Some initial debugging suggests this is just an issue with the order packages are being autoloaded. the This suggests to me that it isn't possible to reliably actually override an existing command in the way we test, and it just happened to 'work' before because we used the same class names. If you add |
I should use One of the early bootstrap steps is Later on, In tests, this will add the commands found in I don't know whether that means it is working as intended. However, conceptually, I would think that a reliable override would need to happen by actually waiting for the original command to be registered first, by hooking into WP_CLI::add_hook(
'after_add_command:eval',
static function () {
WP_CLI::add_command( 'eval', 'Custom_Eval_Command', array( 'when' => 'before_wp_load' ) );
}
); |
^ That seems to cause an infinite loop during tests though because the hook fires every time the command is added again. With a simple static variable it seems to work now... |
It worked 🥳 |
Here's what's going on:
Right now, on the main branch, some of the tests are failing when code coverage is failing:
Example run: https://github.com/wp-cli/wp-cli/actions/runs/14721677772/job/41316957178#step:11:73
004 is due to memory limit, but the other 3 ones can be attributed to a change in how the autoloading works when code coverage is involved:
When running tests with
WP_CLI_TEST_COVERAGE=1
, we modify the command that's being run to prependWP_CLI_REQUIRE=vendor/wp-cli/wp-cli-tests/utils/generate-coverage.php
. So given the above example, it will becomeWP_CLI_REQUIRE=vendor/wp-cli/wp-cli-tests/utils/generate-coverage.php vendor/bin/wp eval '\WP_CLI::Success( "WP-Standard-Eval" );'
The
generate-coverage.php
file requires the project's autoloader to ensure that the code coverage classes exist, see https://github.com/wp-cli/wp-cli-tests/blob/7ac2ff7fc494f94ba34410ea4e7e2409e2afb945/utils/generate-coverage.php#L33-L38The above tests were failing because they defined a custom
\Eval_Command
class to overridewp eval
, but because of the early autoloading, the original\Eval_Command
class (yes, same name) was loaded, so no override was happening.IMO this is just an oversight in the test. If someone overrides a specific command, they should be using a custom class name anyway. So this PR changes those tests to use a custom class name so it doesn't clash with the earlier autoloaded
Eval_Command
.Good news: with this PR, all tests with code coverage now pass 🎉
Bad news: 2 tests fail when code coverage is disabled. Example run: https://github.com/wp-cli/wp-cli/actions/runs/14727955107/job/41335108255?pr=6069#step:11:75
Weirdly enough I cannot seem to reproduce those locally when performing those steps manually 🤔 So not sure why they fail during tests.
See wp-cli/wp-cli-tests#241