diff options
author | Joas Schilling <coding@schilljs.com> | 2016-10-20 15:15:54 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2016-10-20 15:19:41 +0200 |
commit | 9f2d9895a53b13ecba454763d548c0e53068dee5 (patch) | |
tree | 5145f93c044d27189e74f6a4e2047412d89b596c | |
parent | 122edcd0c1b652f25c36c52cc7541eb62695bf37 (diff) | |
download | nextcloud-server-9f2d9895a53b13ecba454763d548c0e53068dee5.tar.gz nextcloud-server-9f2d9895a53b13ecba454763d548c0e53068dee5.zip |
Restore all services when a tests failed/finished for better testcase isolation
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r-- | tests/lib/TestCase.php | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/tests/lib/TestCase.php b/tests/lib/TestCase.php index 7ccff382357..61372d4ae90 100644 --- a/tests/lib/TestCase.php +++ b/tests/lib/TestCase.php @@ -102,6 +102,16 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase { return false; } + public function restoreAllServices() { + if (!empty($this->services)) { + if (!empty($this->services)) { + foreach ($this->services as $name => $service) { + $this->restoreService($name); + } + } + } + } + protected function getTestTraits() { $traits = []; $class = $this; @@ -132,9 +142,7 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase { // overwrite the command bus with one we can run ourselves $this->commandBus = new QueueBus(); - \OC::$server->registerService('AsyncCommandBus', function () { - return $this->commandBus; - }); + $this->overwriteService('AsyncCommandBus', $this->commandBus); $traits = $this->getTestTraits(); foreach ($traits as $trait) { @@ -145,7 +153,22 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase { } } + protected function onNotSuccessfulTest($e) { + $this->restoreAllServices(); + + // restore database connection + if (!$this->IsDatabaseAccessAllowed()) { + \OC::$server->registerService('DatabaseConnection', function () { + return self::$realDatabase; + }); + } + + parent::onNotSuccessfulTest($e); + } + protected function tearDown() { + $this->restoreAllServices(); + // restore database connection if (!$this->IsDatabaseAccessAllowed()) { \OC::$server->registerService('DatabaseConnection', function () { |