@@ -297,6 +297,19 @@ private static function get_process_env_variables() {
297297 'TEST_RUN_DIR ' => self ::$ behat_run_dir ,
298298 ];
299299
300+ $ with_code_coverage = (string ) getenv ( 'WP_CLI_TEST_COVERAGE ' );
301+ if ( \in_array ( $ with_code_coverage , [ 'true ' , '1 ' ], true ) ) {
302+ $ coverage_require_file = self ::$ behat_run_dir . '/vendor/wp-cli/wp-cli-tests/utils/generate-coverage.php ' ;
303+ if ( ! file_exists ( $ coverage_require_file ) ) {
304+ // This file is not vendored inside the wp-cli-tests project
305+ $ coverage_require_file = self ::$ behat_run_dir . '/utils/generate-coverage.php ' ;
306+ }
307+
308+ $ current = getenv ( 'WP_CLI_REQUIRE ' );
309+ $ updated = $ current ? "{$ current }, {$ coverage_require_file }" : $ coverage_require_file ;
310+ $ env ['WP_CLI_REQUIRE ' ] = $ updated ;
311+ }
312+
300313 $ config_path = getenv ( 'WP_CLI_CONFIG_PATH ' );
301314 if ( false !== $ config_path ) {
302315 $ env ['WP_CLI_CONFIG_PATH ' ] = $ config_path ;
@@ -377,7 +390,6 @@ private static function get_behat_internal_variables() {
377390 'FRAMEWORK_ROOT ' => realpath ( $ framework_root ),
378391 'SRC_DIR ' => realpath ( dirname ( dirname ( __DIR__ ) ) ),
379392 'PROJECT_DIR ' => realpath ( dirname ( dirname ( dirname ( dirname ( dirname ( __DIR__ ) ) ) ) ) ),
380- 'TEST_RUN_DIR ' => self ::$ behat_run_dir ,
381393 ];
382394
383395 return $ variables ;
@@ -690,46 +702,6 @@ public function __construct() {
690702 $ this ->set_cache_dir ();
691703 }
692704
693- /**
694- * Enhances a `wp <command>` string with an additional `--require` for code coverage collection.
695- *
696- * Only applies if `WP_CLI_TEST_COVERAGE` is set.
697- *
698- * @param string $cmd Command string.
699- * @return string Possibly enhanced command string.
700- */
701- public function get_command_with_coverage ( $ cmd ) {
702- $ with_code_coverage = (string ) getenv ( 'WP_CLI_TEST_COVERAGE ' );
703-
704- if ( \in_array ( $ with_code_coverage , [ 'true ' , '1 ' ], true ) ) {
705-
706- $ modify_command = function ( $ part ) {
707- if ( preg_match ( '/(^wp )|( wp )|(\/wp )/ ' , $ part ) ) {
708- $ part = preg_replace ( '/(^wp )|( wp )|(\/wp )/ ' , '$1$2$3 ' , $ part );
709-
710- $ require_path = '{TEST_RUN_DIR}/vendor/wp-cli/wp-cli-tests/utils/generate-coverage.php ' ;
711- if ( ! file_exists ( $ this ->variables ['TEST_RUN_DIR ' ] . '/vendor/wp-cli/wp-cli-tests/utils/generate-coverage.php ' ) ) {
712- // This file is not vendored inside the wp-cli-tests project
713- $ require_path = '{TEST_RUN_DIR}/utils/generate-coverage.php ' ;
714- }
715- $ part .= " --require= {$ require_path }" ;
716-
717- }
718- return $ part ;
719- };
720-
721- if ( strpos ( $ cmd , '| ' ) !== false ) {
722- $ parts = explode ( '| ' , $ cmd );
723- $ parts = array_map ( $ modify_command , $ parts );
724- $ cmd = implode ( '| ' , $ parts );
725- } else {
726- $ cmd = $ modify_command ( $ cmd );
727- }
728- }
729-
730- return $ cmd ;
731- }
732-
733705 /**
734706 * Replace standard {VARIABLE_NAME} variables and the special {INVOKE_WP_CLI_WITH_PHP_ARGS-args} and {WP_VERSION-version-latest} variables.
735707 * Note that standard variable names can only contain uppercase letters, digits and underscores and cannot begin with a digit.
0 commit comments