diff options
author | Joas Schilling <coding@schilljs.com> | 2023-09-21 21:32:15 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2023-09-21 21:32:15 +0200 |
commit | 5e7b41086dacab1b63a564259baea5eb9b59b7bd (patch) | |
tree | 946a0be71b2b1b24bb171d054cd673537a09616c /tests | |
parent | 3b6a9cd23628464cd24da3d426764a8232124f33 (diff) | |
download | nextcloud-server-5e7b41086dacab1b63a564259baea5eb9b59b7bd.tar.gz nextcloud-server-5e7b41086dacab1b63a564259baea5eb9b59b7bd.zip |
feat(CI): Allow apps to test with PHPUnit10
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/TestCase.php | 47 |
1 files changed, 34 insertions, 13 deletions
diff --git a/tests/lib/TestCase.php b/tests/lib/TestCase.php index f5fc9a6e8f2..14f1961ef2e 100644 --- a/tests/lib/TestCase.php +++ b/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(); |