summaryrefslogtreecommitdiffstats
path: root/tests/lib/testcase.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/testcase.php')
-rw-r--r--tests/lib/testcase.php28
1 files changed, 23 insertions, 5 deletions
diff --git a/tests/lib/testcase.php b/tests/lib/testcase.php
index 5d88fa08a6d..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();
}
@@ -92,6 +95,12 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase {
throw $hookExceptions[0];
}
+ // fail hard if xml errors have not been cleaned up
+ $errors = libxml_get_errors();
+ libxml_clear_errors();
+ $this->assertEquals([], $errors);
+
+ // tearDown the traits
$traits = $this->getTestTraits();
foreach ($traits as $trait) {
$methodName = 'tearDown' . basename(str_replace('\\', '/', $trait));
@@ -149,12 +158,21 @@ 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');
- $queryBuilder = \OC::$server->getDatabaseConnection()->getQueryBuilder();
+ if (self::$wasDatabaseAllowed && \OC::$server->getDatabaseConnection()) {
+ $queryBuilder = \OC::$server->getDatabaseConnection()->getQueryBuilder();
- self::tearDownAfterClassCleanShares($queryBuilder);
- self::tearDownAfterClassCleanStorages($queryBuilder);
- self::tearDownAfterClassCleanFileCache($queryBuilder);
+ self::tearDownAfterClassCleanShares($queryBuilder);
+ self::tearDownAfterClassCleanStorages($queryBuilder);
+ self::tearDownAfterClassCleanFileCache($queryBuilder);
+ }
self::tearDownAfterClassCleanStrayDataFiles($dataDir);
self::tearDownAfterClassCleanStrayHooks();
self::tearDownAfterClassCleanStrayLocks();