Restore all services when a tests failed/finished for better testcase isolation
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
122edcd0c1
commit
9f2d9895a5
|
@ -102,6 +102,16 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase {
|
||||||
return false;
|
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() {
|
protected function getTestTraits() {
|
||||||
$traits = [];
|
$traits = [];
|
||||||
$class = $this;
|
$class = $this;
|
||||||
|
@ -132,9 +142,7 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
// overwrite the command bus with one we can run ourselves
|
// overwrite the command bus with one we can run ourselves
|
||||||
$this->commandBus = new QueueBus();
|
$this->commandBus = new QueueBus();
|
||||||
\OC::$server->registerService('AsyncCommandBus', function () {
|
$this->overwriteService('AsyncCommandBus', $this->commandBus);
|
||||||
return $this->commandBus;
|
|
||||||
});
|
|
||||||
|
|
||||||
$traits = $this->getTestTraits();
|
$traits = $this->getTestTraits();
|
||||||
foreach ($traits as $trait) {
|
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() {
|
protected function tearDown() {
|
||||||
|
$this->restoreAllServices();
|
||||||
|
|
||||||
// restore database connection
|
// restore database connection
|
||||||
if (!$this->IsDatabaseAccessAllowed()) {
|
if (!$this->IsDatabaseAccessAllowed()) {
|
||||||
\OC::$server->registerService('DatabaseConnection', function () {
|
\OC::$server->registerService('DatabaseConnection', function () {
|
||||||
|
|
Loading…
Reference in New Issue