Skip to content

Commit ab81bed

Browse files
committed
Add to when_i_run_from_a_subfolder
1 parent aa2ce7e commit ab81bed

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/Context/FeatureContext.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,23 @@ public function __construct() {
683683
$this->set_cache_dir();
684684
}
685685

686+
/**
687+
* Enhances a `wp <command>` string with an additional `--require` for code coverage collection.
688+
*
689+
* Only applies if `WP_CLI_TEST_COVERAGE` is set.
690+
*
691+
* @param string $cmd Command string.
692+
* @return string Possibly enhanced command string.
693+
*/
694+
public function get_command_with_coverage( $cmd ) {
695+
$with_code_coverage = (string) getenv( 'WP_CLI_TEST_COVERAGE' );
696+
if ( \in_array( $with_code_coverage, [ 'true', '1' ], true ) ) {
697+
return preg_replace( '/(^wp )|( wp )|(\/wp )/', '$1$2$3--require={SRC_DIR}/utils/generate-coverage.php ', $cmd );
698+
}
699+
700+
return $cmd;
701+
}
702+
686703
/**
687704
* Replace standard {VARIABLE_NAME} variables and the special {INVOKE_WP_CLI_WITH_PHP_ARGS-args} and {WP_VERSION-version-latest} variables.
688705
* 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: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,7 @@ public function when_i_launch_in_the_background( $cmd ) {
3535
* @When /^I (run|try) `([^`]+)`$/
3636
*/
3737
public function when_i_run( $mode, $cmd ) {
38-
$with_code_coverage = (string) getenv( 'WP_CLI_TEST_COVERAGE' );
39-
if ( \in_array( $with_code_coverage, [ 'true', '1' ], true ) ) {
40-
$cmd = preg_replace( '/(^wp )|( wp )|(\/wp )/', '$1$2$3--require={SRC_DIR}/utils/generate-coverage.php ', $cmd );
41-
}
42-
38+
$cmd = $this->get_command_with_coverage( $cmd );
4339
$cmd = $this->replace_variables( $cmd );
4440
$this->result = $this->wpcli_tests_invoke_proc( $this->proc( $cmd ), $mode );
4541
list( $this->result->stdout, $this->email_sends ) = $this->wpcli_tests_capture_email_sends( $this->result->stdout );
@@ -49,6 +45,7 @@ public function when_i_run( $mode, $cmd ) {
4945
* @When /^I (run|try) `([^`]+)` from '([^\s]+)'$/
5046
*/
5147
public function when_i_run_from_a_subfolder( $mode, $cmd, $subdir ) {
48+
$cmd = $this->get_command_with_coverage( $cmd );
5249
$cmd = $this->replace_variables( $cmd );
5350
$this->result = $this->wpcli_tests_invoke_proc( $this->proc( $cmd, array(), $subdir ), $mode );
5451
list( $this->result->stdout, $this->email_sends ) = $this->wpcli_tests_capture_email_sends( $this->result->stdout );

0 commit comments

Comments
 (0)