Merge pull request #21316 from owncloud/tests-fixtestcasetoallowfailure
Restore DB connection after failure
This commit is contained in:
commit
6b1cb44cb1
|
@ -33,7 +33,8 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase {
|
||||||
private $commandBus;
|
private $commandBus;
|
||||||
|
|
||||||
/** @var IDBConnection */
|
/** @var IDBConnection */
|
||||||
static private $realDatabase;
|
static protected $realDatabase = null;
|
||||||
|
static private $wasDatabaseAllowed = false;
|
||||||
|
|
||||||
protected function getTestTraits() {
|
protected function getTestTraits() {
|
||||||
$traits = [];
|
$traits = [];
|
||||||
|
@ -52,7 +53,9 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
protected function setUp() {
|
protected function setUp() {
|
||||||
// detect database access
|
// detect database access
|
||||||
|
self::$wasDatabaseAllowed = true;
|
||||||
if (!$this->IsDatabaseAccessAllowed()) {
|
if (!$this->IsDatabaseAccessAllowed()) {
|
||||||
|
self::$wasDatabaseAllowed = false;
|
||||||
if (is_null(self::$realDatabase)) {
|
if (is_null(self::$realDatabase)) {
|
||||||
self::$realDatabase = \OC::$server->getDatabaseConnection();
|
self::$realDatabase = \OC::$server->getDatabaseConnection();
|
||||||
}
|
}
|
||||||
|
@ -155,8 +158,15 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function tearDownAfterClass() {
|
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');
|
$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();
|
$queryBuilder = \OC::$server->getDatabaseConnection()->getQueryBuilder();
|
||||||
|
|
||||||
self::tearDownAfterClassCleanShares($queryBuilder);
|
self::tearDownAfterClassCleanShares($queryBuilder);
|
||||||
|
|
Loading…
Reference in New Issue