Commit 1973a7e2 authored by Ankit Agarwal's avatar Ankit Agarwal
Browse files

MDL-42862 behat: update deprecated_message api

Deprecated message api now accepts a $throwexception param that if set to true always throws an exception
parent 2d84748c
......@@ -521,13 +521,14 @@ class behat_deprecated extends behat_base {
*
* @throws Exception
* @param string|array $alternatives Alternative/s to the requested step
* @param bool $throwexception If set to true we always throw exception, irrespective of behat_usedeprecated setting.
* @return void
*/
protected function deprecated_message($alternatives) {
protected function deprecated_message($alternatives, $throwexception = false) {
global $CFG;
// We do nothing if it is enabled.
if (!empty($CFG->behat_usedeprecated)) {
if (!empty($CFG->behat_usedeprecated) && !$throwexception) {
return;
}
......@@ -535,11 +536,23 @@ class behat_deprecated extends behat_base {
$alternatives = array($alternatives);
}
$message = 'Deprecated step, rather than using this step you can:';
// Show an appropriate message based on the throwexception flag.
if ($throwexception) {
$message = 'This step has been removed. Rather than using this step you can:';
} else {
$message = 'Deprecated step, rather than using this step you can:';
}
// Add all alternatives to the message.
foreach ($alternatives as $alternative) {
$message .= PHP_EOL . '- ' . $alternative;
}
$message .= PHP_EOL . '- Set $CFG->behat_usedeprecated in config.php to allow the use of deprecated steps if you don\'t have any other option';
if (!$throwexception) {
$message .= PHP_EOL . '- Set $CFG->behat_usedeprecated in config.php to allow the use of deprecated steps
if you don\'t have any other option';
}
throw new Exception($message);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment