From ddd6a67d2a36791e2f921596f6c34436c4d5752d Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 24 Mar 2015 10:19:30 +0100 Subject: [PATCH] Handle exceptions thrown during hooks when running unit tests --- lib/private/hook.php | 3 +++ tests/lib/testcase.php | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/lib/private/hook.php b/lib/private/hook.php index 00fb4cb0ff5..c4997eeceff 100644 --- a/lib/private/hook.php +++ b/lib/private/hook.php @@ -5,6 +5,8 @@ * slots and emitting signals. */ class OC_Hook{ + public static $thrownExceptions = []; + static private $registered = array(); /** @@ -77,6 +79,7 @@ class OC_Hook{ try { call_user_func( array( $i["class"], $i["name"] ), $params ); } catch (Exception $e){ + self::$thrownExceptions[] = $e; OC_Log::write('hook', 'error while running hook (' . $i["class"] . '::' . $i["name"] . '): '.$e->getMessage(), OC_Log::ERROR); diff --git a/tests/lib/testcase.php b/tests/lib/testcase.php index f4bb8479559..d532a3b01c0 100644 --- a/tests/lib/testcase.php +++ b/tests/lib/testcase.php @@ -40,6 +40,14 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase { }); } + protected function tearDown() { + $hookExceptions = \OC_Hook::$thrownExceptions; + \OC_Hook::$thrownExceptions = []; + if(!empty($hookExceptions)) { + throw $hookExceptions[0]; + } + } + /** * Returns a unique identifier as uniqid() is not reliable sometimes * -- 2.39.5