diff --git a/README.md b/README.md index ceb0c980..485e0b0d 100644 --- a/README.md +++ b/README.md @@ -147,6 +147,15 @@ chmod +x ~/wp-cli/wp WP_CLI_BIN_DIR=~/wp-cli composer behat ``` +#### Project configuration trust + +WP-CLI asks for confirmation before acting on `require`, `exec`, `env` or `ssh-args` directives found in a project-level `wp-cli.yml` file. Test fixtures create such files all the time and a test run cannot answer an interactive prompt, so the Behat context passes `WP_CLI_TRUST_PROJECT_CONFIG=1` to every command it runs. + +Set the `WP_CLI_TRUST_PROJECT_CONFIG` environment variable yourself to override that default for the whole run. Individual scenarios can override it per command: +``` +When I try `WP_CLI_TRUST_PROJECT_CONFIG=false wp cli version` +``` + ### Setting up the tests in Travis CI Basic rules for setting up the test framework with Travis CI: diff --git a/src/Context/FeatureContext.php b/src/Context/FeatureContext.php index 867f535c..c4055ad7 100644 --- a/src/Context/FeatureContext.php +++ b/src/Context/FeatureContext.php @@ -489,6 +489,14 @@ private static function get_process_env_variables(): array { $env['WP_CLI_REQUIRE'] = $updated; } + // Test fixtures routinely create project-level `wp-cli.yml` files that contain + // `require`, `exec`, `env` or `ssh-args` directives. WP-CLI gates those behind a + // trust confirmation, which cannot be answered in a non-interactive test run, so + // trust them by default. Scenarios that specifically test the trust mechanism can + // still override this by prefixing their command with their own value. + $trust_project_config = getenv( 'WP_CLI_TRUST_PROJECT_CONFIG' ); + $env['WP_CLI_TRUST_PROJECT_CONFIG'] = false !== $trust_project_config ? $trust_project_config : '1'; + $config_path = getenv( 'WP_CLI_CONFIG_PATH' ); if ( false !== $config_path ) { $env['WP_CLI_CONFIG_PATH'] = $config_path;