Handle exceptions thrown during hooks when running unit tests

This commit is contained in:
Robin Appelman 2015-03-24 10:19:30 +01:00
parent 3ed6ed3c36
commit ddd6a67d2a
2 changed files with 11 additions and 0 deletions

View 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);

View 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
*