diff --git a/lib/behat/lib.php b/lib/behat/lib.php index ff53aab8318..313cd082005 100644 --- a/lib/behat/lib.php +++ b/lib/behat/lib.php @@ -461,26 +461,40 @@ function behat_get_run_process() { } } } else if (defined('BEHAT_TEST') || defined('BEHAT_UTIL')) { - if ($match = preg_filter('#--run=(.+)#', '$1', $argv)) { - $behatrunprocess = reset($match); - } else if ($k = array_search('--config', $argv)) { - $behatconfig = str_replace("\\", "/", $argv[$k + 1]); - // Try get it from config if present. - if (!empty($CFG->behat_parallel_run)) { - foreach ($CFG->behat_parallel_run as $run => $parallelconfig) { - if (!empty($parallelconfig['behat_dataroot']) && - $parallelconfig['behat_dataroot'] . '/behat/behat.yml' == $behatconfig) { + $behatconfig = ''; - $behatrunprocess = $run + 1; // We start process from 1. - break; + if ($match = preg_filter('#--run=(.+)#', '$1', $argv)) { + // Try to guess the run from the existence of the --run arg. + $behatrunprocess = reset($match); + + } else { + // Try to guess the run from the existence of the --config arg. Note there are 2 alternatives below. + if ($k = array_search('--config', $argv)) { + // Alternative 1: --config /path/to/config.yml => (next arg, pick it). + $behatconfig = str_replace("\\", "/", $argv[$k + 1]); + + } else if ($config = preg_filter('#^(?:--config[ =]*)(.+)$#', '$1', $argv)) { + // Alternative 2: --config=/path/to/config.yml => (same arg, just get the path part). + $behatconfig = str_replace("\\", "/", reset($config)); + } + + // Try get it from config if present. + if ($behatconfig) { + if (!empty($CFG->behat_parallel_run)) { + foreach ($CFG->behat_parallel_run as $run => $parallelconfig) { + if (!empty($parallelconfig['behat_dataroot']) && + $parallelconfig['behat_dataroot'] . '/behat/behat.yml' == $behatconfig) { + $behatrunprocess = $run + 1; // We start process from 1. + break; + } } } - } - // Check if default behat datroot increment was done. - if (empty($behatrunprocess)) { - $behatdataroot = str_replace("\\", "/", $CFG->behat_dataroot . '/' . BEHAT_PARALLEL_SITE_NAME); - $behatrunprocess = preg_filter("#^{$behatdataroot}" . "(.+?)[/|\\\]behat[/|\\\]behat\.yml#", '$1', - $behatconfig); + // Check if default behat dataroot increment was done. + if (empty($behatrunprocess)) { + $behatdataroot = str_replace("\\", "/", $CFG->behat_dataroot . '/' . BEHAT_PARALLEL_SITE_NAME); + $behatrunprocess = preg_filter("#^{$behatdataroot}" . "(.+?)[/|\\\]behat[/|\\\]behat\.yml#", '$1', + $behatconfig); + } } } }