diff options
author | Joas Schilling <213943+nickvergessen@users.noreply.github.com> | 2023-09-22 08:45:19 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-22 08:45:19 +0200 |
commit | 26ad0a1b9c4b617e50cfd27b9696b052522953be (patch) | |
tree | e62372852b832614cd882451b23f1adbdb83c22a | |
parent | c63ef4a2d5835a5301435b62bc010c7834297d75 (diff) | |
parent | 5e7b41086dacab1b63a564259baea5eb9b59b7bd (diff) | |
download | nextcloud-server-26ad0a1b9c4b617e50cfd27b9696b052522953be.tar.gz nextcloud-server-26ad0a1b9c4b617e50cfd27b9696b052522953be.zip |
Merge pull request #40574 from nextcloud/techdebt/noid/allow-phpunit10
feat(CI): Allow apps to test with PHPUnit10
-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(); |