Skip to content

Enable displaying PHP errors to stderr if running behat.#4515

Merged
gitlost merged 3 commits intomasterfrom
enable_error_reporting
Nov 16, 2017
Merged

Enable displaying PHP errors to stderr if running behat.#4515
gitlost merged 3 commits intomasterfrom
enable_error_reporting

Conversation

@gitlost
Copy link
Contributor

@gitlost gitlost commented Nov 14, 2017

Fixes #4504

Enables displaying PHP errors (except E_DEPRECATED) to stderr if running behat, first on starting WP-CLI and then after WP loads.

Changes WP_CLI\Process to throw an error if stderr is non-empty if running behat.

Changes FeatureContext to redirect composer messages (which are output to stderr) to stdout, and to redirect warning messages on caching wp core download, and to skip-email, so as not to pollute stderr.

Suppresses "Warning: Wildcard DNS may not be configured correctly" message on Given a WP multisite install, so as not to pollute stderr. Also adds not option to the Then the return code should step for situations where there could be OS-dependent return values.

Adjusts various tests to allow for these changes, and removes individual stderr handling. Also in help.feature simplifies some copy-pasta introduced (by me) in #4285.

As noted in #4504, this PR will cause tests for bundled commands to fail until they're adjusted. It will also cause breakage in any external code that uses the behat test suite.

@schlessera
Copy link
Member

schlessera commented Nov 15, 2017

This would now be a use case for an external test suite package, that could be separately versioned. This way, we could add breaking changes by bumping the major version. Different commands could use different versions of the tests.

(... and probably break our automated full test suite in the process...? )

@danielbachhuber
Copy link
Member

As noted in #4504, this PR will cause tests for bundled commands to fail until they're adjusted.

Is this actually the case though? These files are copied into the bundled commands.

throw new \RuntimeException( $r );
}
// But do it right if testing.
if ( ! empty( $this->env['BEHAT_RUN'] ) && ! empty( $r->stderr ) ) {
Copy link
Member

Choose a reason for hiding this comment

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

Can we perform this check where run_check() is called, instead of modifying the Process class itself?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's called in a lot of places - do mean just in invoke_proc() https://github.com/wp-cli/wp-cli/blob/v1.4.1/features/steps/when.php#L7?

Copy link
Member

Choose a reason for hiding this comment

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

Yes. Given this change is specific to the test suite, it makes more sense to include it in the test suite.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, that would make the code a bit yuck, which usually isn't a good sign. Is the BEHAT_RUN check not exclusive enough?

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, that would make the code a bit yuck, which usually isn't a good sign.

Why?

Is the BEHAT_RUN check not exclusive enough?

It's hacky. It's not the Process class' responsibility to adapt behavior based on some environmental flag. It's Behat that wants to change the behavior of STDERR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll add it as a new function run_check_stderr() - that should keep us both happy...

@gitlost
Copy link
Contributor Author

gitlost commented Nov 15, 2017

Is this actually the case though?

Those tests that do an And I run step that produce non-empty stderr will fail until adjusted - a simple example is those that use the --debug flag, eg in package-command/features/package-install.feature#L31.

@danielbachhuber
Copy link
Member

Those tests that do an And I run step that produce non-empty stderr will fail until adjusted

But they're only fail after I run wp scaffold package-tests ? e.g. the fail won't occur until I copy the new version of the test suite into the package.

@gitlost
Copy link
Contributor Author

gitlost commented Nov 15, 2017

But they're only fail after I run wp scaffold package-tests

Sorry, yes (I think!).

@danielbachhuber danielbachhuber self-requested a review November 16, 2017 16:49
Copy link
Member

@danielbachhuber danielbachhuber left a comment

Choose a reason for hiding this comment

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

👌 Looks good on my end. Feel free to merge if you're happy with it.

@danielbachhuber danielbachhuber added this to the 1.5.0 milestone Nov 16, 2017
@danielbachhuber danielbachhuber added the scope:testing Related to testing label Nov 16, 2017
@gitlost
Copy link
Contributor Author

gitlost commented Nov 16, 2017

Cool. How do you want to deal with fixing the test breakages in the bundled commands? If you want to split them out and assign them I'm good for several hours now...

@gitlost gitlost merged commit e9d04ae into master Nov 16, 2017
@gitlost gitlost deleted the enable_error_reporting branch November 16, 2017 17:05
@danielbachhuber
Copy link
Member

If you want to split them out and assign them I'm good for several hours now...

If you want to go through each package individually and run wp scaffold package-tests ./ --force, I'm fine with that. I was going to refrain until #3924 is ready but I'm not opposed to doing them manually.

I don't think you need to create issues though. Feel free to simply start creating PRs with the updated test suite and the fixes.

@gitlost
Copy link
Contributor Author

gitlost commented Nov 16, 2017

Okay I'll start going through them alphabetically...

danielbachhuber added a commit to wp-cli/language-command that referenced this pull request Nov 17, 2017
danielbachhuber added a commit to wp-cli/import-command that referenced this pull request Nov 17, 2017
iandunn added a commit to iandunn/wp-cli that referenced this pull request Mar 22, 2018
As of wp-cli#4515, `WP_CLI\Runner\enable_error_reporting()` is called when running the Behat suite, in order to expose errors.

That's desirable in most situations, but there are some Behat scenarios which need to test WP_CLI's error handling directly, and `enable_error_reporting()` creates unwanted side-effects in those situations.

`WP_CLI_FORCE_BEHAT_ERROR_REPORTING` provides a way for scenarios to disable those side-effects when needed.
ahberg pushed a commit to ahberg/wp-cli that referenced this pull request Feb 5, 2021
As of wp-cli#4515, `WP_CLI\Runner\enable_error_reporting()` is called when running the Behat suite, in order to expose errors.

That's desirable in most situations, but there are some Behat scenarios which need to test WP_CLI's error handling directly, and `enable_error_reporting()` creates unwanted side-effects in those situations.

`WP_CLI_FORCE_BEHAT_ERROR_REPORTING` provides a way for scenarios to disable those side-effects when needed.
ahberg pushed a commit to ahberg/wp-cli that referenced this pull request Mar 5, 2021
As of wp-cli#4515, `WP_CLI\Runner\enable_error_reporting()` is called when running the Behat suite, in order to expose errors.

That's desirable in most situations, but there are some Behat scenarios which need to test WP_CLI's error handling directly, and `enable_error_reporting()` creates unwanted side-effects in those situations.

`WP_CLI_FORCE_BEHAT_ERROR_REPORTING` provides a way for scenarios to disable those side-effects when needed.
schlessera pushed a commit to ahberg/wp-cli that referenced this pull request Jan 5, 2022
As of wp-cli#4515, `WP_CLI\Runner\enable_error_reporting()` is called when running the Behat suite, in order to expose errors.

That's desirable in most situations, but there are some Behat scenarios which need to test WP_CLI's error handling directly, and `enable_error_reporting()` creates unwanted side-effects in those situations.

`WP_CLI_FORCE_BEHAT_ERROR_REPORTING` provides a way for scenarios to disable those side-effects when needed.
ahberg pushed a commit to ahberg/wp-cli that referenced this pull request Jan 22, 2022
As of wp-cli#4515, `WP_CLI\Runner\enable_error_reporting()` is called when running the Behat suite, in order to expose errors.

That's desirable in most situations, but there are some Behat scenarios which need to test WP_CLI's error handling directly, and `enable_error_reporting()` creates unwanted side-effects in those situations.

`WP_CLI_FORCE_BEHAT_ERROR_REPORTING` provides a way for scenarios to disable those side-effects when needed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope:testing Related to testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants