From 069cfef5909b8904cc8156c65391da385052b627 Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Tue, 16 Feb 2021 23:39:49 +0000 Subject: [PATCH] MDL-70917 tool_behat: fix profile/replace option comparison. The `isset` call always returned true for the 'replace' option, because even if not specified it receives a non-null value. The `strpos` call now does a strict equality check rather than greater-than-or-equal (which always returns true). --- admin/tool/behat/cli/run.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/admin/tool/behat/cli/run.php b/admin/tool/behat/cli/run.php index 98375c4191221..a5dfa1d8b11df 100644 --- a/admin/tool/behat/cli/run.php +++ b/admin/tool/behat/cli/run.php @@ -45,7 +45,7 @@ array( 'stop-on-failure' => 0, 'verbose' => false, - 'replace' => false, + 'replace' => '', 'help' => false, 'tags' => '', 'profile' => '', @@ -70,7 +70,7 @@ Behat utilities to run behat tests in parallel Usage: - php run.php [--BEHAT_OPTION=\"value\"] [--feature=\"value\"] [--replace] [--fromrun=value --torun=value] [--help] + php run.php [--BEHAT_OPTION=\"value\"] [--feature=\"value\"] [--replace=\"{run}\"] [--fromrun=value --torun=value] [--help] Options: --BEHAT_OPTION Any combination of behat option specified in http://behat.readthedocs.org/en/v2.5/guides/6.cli.html @@ -144,9 +144,10 @@ if ($options['profile']) { $profile = $options['profile']; - // If profile passed is not set, then exit. + // If profile passed is not set, then exit (note we skip if the 'replace' option is found within the 'profile' value). if (!isset($CFG->behat_config[$profile]) && !isset($CFG->behat_profiles[$profile]) && - !(isset($options['replace']) && (strpos($options['profile'], $options['replace']) >= 0 ))) { + !($options['replace'] && (strpos($profile, (string) $options['replace']) !== false))) { + echo "Invalid profile passed: " . $profile . PHP_EOL; exit(1); }