Skip to content

Commit 50d470b

Browse files
authored
Merge pull request #244 from wp-cli/use-wp-cli-require
Use WP_CLI_REQUIRE to require codecov file for testing
2 parents 23dd5d0 + 7a340b8 commit 50d470b

File tree

2 files changed

+13
-43
lines changed

2 files changed

+13
-43
lines changed

src/Context/FeatureContext.php

Lines changed: 13 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -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.

src/Context/WhenStepDefinitions.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ public function when_i_launch_in_the_background( $cmd ) {
3535
* @When /^I (run|try) `([^`]+)`$/
3636
*/
3737
public function when_i_run( $mode, $cmd ) {
38-
$cmd = $this->get_command_with_coverage( $cmd );
3938
$cmd = $this->replace_variables( $cmd );
4039
$this->result = $this->wpcli_tests_invoke_proc( $this->proc( $cmd ), $mode );
4140
list( $this->result->stdout, $this->email_sends ) = $this->wpcli_tests_capture_email_sends( $this->result->stdout );
@@ -45,7 +44,6 @@ public function when_i_run( $mode, $cmd ) {
4544
* @When /^I (run|try) `([^`]+)` from '([^\s]+)'$/
4645
*/
4746
public function when_i_run_from_a_subfolder( $mode, $cmd, $subdir ) {
48-
$cmd = $this->get_command_with_coverage( $cmd );
4947
$cmd = $this->replace_variables( $cmd );
5048
$this->result = $this->wpcli_tests_invoke_proc( $this->proc( $cmd, array(), $subdir ), $mode );
5149
list( $this->result->stdout, $this->email_sends ) = $this->wpcli_tests_capture_email_sends( $this->result->stdout );

0 commit comments

Comments
 (0)