diff --git a/lib/phpunit/bootstrap.php b/lib/phpunit/bootstrap.php index 4d573df0b00..add63122157 100644 --- a/lib/phpunit/bootstrap.php +++ b/lib/phpunit/bootstrap.php @@ -209,8 +209,6 @@ error_reporting($CFG->debug); ini_set('display_errors', '1'); ini_set('log_errors', '1'); -$CFG->noemailever = true; // better not mail anybody from tests, override temporarily if necessary - // some ugly hacks $CFG->themerev = 1; $CFG->jsrev = 1; diff --git a/lib/phpunit/classes/util.php b/lib/phpunit/classes/util.php index c5e408b3ae7..1c1928e0ff7 100644 --- a/lib/phpunit/classes/util.php +++ b/lib/phpunit/classes/util.php @@ -106,12 +106,15 @@ class phpunit_util extends testing_util { // Stop any message redirection. phpunit_util::stop_message_redirection(); - // Stop any message redirection. - phpunit_util::stop_phpmailer_redirection(); - // Stop any message redirection. phpunit_util::stop_event_redirection(); + // Start a new email redirection. + // This will clear any existing phpmailer redirection. + // We redirect all phpmailer output to this message sink which is + // called instead of phpmailer actually sending the message. + phpunit_util::start_phpmailer_redirection(); + // We used to call gc_collect_cycles here to ensure desctructors were called between tests. // This accounted for 25% of the total time running phpunit - so we removed it. @@ -678,9 +681,11 @@ class phpunit_util extends testing_util { */ public static function start_phpmailer_redirection() { if (self::$phpmailersink) { - self::stop_phpmailer_redirection(); + // If an existing mailer sink is active, just clear it. + self::$phpmailersink->clear(); + } else { + self::$phpmailersink = new phpunit_phpmailer_sink(); } - self::$phpmailersink = new phpunit_phpmailer_sink(); return self::$phpmailersink; } diff --git a/lib/upgrade.txt b/lib/upgrade.txt index 79e608d706b..7ea8021503a 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -4,6 +4,9 @@ information provided here is intended especially for developers. === 2.9 === * \core\event\course_viewed 'other' argument renamed from coursesectionid to coursesectionnumber as it contains the section number. +* PHPUnit: PHPMailer Sink is now started for all tests and is setup within the phpunit wrapper for advanced tests. + Catching debugging messages when sending mail will no longer work. Use $sink = $this->redirectEmails(); and then check + the message in the sink instead. === 2.8 ===