From 3ed6ed3c3674bfc60bcd2fc64edea1820f1be9d0 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 24 Mar 2015 10:02:48 +0100 Subject: Force test cases using background commands to handle setting up the filesystem --- lib/private/command/fileaccess.php | 6 +++++- lib/private/command/queuebus.php | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/private/command/fileaccess.php b/lib/private/command/fileaccess.php index 5de00862fac..b08fb1825ea 100644 --- a/lib/private/command/fileaccess.php +++ b/lib/private/command/fileaccess.php @@ -11,8 +11,12 @@ namespace OC\Command; use OCP\IUser; trait FileAccess { - protected function getUserFolder(IUser $user) { + protected function setupFS(IUser $user){ \OC_Util::setupFS($user->getUID()); + } + + protected function getUserFolder(IUser $user) { + $this->setupFS($user); return \OC::$server->getUserFolder($user->getUID()); } } diff --git a/lib/private/command/queuebus.php b/lib/private/command/queuebus.php index 29c769e0107..953479086ca 100644 --- a/lib/private/command/queuebus.php +++ b/lib/private/command/queuebus.php @@ -15,7 +15,7 @@ class QueueBus implements IBus { /** * @var (ICommand|callable)[] */ - private $queue; + private $queue = []; /** * Schedule a command to be fired -- cgit v1.2.3 From ddd6a67d2a36791e2f921596f6c34436c4d5752d Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 24 Mar 2015 10:19:30 +0100 Subject: Handle exceptions thrown during hooks when running unit tests --- lib/private/hook.php | 3 +++ tests/lib/testcase.php | 8 ++++++++ 2 files changed, 11 insertions(+) (limited to 'lib') 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 * -- cgit v1.2.3 From 268f249e8d98e8b91f51f4d39cfc060efbd5caab Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 24 Mar 2015 10:46:29 +0100 Subject: ensure commands can be serialized in unit tests --- lib/private/command/queuebus.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/private/command/queuebus.php b/lib/private/command/queuebus.php index 953479086ca..e5604eb1fef 100644 --- a/lib/private/command/queuebus.php +++ b/lib/private/command/queuebus.php @@ -39,7 +39,10 @@ class QueueBus implements IBus { */ private function runCommand($command) { if ($command instanceof ICommand) { - $command->handle(); + // ensure the command can be serialized + $serialized = serialize($command); + $unserialized = unserialize($serialized); + $unserialized->handle(); } else { $command(); } -- cgit v1.2.3 From 8c903c100ff6517806e5328ef56d615f5c93490b Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 24 Mar 2015 10:48:21 +0100 Subject: check limit of serialized command in unit tests --- lib/private/command/queuebus.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib') diff --git a/lib/private/command/queuebus.php b/lib/private/command/queuebus.php index e5604eb1fef..78712ebd9cd 100644 --- a/lib/private/command/queuebus.php +++ b/lib/private/command/queuebus.php @@ -41,6 +41,9 @@ class QueueBus implements IBus { if ($command instanceof ICommand) { // ensure the command can be serialized $serialized = serialize($command); + if(strlen($serialized) > 4000) { + throw new \InvalidArgumentException('Trying to push a command which serialized form can not be stored in the database (>4000 character)'); + } $unserialized = unserialize($serialized); $unserialized->handle(); } else { -- cgit v1.2.3