]> source.dussan.org Git - nextcloud-server.git/commitdiff
Handle exceptions thrown during hooks when running unit tests
authorRobin Appelman <icewind@owncloud.com>
Tue, 24 Mar 2015 09:19:30 +0000 (10:19 +0100)
committerRobin Appelman <icewind@owncloud.com>
Thu, 26 Mar 2015 16:07:02 +0000 (17:07 +0100)
lib/private/hook.php
tests/lib/testcase.php

index 00fb4cb0ff5d87b8a490753c4255c2ef701ee61f..c4997eeceffb3967d74bdf16144e26bce85b51e8 100644 (file)
@@ -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);
index f4bb847955967231f3df3341394e7c9737c77d7e..d532a3b01c0944be2795c0e5d159ea28f723ca76 100644 (file)
@@ -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
         *