Created
April 12, 2019 09:55
-
-
Save sammarshallou/59a3493e9fdf7f26f8b35f1d11d37228 to your computer and use it in GitHub Desktop.
Moodle scheduled task with mtrace convenient for unit tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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