mirror of https://github.com/nextcloud/server
feat(CI): Allow apps to test with PHPUnit10
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
3b6a9cd236
commit
5e7b41086d
|
@ -41,6 +41,38 @@ use OCP\IL10N;
|
|||
use OCP\Security\ISecureRandom;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
if (version_compare(\PHPUnit\Runner\Version::id(), 10, '>=')) {
|
||||
trait OnNotSuccessfulTestTrait {
|
||||
protected function onNotSuccessfulTest(\Throwable $t): never {
|
||||
$this->restoreAllServices();
|
||||
|
||||
// restore database connection
|
||||
if (!$this->IsDatabaseAccessAllowed()) {
|
||||
\OC::$server->registerService(IDBConnection::class, function () {
|
||||
return self::$realDatabase;
|
||||
});
|
||||
}
|
||||
|
||||
parent::onNotSuccessfulTest($t);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
trait OnNotSuccessfulTestTrait {
|
||||
protected function onNotSuccessfulTest(\Throwable $t): void {
|
||||
$this->restoreAllServices();
|
||||
|
||||
// restore database connection
|
||||
if (!$this->IsDatabaseAccessAllowed()) {
|
||||
\OC::$server->registerService(IDBConnection::class, function () {
|
||||
return self::$realDatabase;
|
||||
});
|
||||
}
|
||||
|
||||
parent::onNotSuccessfulTest($t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
abstract class TestCase extends \PHPUnit\Framework\TestCase {
|
||||
/** @var \OC\Command\QueueBus */
|
||||
private $commandBus;
|
||||
|
@ -54,6 +86,8 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase {
|
|||
/** @var array */
|
||||
protected $services = [];
|
||||
|
||||
use OnNotSuccessfulTestTrait;
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param mixed $newService
|
||||
|
@ -150,19 +184,6 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
protected function onNotSuccessfulTest(\Throwable $t): void {
|
||||
$this->restoreAllServices();
|
||||
|
||||
// restore database connection
|
||||
if (!$this->IsDatabaseAccessAllowed()) {
|
||||
\OC::$server->registerService(IDBConnection::class, function () {
|
||||
return self::$realDatabase;
|
||||
});
|
||||
}
|
||||
|
||||
parent::onNotSuccessfulTest($t);
|
||||
}
|
||||
|
||||
protected function tearDown(): void {
|
||||
$this->restoreAllServices();
|
||||
|
||||
|
|
Loading…
Reference in New Issue