diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2015-12-21 18:53:35 +0100 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2015-12-21 18:53:35 +0100 |
commit | 6b1cb44cb1c9195540e38d3e93ec72c99aa0b29d (patch) | |
tree | 75165c1b9aa8608b1bf33ce4aa1888b5febcd7af | |
parent | 38a006b1e845de399ed10001d3ff9efbe76a5de5 (diff) | |
parent | d7169ffdec2a744683b9fb613dd08d560ed9842f (diff) | |
download | nextcloud-server-6b1cb44cb1c9195540e38d3e93ec72c99aa0b29d.tar.gz nextcloud-server-6b1cb44cb1c9195540e38d3e93ec72c99aa0b29d.zip |
Merge pull request #21316 from owncloud/tests-fixtestcasetoallowfailure
Restore DB connection after failure
-rw-r--r-- | tests/lib/testcase.php | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/tests/lib/testcase.php b/tests/lib/testcase.php index 1ee0c85b98a..93b354863a9 100644 --- a/tests/lib/testcase.php +++ b/tests/lib/testcase.php @@ -33,7 +33,8 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase { private $commandBus; /** @var IDBConnection */ - static private $realDatabase; + static protected $realDatabase = null; + static private $wasDatabaseAllowed = false; protected function getTestTraits() { $traits = []; @@ -52,7 +53,9 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase { protected function setUp() { // detect database access + self::$wasDatabaseAllowed = true; if (!$this->IsDatabaseAccessAllowed()) { + self::$wasDatabaseAllowed = false; if (is_null(self::$realDatabase)) { self::$realDatabase = \OC::$server->getDatabaseConnection(); } @@ -155,8 +158,15 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase { } public static function tearDownAfterClass() { + if (!self::$wasDatabaseAllowed && self::$realDatabase !== null) { + // in case an error is thrown in a test, PHPUnit jumps straight to tearDownAfterClass, + // so we need the database again + \OC::$server->registerService('DatabaseConnection', function () { + return self::$realDatabase; + }); + } $dataDir = \OC::$server->getConfig()->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data-autotest'); - if (\OC::$server->getDatabaseConnection()) { + if (self::$wasDatabaseAllowed && \OC::$server->getDatabaseConnection()) { $queryBuilder = \OC::$server->getDatabaseConnection()->getQueryBuilder(); self::tearDownAfterClassCleanShares($queryBuilder); |