From 3ed6ed3c3674bfc60bcd2fc64edea1820f1be9d0 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 24 Mar 2015 10:02:48 +0100 Subject: [PATCH] Force test cases using background commands to handle setting up the filesystem --- lib/private/command/fileaccess.php | 6 +++++- lib/private/command/queuebus.php | 2 +- tests/lib/testcase.php | 17 ++++++++++++++++- 3 files changed, 22 insertions(+), 3 deletions(-) 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 diff --git a/tests/lib/testcase.php b/tests/lib/testcase.php index 2b4540120d2..f4bb8479559 100644 --- a/tests/lib/testcase.php +++ b/tests/lib/testcase.php @@ -23,6 +23,7 @@ namespace Test; use OC\Command\QueueBus; +use OC\Files\Filesystem; use OCP\Security\ISecureRandom; abstract class TestCase extends \PHPUnit_Framework_TestCase { @@ -34,7 +35,7 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase { protected function setUp() { // overwrite the command bus with one we can run ourselves $this->commandBus = new QueueBus(); - \OC::$server->registerService('AsyncCommandBus', function(){ + \OC::$server->registerService('AsyncCommandBus', function () { return $this->commandBus; }); } @@ -190,6 +191,20 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase { * Run all commands pushed to the bus */ protected function runCommands() { + // get the user for which the fs is setup + $view = Filesystem::getView(); + if ($view) { + list(, $user) = explode('/', $view->getRoot()); + } else { + $user = null; + } + + \OC_Util::tearDownFS(); // command cant reply on the fs being setup $this->commandBus->run(); + \OC_Util::tearDownFS(); + + if ($user) { + \OC_Util::setupFS($user); + } } } -- 2.39.5