Merge branch 'wip-mdl-51266' of https://github.com/rajeshtaneja/moodle
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Wed, 30 Sep 2015 18:34:33 +0000 (20:34 +0200)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Wed, 30 Sep 2015 18:34:33 +0000 (20:34 +0200)
availability/tests/info_test.php
lib/phpunit/classes/advanced_testcase.php
lib/phpunit/classes/database_driver_testcase.php
lib/phpunit/classes/util.php
lib/phpunit/tests/advanced_test.php
lib/tests/messagelib_test.php
mod/forum/tests/subscriptions_test.php

index 13091ec..1477978 100644 (file)
@@ -35,7 +35,7 @@ use core_availability\info_section;
  * @copyright 2014 The Open University
  * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class info_testcase extends \advanced_testcase {
+class info_testcase extends advanced_testcase {
     public function setUp() {
         // Load the mock condition so that it can be used.
         require_once(__DIR__ . '/fixtures/mock_condition.php');
@@ -87,8 +87,8 @@ class info_testcase extends \advanced_testcase {
         // Check invalid one.
         $info = new info_module($cm3);
         $this->assertFalse($info->is_available($information));
-        $debugging = phpunit_util::get_debugging_messages();
-        phpunit_util::reset_debugging();
+        $debugging = $this->getDebuggingMessages();
+        $this->resetDebugging();
         $this->assertEquals(1, count($debugging));
         $this->assertContains('Invalid availability', $debugging[0]->message);
 
@@ -141,8 +141,8 @@ class info_testcase extends \advanced_testcase {
         // Check invalid one.
         $info = new info_section($sections[3]);
         $this->assertFalse($info->is_available($information));
-        $debugging = phpunit_util::get_debugging_messages();
-        phpunit_util::reset_debugging();
+        $debugging = $this->getDebuggingMessages();
+        $this->resetDebugging();
         $this->assertEquals(1, count($debugging));
         $this->assertContains('Invalid availability', $debugging[0]->message);
 
index 1acdba7..8995f76 100644 (file)
@@ -83,14 +83,14 @@ abstract class advanced_testcase extends base_testcase {
 
             // Deal with any debugging messages.
             $debugerror = phpunit_util::display_debugging_messages();
-            phpunit_util::reset_debugging();
+            $this->resetDebugging();
             if ($debugerror) {
                 trigger_error('Unenxpected debugging() call detected.', E_USER_NOTICE);
             }
 
         } catch (Exception $e) {
             // cleanup after failed expectation
-            phpunit_util::reset_all_data();
+            self::resetAllData();
             throw $e;
         }
 
@@ -104,7 +104,7 @@ abstract class advanced_testcase extends base_testcase {
                 phpunit_util::reset_all_database_sequences();
                 phpunit_util::$lastdbwrites = $DB->perf_get_writes(); // no db reset necessary
             }
-            phpunit_util::reset_all_data(null);
+            self::resetAllData(null);
 
         } else if ($this->resetAfterTest === false) {
             if ($this->testdbtransaction) {
@@ -118,16 +118,16 @@ abstract class advanced_testcase extends base_testcase {
                 try {
                     $this->testdbtransaction->allow_commit();
                 } catch (dml_transaction_exception $e) {
-                    phpunit_util::reset_all_data();
+                    self::resetAllData();
                     throw new coding_exception('Invalid transaction state detected in test '.$this->getName());
                 }
             }
-            phpunit_util::reset_all_data(true);
+            self::resetAllData(true);
         }
 
         // make sure test did not forget to close transaction
         if ($DB->is_transaction_started()) {
-            phpunit_util::reset_all_data();
+            self::resetAllData();
             if ($this->getStatus() == PHPUnit_Runner_BaseTestRunner::STATUS_PASSED
                 or $this->getStatus() == PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED
                 or $this->getStatus() == PHPUnit_Runner_BaseTestRunner::STATUS_INCOMPLETE) {
@@ -272,7 +272,7 @@ abstract class advanced_testcase extends base_testcase {
      * @param string $message
      */
     public function assertDebuggingCalled($debugmessage = null, $debuglevel = null, $message = '') {
-        $debugging = phpunit_util::get_debugging_messages();
+        $debugging = $this->getDebuggingMessages();
         $count = count($debugging);
 
         if ($count == 0) {
@@ -297,7 +297,7 @@ abstract class advanced_testcase extends base_testcase {
             $this->assertSame($debuglevel, $debug->level, $message);
         }
 
-        phpunit_util::reset_debugging();
+        $this->resetDebugging();
     }
 
     /**
@@ -305,7 +305,7 @@ abstract class advanced_testcase extends base_testcase {
      * @param string $message
      */
     public function assertDebuggingNotCalled($message = '') {
-        $debugging = phpunit_util::get_debugging_messages();
+        $debugging = $this->getDebuggingMessages();
         $count = count($debugging);
 
         if ($message === '') {
@@ -446,16 +446,21 @@ abstract class advanced_testcase extends base_testcase {
      * @return void
      */
     public static function tearDownAfterClass() {
-        phpunit_util::reset_all_data();
+        self::resetAllData();
     }
 
+
     /**
      * Reset all database tables, restore global state and clear caches and optionally purge dataroot dir.
-     * @static
+     *
+     * @param bool $detectchanges
+     *      true  - changes in global state and database are reported as errors
+     *      false - no errors reported
+     *      null  - only critical problems are reported as errors
      * @return void
      */
-    public static function resetAllData() {
-        phpunit_util::reset_all_data();
+    public static function resetAllData($detectchanges = false) {
+        phpunit_util::reset_all_data($detectchanges);
     }
 
     /**
index f186abc..eaacaa2 100644 (file)
@@ -45,7 +45,7 @@
  * @copyright  2012 Petr Skoda {@link http://skodak.org}
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-abstract class database_driver_testcase extends PHPUnit_Framework_TestCase {
+abstract class database_driver_testcase extends base_testcase {
     /** @var moodle_database connection to extra database */
     private static $extradb = null;
 
@@ -176,7 +176,7 @@ abstract class database_driver_testcase extends PHPUnit_Framework_TestCase {
      * @param string $message
      */
     public function assertDebuggingCalled($debugmessage = null, $debuglevel = null, $message = '') {
-        $debugging = phpunit_util::get_debugging_messages();
+        $debugging = $this->getDebuggingMessages();
         $count = count($debugging);
 
         if ($count == 0) {
@@ -201,7 +201,7 @@ abstract class database_driver_testcase extends PHPUnit_Framework_TestCase {
             $this->assertSame($debuglevel, $debug->level, $message);
         }
 
-        phpunit_util::reset_debugging();
+        $this->resetDebugging();
     }
 
     /**
@@ -209,7 +209,7 @@ abstract class database_driver_testcase extends PHPUnit_Framework_TestCase {
      * @param string $message
      */
     public function assertDebuggingNotCalled($message = '') {
-        $debugging = phpunit_util::get_debugging_messages();
+        $debugging = $this->getDebuggingMessages();
         $count = count($debugging);
 
         if ($message === '') {
index 8114893..cc1c64a 100644 (file)
@@ -104,16 +104,16 @@ class phpunit_util extends testing_util {
         global $DB, $CFG, $USER, $SITE, $COURSE, $PAGE, $OUTPUT, $SESSION;
 
         // Stop any message redirection.
-        phpunit_util::stop_message_redirection();
+        self::stop_message_redirection();
 
         // Stop any message redirection.
-        phpunit_util::stop_event_redirection();
+        self::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();
+        self::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.
@@ -320,7 +320,7 @@ class phpunit_util extends testing_util {
         self::$globals['DB'] = $DB;
 
         // refresh data in all tables, clear caches, etc.
-        phpunit_util::reset_all_data();
+        self::reset_all_data();
     }
 
     /**
@@ -427,7 +427,7 @@ class phpunit_util extends testing_util {
         }
 
         if ($DB->get_tables()) {
-            list($errorcode, $message) = phpunit_util::testing_ready_problem();
+            list($errorcode, $message) = self::testing_ready_problem();
             if ($errorcode) {
                 phpunit_bootstrap_error(PHPUNIT_EXITCODE_REINSTALL, 'Database tables already present, Moodle PHPUnit test environment can not be initialised');
             } else {
index 1bd4d58..cc2d8e8 100644 (file)
@@ -198,13 +198,13 @@ class core_phpunit_advanced_testcase extends advanced_testcase {
         global $DB, $CFG, $COURSE, $SITE, $USER;
 
         $this->preventResetByRollback();
-        phpunit_util::reset_all_data(true);
+        self::resetAllData(true);
 
         // Database change.
         $this->assertEquals(1, $DB->get_field('user', 'confirmed', array('id'=>2)));
         $DB->set_field('user', 'confirmed', 0, array('id'=>2));
         try {
-            phpunit_util::reset_all_data(true);
+            self::resetAllData(true);
         } catch (Exception $e) {
             $this->assertInstanceOf('PHPUnit_Framework_Error_Warning', $e);
         }
@@ -215,7 +215,7 @@ class core_phpunit_advanced_testcase extends advanced_testcase {
         unset($CFG->admin);
         $CFG->rolesactive = 0;
         try {
-            phpunit_util::reset_all_data(true);
+            self::resetAllData(true);
         } catch (Exception $e) {
             $this->assertInstanceOf('PHPUnit_Framework_Error_Warning', $e);
             $this->assertContains('xx', $e->getMessage());
@@ -228,28 +228,28 @@ class core_phpunit_advanced_testcase extends advanced_testcase {
 
         // _GET change.
         $_GET['__somethingthatwillnotnormallybepresent__'] = 'yy';
-        phpunit_util::reset_all_data(true);
+        self::resetAllData(true);
 
         $this->assertEquals(array(), $_GET);
 
         // _POST change.
         $_POST['__somethingthatwillnotnormallybepresent2__'] = 'yy';
-        phpunit_util::reset_all_data(true);
+        self::resetAllData(true);
         $this->assertEquals(array(), $_POST);
 
         // _FILES change.
         $_FILES['__somethingthatwillnotnormallybepresent3__'] = 'yy';
-        phpunit_util::reset_all_data(true);
+        self::resetAllData(true);
         $this->assertEquals(array(), $_FILES);
 
         // _REQUEST change.
         $_REQUEST['__somethingthatwillnotnormallybepresent4__'] = 'yy';
-        phpunit_util::reset_all_data(true);
+        self::resetAllData(true);
         $this->assertEquals(array(), $_REQUEST);
 
         // Silent changes.
         $_SERVER['xx'] = 'yy';
-        phpunit_util::reset_all_data(true);
+        self::resetAllData(true);
         $this->assertFalse(isset($_SERVER['xx']));
 
         // COURSE change.
@@ -257,7 +257,7 @@ class core_phpunit_advanced_testcase extends advanced_testcase {
         $COURSE = new stdClass();
         $COURSE->id = 7;
         try {
-            phpunit_util::reset_all_data(true);
+            self::resetAllData(true);
         } catch (Exception $e) {
             $this->assertInstanceOf('PHPUnit_Framework_Error_Warning', $e);
             $this->assertEquals(1, $SITE->id);
@@ -268,7 +268,7 @@ class core_phpunit_advanced_testcase extends advanced_testcase {
         // USER change.
         $this->setUser(2);
         try {
-            phpunit_util::reset_all_data(true);
+            self::resetAllData(true);
         } catch (Exception $e) {
             $this->assertInstanceOf('PHPUnit_Framework_Error_Warning', $e);
             $this->assertEquals(0, $USER->id);
@@ -601,7 +601,7 @@ class core_phpunit_advanced_testcase extends advanced_testcase {
 
         $this->resetAfterTest();
 
-        // If this fails \phpunit_util::reset_all_data() must be updated.
+        // If this fails self::resetAllData(); must be updated.
         $this->assertSame('en_AU.UTF-8', get_string('locale', 'langconfig'));
         $this->assertSame('English_Australia.1252', get_string('localewin', 'langconfig'));
 
@@ -614,7 +614,7 @@ class core_phpunit_advanced_testcase extends advanced_testcase {
         }
 
         try {
-            phpunit_util::reset_all_data(true);
+            self::resetAllData(true);
         } catch (Exception $e) {
             $this->assertInstanceOf('PHPUnit_Framework_Error_Warning', $e);
         }
@@ -633,7 +633,7 @@ class core_phpunit_advanced_testcase extends advanced_testcase {
             setlocale(LC_TIME, 'en_US.UTF-8');
         }
 
-        phpunit_util::reset_all_data(false);
+        self::resetAllData(false);
 
         if ($CFG->ostype === 'WINDOWS') {
             $this->assertSame('English_Australia.1252', setlocale(LC_TIME, 0));
index 9d86d0c..ecc3dc5 100644 (file)
@@ -51,7 +51,6 @@ class core_messagelib_testcase extends advanced_testcase {
 
         // Check message is not sent.
         $sink = $this->redirectEmails();
-        $this->assertTrue(phpunit_util::is_redirecting_phpmailer());
         message_send($message);
         $emails = $sink->get_messages();
         $this->assertEmpty($emails);
@@ -62,7 +61,6 @@ class core_messagelib_testcase extends advanced_testcase {
         $this->assertTrue($preferences->$disableprovidersetting == 0);
 
         $sink = $this->redirectEmails();
-        $this->assertTrue(phpunit_util::is_redirecting_phpmailer());
         message_send($message);
         $emails = $sink->get_messages();
         $email = reset($emails);
@@ -853,7 +851,6 @@ class core_messagelib_testcase extends advanced_testcase {
 
         // Make sure we are redirecting emails.
         $sink = $this->redirectEmails();
-        $this->assertTrue(phpunit_util::is_redirecting_phpmailer());
         message_send($message);
 
         // Get the email that we just sent.
index 8f57abc..8b2d40b 100644 (file)
@@ -222,8 +222,8 @@ class mod_forum_subscriptions_testcase extends advanced_testcase {
 
         // Check the deprecated function too.
         $this->assertFalse(forum_is_subscribed($author->id, $forum));
-        $this->assertEquals(1, count(phpunit_util::get_debugging_messages()));
-        phpunit_util::reset_debugging();
+        $this->assertEquals(1, count($this->getDebuggingMessages()));
+        $this->resetDebugging();
 
         // Check that the user is unsubscribed from the discussion too.
         $this->assertFalse(\mod_forum\subscriptions::is_subscribed($author->id, $forum, $discussion->id));
@@ -267,8 +267,8 @@ class mod_forum_subscriptions_testcase extends advanced_testcase {
         // Subscribing to the forum should create a record in the subscriptions table, but not the forum discussion
         // subscriptions table.
         forum_subscribe($author->id, $forum->id);
-        $this->assertEquals(1, count(phpunit_util::get_debugging_messages()));
-        phpunit_util::reset_debugging();
+        $this->assertEquals(1, count($this->getDebuggingMessages()));
+        $this->resetDebugging();
         $this->assertEquals(1, $DB->count_records('forum_subscriptions', array(
             'userid'        => $author->id,
             'forum'         => $forum->id,
@@ -281,8 +281,8 @@ class mod_forum_subscriptions_testcase extends advanced_testcase {
         // Unsubscribing should remove the record from the forum subscriptions table, and not modify the forum
         // discussion subscriptions table.
         forum_unsubscribe($author->id, $forum->id);
-        $this->assertEquals(1, count(phpunit_util::get_debugging_messages()));
-        phpunit_util::reset_debugging();
+        $this->assertEquals(1, count($this->getDebuggingMessages()));
+        $this->resetDebugging();
         $this->assertEquals(0, $DB->count_records('forum_subscriptions', array(
             'userid'        => $author->id,
             'forum'         => $forum->id,
@@ -441,8 +441,8 @@ class mod_forum_subscriptions_testcase extends advanced_testcase {
 
         // Check the deprecated function too.
         $this->assertFalse(forum_is_subscribed($author->id, $forum));
-        $this->assertEquals(1, count(phpunit_util::get_debugging_messages()));
-        phpunit_util::reset_debugging();
+        $this->assertEquals(1, count($this->getDebuggingMessages()));
+        $this->resetDebugging();
 
         // Post a discussion to the forum.
         list($discussion, $post) = $this->helper_post_to_forum($forum, $author);
@@ -478,8 +478,8 @@ class mod_forum_subscriptions_testcase extends advanced_testcase {
 
         // Check the deprecated function too.
         $this->assertTrue(forum_is_subscribed($author->id, $forum));
-        $this->assertEquals(1, count(phpunit_util::get_debugging_messages()));
-        phpunit_util::reset_debugging();
+        $this->assertEquals(1, count($this->getDebuggingMessages()));
+        $this->resetDebugging();
 
         // Post a discussion to the forum.
         list($discussion, $post) = $this->helper_post_to_forum($forum, $author);
@@ -508,8 +508,8 @@ class mod_forum_subscriptions_testcase extends advanced_testcase {
 
         // Check the deprecated function too.
         $this->assertFalse(forum_is_subscribed($author->id, $forum));
-        $this->assertEquals(1, count(phpunit_util::get_debugging_messages()));
-        phpunit_util::reset_debugging();
+        $this->assertEquals(1, count($this->getDebuggingMessages()));
+        $this->resetDebugging();
 
         // Post a discussion to the forum.
         list($discussion, $post) = $this->helper_post_to_forum($forum, $author);
@@ -525,8 +525,8 @@ class mod_forum_subscriptions_testcase extends advanced_testcase {
 
         // Check the deprecated function too.
         $this->assertFalse(forum_is_subscribed($author->id, $forum));
-        $this->assertEquals(1, count(phpunit_util::get_debugging_messages()));
-        phpunit_util::reset_debugging();
+        $this->assertEquals(1, count($this->getDebuggingMessages()));
+        $this->resetDebugging();
 
         // But subscribed to the discussion.
         $this->assertTrue(\mod_forum\subscriptions::is_subscribed($author->id, $forum, $discussion->id));
@@ -555,8 +555,8 @@ class mod_forum_subscriptions_testcase extends advanced_testcase {
 
         // Check the deprecated function too.
         $this->assertTrue(forum_is_subscribed($author->id, $forum));
-        $this->assertEquals(1, count(phpunit_util::get_debugging_messages()));
-        phpunit_util::reset_debugging();
+        $this->assertEquals(1, count($this->getDebuggingMessages()));
+        $this->resetDebugging();
 
         // Post a discussion to the forum.
         list($discussion, $post) = $this->helper_post_to_forum($forum, $author);
@@ -569,8 +569,8 @@ class mod_forum_subscriptions_testcase extends advanced_testcase {
 
         // Check the deprecated function too.
         $this->assertTrue(forum_is_subscribed($author->id, $forum));
-        $this->assertEquals(1, count(phpunit_util::get_debugging_messages()));
-        phpunit_util::reset_debugging();
+        $this->assertEquals(1, count($this->getDebuggingMessages()));
+        $this->resetDebugging();
 
         // But unsubscribed from the discussion.
         $this->assertFalse(\mod_forum\subscriptions::is_subscribed($author->id, $forum, $discussion->id));
@@ -601,8 +601,8 @@ class mod_forum_subscriptions_testcase extends advanced_testcase {
 
         // Check the deprecated function too.
         $this->assertTrue(forum_is_subscribed($author->id, $forum));
-        $this->assertEquals(1, count(phpunit_util::get_debugging_messages()));
-        phpunit_util::reset_debugging();
+        $this->assertEquals(1, count($this->getDebuggingMessages()));
+        $this->resetDebugging();
 
         // Post a discussion to the forum.
         list($discussion, $post) = $this->helper_post_to_forum($forum, $author);
@@ -631,8 +631,8 @@ class mod_forum_subscriptions_testcase extends advanced_testcase {
 
         // Check the deprecated function too.
         $this->assertTrue(forum_is_subscribed($author->id, $forum));
-        $this->assertEquals(1, count(phpunit_util::get_debugging_messages()));
-        phpunit_util::reset_debugging();
+        $this->assertEquals(1, count($this->getDebuggingMessages()));
+        $this->resetDebugging();
 
         // An attempt to unsubscribe again should result in a falsey return to indicate that no change was made.
         $this->assertFalse(\mod_forum\subscriptions::unsubscribe_user_from_discussion($author->id, $discussion));
@@ -670,13 +670,13 @@ class mod_forum_subscriptions_testcase extends advanced_testcase {
 
         // Check the deprecated function too.
         $this->assertTrue(forum_is_subscribed($author->id, $forum));
-        $this->assertEquals(1, count(phpunit_util::get_debugging_messages()));
-        phpunit_util::reset_debugging();
+        $this->assertEquals(1, count($this->getDebuggingMessages()));
+        $this->resetDebugging();
 
         // Check the deprecated function too.
         $this->assertTrue(forum_is_subscribed($author->id, $forum));
-        $this->assertEquals(1, count(phpunit_util::get_debugging_messages()));
-        phpunit_util::reset_debugging();
+        $this->assertEquals(1, count($this->getDebuggingMessages()));
+        $this->resetDebugging();
 
         // And is subscribed to the discussion again.
         $this->assertTrue(\mod_forum\subscriptions::is_subscribed($author->id, $forum, $discussion->id));
@@ -701,8 +701,8 @@ class mod_forum_subscriptions_testcase extends advanced_testcase {
 
         // Check the deprecated function too.
         $this->assertTrue(forum_is_subscribed($author->id, $forum));
-        $this->assertEquals(1, count(phpunit_util::get_debugging_messages()));
-        phpunit_util::reset_debugging();
+        $this->assertEquals(1, count($this->getDebuggingMessages()));
+        $this->resetDebugging();
 
         // But unsubscribed from the discussion.
         $this->assertFalse(\mod_forum\subscriptions::is_subscribed($author->id, $forum, $discussion->id));
@@ -749,8 +749,8 @@ class mod_forum_subscriptions_testcase extends advanced_testcase {
 
         // Check the deprecated function too.
         $this->assertTrue(forum_is_subscribed($author->id, $forum));
-        $this->assertEquals(1, count(phpunit_util::get_debugging_messages()));
-        phpunit_util::reset_debugging();
+        $this->assertEquals(1, count($this->getDebuggingMessages()));
+        $this->resetDebugging();
 
         // But unsubscribed from the discussion.
         $this->assertFalse(\mod_forum\subscriptions::is_subscribed($author->id, $forum, $discussion->id));
@@ -808,8 +808,8 @@ class mod_forum_subscriptions_testcase extends advanced_testcase {
 
         // Check the deprecated function too.
         $this->assertFalse(forum_is_subscribed($author->id, $forum));
-        $this->assertEquals(1, count(phpunit_util::get_debugging_messages()));
-        phpunit_util::reset_debugging();
+        $this->assertEquals(1, count($this->getDebuggingMessages()));
+        $this->resetDebugging();
 
         // Post a discussion to the forum.
         list($discussion, $post) = $this->helper_post_to_forum($forum, $author);
@@ -828,8 +828,8 @@ class mod_forum_subscriptions_testcase extends advanced_testcase {
 
         // Check the deprecated function too.
         $this->assertFalse(forum_is_subscribed($author->id, $forum));
-        $this->assertEquals(1, count(phpunit_util::get_debugging_messages()));
-        phpunit_util::reset_debugging();
+        $this->assertEquals(1, count($this->getDebuggingMessages()));
+        $this->resetDebugging();
 
         // But subscribed to the discussion.
         $this->assertTrue(\mod_forum\subscriptions::is_subscribed($author->id, $forum, $discussion->id));
@@ -848,8 +848,8 @@ class mod_forum_subscriptions_testcase extends advanced_testcase {
 
         // Check the deprecated function too.
         $this->assertFalse(forum_is_subscribed($author->id, $forum));
-        $this->assertEquals(1, count(phpunit_util::get_debugging_messages()));
-        phpunit_util::reset_debugging();
+        $this->assertEquals(1, count($this->getDebuggingMessages()));
+        $this->resetDebugging();
 
         // And is unsubscribed from the discussion again.
         $this->assertFalse(\mod_forum\subscriptions::is_subscribed($author->id, $forum, $discussion->id));
@@ -868,8 +868,8 @@ class mod_forum_subscriptions_testcase extends advanced_testcase {
 
         // Check the deprecated function too.
         $this->assertFalse(forum_is_subscribed($author->id, $forum));
-        $this->assertEquals(1, count(phpunit_util::get_debugging_messages()));
-        phpunit_util::reset_debugging();
+        $this->assertEquals(1, count($this->getDebuggingMessages()));
+        $this->resetDebugging();
 
         // And is subscribed to the discussion again.
         $this->assertTrue(\mod_forum\subscriptions::is_subscribed($author->id, $forum, $discussion->id));
@@ -888,8 +888,8 @@ class mod_forum_subscriptions_testcase extends advanced_testcase {
 
         // Check the deprecated function too.
         $this->assertFalse(forum_is_subscribed($author->id, $forum));
-        $this->assertEquals(1, count(phpunit_util::get_debugging_messages()));
-        phpunit_util::reset_debugging();
+        $this->assertEquals(1, count($this->getDebuggingMessages()));
+        $this->resetDebugging();
 
         // But unsubscribed from the discussion.
         $this->assertFalse(\mod_forum\subscriptions::is_subscribed($author->id, $forum, $discussion->id));
@@ -920,25 +920,25 @@ class mod_forum_subscriptions_testcase extends advanced_testcase {
 
         // Check that the user is currently unsubscribed to the forum.
         $this->assertFalse(forum_is_subscribed($author->id, $forum->id));
-        $this->assertEquals(1, count(phpunit_util::get_debugging_messages()));
-        phpunit_util::reset_debugging();
+        $this->assertEquals(1, count($this->getDebuggingMessages()));
+        $this->resetDebugging();
 
         // It should match the result of when it's called with the forum object.
         $this->assertFalse(forum_is_subscribed($author->id, $forum));
-        $this->assertEquals(1, count(phpunit_util::get_debugging_messages()));
-        phpunit_util::reset_debugging();
+        $this->assertEquals(1, count($this->getDebuggingMessages()));
+        $this->resetDebugging();
 
         // And when the user is subscribed, we should also get the correct result.
         \mod_forum\subscriptions::subscribe_user($author->id, $forum);
 
         $this->assertTrue(forum_is_subscribed($author->id, $forum->id));
-        $this->assertEquals(1, count(phpunit_util::get_debugging_messages()));
-        phpunit_util::reset_debugging();
+        $this->assertEquals(1, count($this->getDebuggingMessages()));
+        $this->resetDebugging();
 
         // It should match the result of when it's called with the forum object.
         $this->assertTrue(forum_is_subscribed($author->id, $forum));
-        $this->assertEquals(1, count(phpunit_util::get_debugging_messages()));
-        phpunit_util::reset_debugging();
+        $this->assertEquals(1, count($this->getDebuggingMessages()));
+        $this->resetDebugging();
     }
 
     /**