Handle exceptions thrown during hooks when running unit tests

remotes/origin/versions-cleanup
Robin Appelman 11 years ago
parent 3ed6ed3c36
commit ddd6a67d2a
  1. 3
      lib/private/hook.php
  2. 8
      tests/lib/testcase.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);

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

Loading…
Cancel
Save