Skip to content

Commit

Permalink
Merge branch 'MDL-75559-39' of https://github.com/andrewnicols/moodle
Browse files Browse the repository at this point in the history
…into MOODLE_39_STABLE
  • Loading branch information
junpataleta committed Sep 29, 2022
2 parents 507f737 + bf1ebf3 commit c8be5a9
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion lib/behat/classes/behat_config_util.php
Expand Up @@ -333,6 +333,34 @@ public function get_components_contexts($component = '') {
return $this->get_component_contexts($component);
}

/**
* Sort the list of components contexts.
*
* This ensures that contexts are sorted consistently.
* Core hooks defined in the behat_hooks class _must_ be defined first.
*
* @param array $contexts
* @return array The sorted context list
*/
protected function sort_component_contexts(array $contexts): array {
// Ensure that the lib_tests are first as they include the root of all tests, hooks, and more.
uksort($contexts, function($a, $b): int {
if ($a === 'behat_hooks') {
return -1;
}
if ($b === 'behat_hooks') {
return 1;
}

if ($a == $b) {
return 0;
}
return ($a < $b) ? -1 : 1;
});

return $contexts;
}

/**
* Behat config file specifing the main context class,
* the required Behat extensions and Moodle test wwwroot.
Expand Down Expand Up @@ -1537,8 +1565,9 @@ protected function get_behat_contexts_for_theme($theme) : array {
}

// Sort the list of contexts.
ksort($contexts);
$contexts = $this->sort_component_contexts($contexts);

// Cache it for subsequent fetches.
$this->themecontexts[$theme] = $contexts;

return $contexts;
Expand Down

0 comments on commit c8be5a9

Please sign in to comment.