From 995821591d09f9aca16ec18da1cdb0babc973a0d Mon Sep 17 00:00:00 2001 From: skodak Date: Thu, 4 Dec 2008 23:19:37 +0000 Subject: [PATCH] MDL-17534 simpletest: temporary fix for exception problems --- lib/simpletestlib/errors.php | 13 ++++++++++++- lib/simpletestlib/invoker.php | 13 ++++++++++++- lib/simpletestlib/readme_moodle.txt | 1 + 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/lib/simpletestlib/errors.php b/lib/simpletestlib/errors.php index 14c4d06266..204f0b1e05 100644 --- a/lib/simpletestlib/errors.php +++ b/lib/simpletestlib/errors.php @@ -46,9 +46,20 @@ class SimpleErrorTrappingInvoker extends SimpleInvokerDecorator { function invoke($method) { $queue = &$this->_createErrorQueue(); set_error_handler('SimpleTestErrorHandler'); - parent::invoke($method); + //moodle hack start + // note: this breaks PHP4 compatibility! + $rethrow = null; + try { + parent::invoke($method); + } catch (Exception $e) { + $rethrow = $e; + } restore_error_handler(); $queue->tally(); + if ($rethrow) { + throw $rethrow; + } + //moodle hack end } /** diff --git a/lib/simpletestlib/invoker.php b/lib/simpletestlib/invoker.php index 49b393c0fb..b9f81ff5ab 100644 --- a/lib/simpletestlib/invoker.php +++ b/lib/simpletestlib/invoker.php @@ -65,8 +65,19 @@ class SimpleInvoker { */ function invoke($method) { $this->_test_case->setUp(); - $this->_test_case->$method(); + // moodle hack start + // note: this breaks PHP4 compatibility! + $rethrow = null; + try { + $this->_test_case->$method(); + } catch (Exception $e) { + $rethrow = $e; + } $this->_test_case->tearDown(); + if ($rethrow) { + throw $rethrow; + } + // moodle hack end } /** diff --git a/lib/simpletestlib/readme_moodle.txt b/lib/simpletestlib/readme_moodle.txt index d2a28b4e3b..e0015a8aa5 100644 --- a/lib/simpletestlib/readme_moodle.txt +++ b/lib/simpletestlib/readme_moodle.txt @@ -2,6 +2,7 @@ Description of Simpletest 1.0.1beta library import into Moodle Changes: * test_case.php - added our global $CFG before include() MDL-10064 + * fixed exception support (MDL-17534) - try/catch in invoker.php and errors.php skodak -- 2.39.5