MDL-37919 Let PHPUnit display the content of $a even if the error string is not found
authorDavid Mudrák <david@moodle.com>
Fri, 8 Feb 2013 00:25:31 +0000 (01:25 +0100)
committerDavid Mudrák <david@moodle.com>
Fri, 8 Feb 2013 00:25:31 +0000 (01:25 +0100)
lib/setuplib.php

index 88fd5fd..d3b8a7e 100644 (file)
@@ -137,14 +137,23 @@ class moodle_exception extends Exception {
 
         if (get_string_manager()->string_exists($errorcode, $module)) {
             $message = get_string($errorcode, $module, $a);
+            $haserrorstring = true;
         } else {
             $message = $module . '/' . $errorcode;
+            $haserrorstring = false;
         }
 
         if (defined('PHPUNIT_TEST') and PHPUNIT_TEST and $debuginfo) {
             $message = "$message ($debuginfo)";
         }
 
+        if (!$haserrorstring and defined('PHPUNIT_TEST') and PHPUNIT_TEST) {
+            // Append the contents of $a to $debuginfo so helpful information isn't lost.
+            // This emulates what {@link get_exception_info()} does. Unfortunately that
+            // function is not used by phpunit.
+            $message .= PHP_EOL.'$a contents: '.print_r($a, true);
+        }
+
         parent::__construct($message, 0);
     }
 }