Skip to content

Instantly share code, notes, and snippets.

@sammarshallou
Created April 12, 2019 09:55
Show Gist options
  • Save sammarshallou/59a3493e9fdf7f26f8b35f1d11d37228 to your computer and use it in GitHub Desktop.
Save sammarshallou/59a3493e9fdf7f26f8b35f1d11d37228 to your computer and use it in GitHub Desktop.
Moodle scheduled task with mtrace convenient for unit tests
class move_to_recycle_bin extends scheduled_task {
/** @var string For unit testing only */
protected $testmtracebuffer = '';
/**
* Outputs a line of text to the cron log.
*
* @param string $line Line of text
*/
public function mtrace($line) {
if (PHPUNIT_TEST) {
$this->testmtracebuffer .= $line . "\n";
} else {
mtrace($line);
}
}
/**
* For unit testing only. Get the mtraced output, and clear it.
*
* @return string Mtraced output (since last call)
*/
public function get_and_clear_test_mtrace_buffer() {
if (!PHPUNIT_TEST) {
throw new \coding_exception('Cannot be called except in unit test');
}
$result = $this->testmtracebuffer;
$this->testmtracebuffer = '';
return $result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment