43
43
/** @var phpunit_message_sink alternative target for moodle messaging */
44
44
protected static $messagesink = null;
46
/** @var phpunit_phpmailer_sink alternative target for phpmailer messaging */
47
protected static $phpmailersink = null;
47
50
* @var array Files to skip when resetting dataroot folder
95
98
// Stop any message redirection.
96
99
phpunit_util::stop_message_redirection();
101
// Stop any message redirection.
102
phpunit_util::stop_phpmailer_redirection();
98
104
// Release memory and indirectly call destroy() methods to release resource handles, etc.
99
105
gc_collect_cycles();
656
666
self::$messagesink->add_message($message);
671
* Start phpmailer redirection.
673
* Note: Do not call directly from tests,
674
* use $sink = $this->redirectEmails() instead.
676
* @return phpunit_phpmailer_sink
678
public static function start_phpmailer_redirection() {
679
if (self::$phpmailersink) {
680
self::stop_phpmailer_redirection();
682
self::$phpmailersink = new phpunit_phpmailer_sink();
683
return self::$phpmailersink;
687
* End phpmailer redirection.
689
* Note: Do not call directly from tests,
690
* use $sink->close() instead.
692
public static function stop_phpmailer_redirection() {
693
self::$phpmailersink = null;
697
* Are messages for phpmailer redirected to some sink?
699
* Note: to be called from moodle_phpmailer.php only!
703
public static function is_redirecting_phpmailer() {
704
return !empty(self::$phpmailersink);
708
* To be called from messagelib.php only!
710
* @param stdClass $message record from message_read table
711
* @return bool true means send message, false means message "sent" to sink.
713
public static function phpmailer_sent($message) {
714
if (self::$phpmailersink) {
715
self::$phpmailersink->add_message($message);