소스 검색

feat(CI): Allow apps to test with PHPUnit10

Signed-off-by: Joas Schilling <coding@schilljs.com>
tags/v28.0.0beta1
Joas Schilling 9 달 전
부모
커밋
5e7b41086d
No account linked to committer's email address
1개의 변경된 파일34개의 추가작업 그리고 13개의 파일을 삭제
  1. 34
    13
      tests/lib/TestCase.php

+ 34
- 13
tests/lib/TestCase.php 파일 보기

@@ -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…
취소
저장