Skip to content

Commit

Permalink
Merge branch 'MDL-80844_402' of https://github.com/stronk7/moodle int…
Browse files Browse the repository at this point in the history
…o MOODLE_402_STABLE
  • Loading branch information
HuongNV13 committed Feb 22, 2024
2 parents 714906f + 207bac7 commit b9c2b43
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
7 changes: 7 additions & 0 deletions lib/phpunit/classes/database_driver_testcase.php
Expand Up @@ -142,6 +142,13 @@ public function runBare(): void {
try {
parent::runBare();

// Deal with any debugging messages.
$debugerror = phpunit_util::display_debugging_messages(true);
$this->resetDebugging();
if (!empty($debugerror)) {
trigger_error('Unexpected debugging() call detected.' . "\n" . $debugerror, E_USER_NOTICE);
}

} catch (Exception $ex) {
$e = $ex;
} catch (Throwable $ex) {
Expand Down
23 changes: 22 additions & 1 deletion lib/phpunit/classes/util.php
Expand Up @@ -681,8 +681,29 @@ public static function debugging_triggered($message, $level, $from) {
// we need normal debugging outside of tests to find problems in our phpunit integration.
$backtrace = debug_backtrace();

// Only for advanced_testcase, database_driver_testcase (and descendants). Others aren't
// able to manage the debugging sink, so any debugging has to be output normally and, hopefully,
// PHPUnit execution will catch that unexpected output properly.
$sinksupport = false;
foreach ($backtrace as $bt) {
if (isset($bt['object']) and is_object($bt['object'])
if (isset($bt['object']) && is_object($bt['object'])
&& (
$bt['object'] instanceof advanced_testcase ||
$bt['object'] instanceof database_driver_testcase)
) {
$sinksupport = true;
break;
}
}
if (!$sinksupport) {
return false;
}

// Verify that we are inside a PHPUnit test (little bit redundant, because
// we already have checked above that this is an advanced/database_driver
// testcase, but let's keep things double safe for now).
foreach ($backtrace as $bt) {
if (isset($bt['object']) && is_object($bt['object'])
&& $bt['object'] instanceof PHPUnit\Framework\TestCase) {
$debug = new stdClass();
$debug->message = $message;
Expand Down

0 comments on commit b9c2b43

Please sign in to comment.