aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/TestCase.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/TestCase.php')
-rw-r--r--tests/lib/TestCase.php49
1 files changed, 36 insertions, 13 deletions
diff --git a/tests/lib/TestCase.php b/tests/lib/TestCase.php
index f5fc9a6e8f2..db124bd6823 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();
@@ -242,6 +263,8 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase {
}
return $property->getValue();
+ } elseif ($reflection->hasConstant($methodName)) {
+ return $reflection->getConstant($methodName);
}
return false;