Skip to content

Commit 8e20b27

Browse files
authored
Replace inner variables first (#295)
1 parent 2e886a5 commit 8e20b27

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

features/steps.feature

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ Feature: Make sure "Given", "When", "Then" steps work as expected
7474
Then STDOUT should match /^WP_CLI_PHP_ARGS=-dopen_basedir=.* ?wp cli info/
7575
And STDERR should be empty
7676

77+
When I run `echo {INVOKE_WP_CLI_WITH_PHP_ARGS--dopen_basedir={RUN_DIR}} eval 'echo "{RUN_DIR}";'`
78+
Then STDOUT should match /^WP_CLI_PHP_ARGS=-dopen_basedir=(.*)(.*) ?wp eval echo "\1";/
79+
7780
@require-mysql-or-mariadb
7881
Scenario: SQL related variables
7982
When I run `echo {MYSQL_BINARY}`

src/Context/FeatureContext.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ private static function terminate_proc( $master_pid ): void {
762762

763763
$output = shell_exec( "ps -o ppid,pid,command | grep $master_pid" );
764764

765-
foreach ( explode( PHP_EOL, $output ) as $line ) {
765+
foreach ( explode( PHP_EOL, $output ? $output : '' ) as $line ) {
766766
if ( preg_match( '/^\s*(\d+)\s+(\d+)/', $line, $matches ) ) {
767767
$parent = $matches[1];
768768
$child = $matches[2];
@@ -939,10 +939,10 @@ protected static function bootstrap_feature_context(): void {
939939
* @return string
940940
*/
941941
public function replace_variables( $str ) {
942+
$str = preg_replace_callback( '/\{([A-Z_][A-Z_0-9]*)\}/', [ $this, 'replace_var' ], $str );
942943
if ( false !== strpos( $str, '{INVOKE_WP_CLI_WITH_PHP_ARGS-' ) ) {
943944
$str = $this->replace_invoke_wp_cli_with_php_args( $str );
944945
}
945-
$str = preg_replace_callback( '/\{([A-Z_][A-Z_0-9]*)\}/', [ $this, 'replace_var' ], $str );
946946
if ( false !== strpos( $str, '{WP_VERSION-' ) ) {
947947
$str = $this->replace_wp_versions( $str );
948948
}

0 commit comments

Comments
 (0)