feat(CI): Allow apps to test with PHPUnit10

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2023-09-21 21:32:15 +02:00
parent 3b6a9cd236
commit 5e7b41086d
No known key found for this signature in database
GPG Key ID: C400AAF20C1BB6FC
1 changed files with 34 additions and 13 deletions

View File

@ -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();