wp-browser icon indicating copy to clipboard operation
wp-browser copied to clipboard

WPCLI module: fix broken env handling and introduce new per process env options.

Open calvinalkan opened this issue 1 year ago • 3 comments

This PR consists of seven atomic commits with a lot of tests so that it's easy to grasp. All fixes and features are backward compatible.

849191f6f9dd7497ada173de168c4d47a14a3171 - A fix for something that has never worked to begin with, which is inheriting from the current shell env if the env key is set in the configuration for the WPCLI module.

65b1ded7684a05673daa9c36ecdfb7a7441dbff6 - Allows setting per process env vars by passing them to $I->cli(). This closes my feature request https://github.com/lucatume/wp-browser/issues/576

413552182044400bd04a90c2e823cf976c6cf286 - Allows setting shell variables for all commands of a test through a PHP API. This is way better than using $ENV or putenv because it does not pollute the scope of the runner shell. This also lays the groundwork for an idea that I have for being able to collect code coverage for WP-CLI tests. Something that is not currently possible at all.

413552182044400bd04a90c2e823cf976c6cf286 - Allows setting env variables for all wp-cli tests using the wp-cli.suite.yml config, this does not introduce a new option but uses the already existing env key. This is very helpful for docker based setups where for example in my case I need to pass the name of the database to use during cli tests dynamically. I can't hard code this in wp-config because I'm doing parallel runs with multiple compose networks. So in docker I read the db to be used out of the current SHELL env. So being able to pass this at runtime in one place would be huge. Currently, I need all sorts of hacks for this.

413552182044400bd04a90c2e823cf976c6cf286 - Allows preventing inheritance of the runner shell on a per command basis.

It would be great if you could merge this PR and the other two open once and release a 3.2.0 version.

calvinalkan avatar Aug 03 '22 14:08 calvinalkan

8eb460ed8d9d940c5d9392f1e5d3c37f55b20a41 - Allows preventing the inheritance of a few select env variables.

I added this feature because I lost nearly a day with the following scenario:

Running codeception like this: codecept run --quiet will populate a global SHELL_VERBOSITY env variable.

This is inherited into the child process in the test which made by test fail due to side effects. symfony/console has some more of these and it would be great to allow to prevent inheriting them

calvinalkan avatar Aug 04 '22 15:08 calvinalkan

491fae8f55306363caa1ef341639be9d763694d6- allow blocking some runner envs vars through module config.

This leverages the API provided in 8eb460e to allow preventing the inheritance of some env vars through the configuration to avoid repetition and cluttering of the tests.

This is how its used:


modules:
    enabled:
        - WPCLI
    config:
        WPCLI:
            path: '%WORDPRESS_ROOT_DIR%'
            allow-root: 1
            without_env:
              - FOO_BLOCKED

calvinalkan avatar Aug 04 '22 16:08 calvinalkan

@lucatume bump

calvinalkan avatar Sep 03 '22 13:09 calvinalkan

Due to GitHub notifications issues, I'm reading this now, sorry.

I appreciate the effort and the contribution and will earmark this as something to be ported over to v4.

Merging in v3.

lucatume avatar Jan 23 '23 19:01 lucatume