From 8275580db32ac04c2d27f5db2dbe8ce720d8b5f8 Mon Sep 17 00:00:00 2001 From: sam_marshall Date: Thu, 24 Jan 2008 16:58:32 +0000 Subject: [PATCH] MDL-13154 Make it possible to unit test code that calls error() (2.0 only, PHP5 req) --- lib/weblib.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/weblib.php b/lib/weblib.php index c62df2e34a4..6f0c2317c4f 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -5671,6 +5671,13 @@ function error ($message, $link='') { die; } + if (defined('UNITTEST')) { + // Errors in unit test become exceptions, so you can unit test + // code that might call error(). + throw new Exception('error() call: '. + $message.($link!=='' ? ' ['.$link.']' : '')); + } + if (! defined('HEADER_PRINTED')) { //header not yet printed @header('HTTP/1.0 404 Not Found');