diff options
author | John Molakvoæ <skjnldsv@users.noreply.github.com> | 2024-05-30 14:24:22 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-30 14:24:22 +0200 |
commit | 258bb03cf59558351bcf47f089fd560de2d82399 (patch) | |
tree | aa59ba898bf410cf8a30e8a8418926536a4537a6 /tests/lib/TestCase.php | |
parent | 1395a5360274a6c6c0b4084d22da53466998c954 (diff) | |
parent | 31b0a44cf65b6625636ea0fa15fb1a1122b525e1 (diff) | |
download | nextcloud-server-258bb03cf59558351bcf47f089fd560de2d82399.tar.gz nextcloud-server-258bb03cf59558351bcf47f089fd560de2d82399.zip |
Merge branch 'master' into refactor/OC-Server-getSecureRandom
Signed-off-by: John Molakvoæ <skjnldsv@users.noreply.github.com>
Diffstat (limited to 'tests/lib/TestCase.php')
-rw-r--r-- | tests/lib/TestCase.php | 77 |
1 files changed, 43 insertions, 34 deletions
diff --git a/tests/lib/TestCase.php b/tests/lib/TestCase.php index 130deaf11a7..8c97c184c6f 100644 --- a/tests/lib/TestCase.php +++ b/tests/lib/TestCase.php @@ -1,23 +1,8 @@ <?php /** - * ownCloud - * - * @author Joas Schilling - * @copyright 2014 Joas Schilling nickvergessen@owncloud.com - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE - * License as published by the Free Software Foundation; either - * version 3 of the License, or any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU AFFERO GENERAL PUBLIC LICENSE for more details. - * - * You should have received a copy of the GNU Affero General Public - * License along with this library. If not, see <http://www.gnu.org/licenses/>. - * + * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace Test; @@ -38,9 +23,42 @@ use OCP\Defaults; use OCP\IConfig; use OCP\IDBConnection; use OCP\IL10N; +use OCP\Lock\ILockingProvider; 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 +72,8 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase { /** @var array */ protected $services = []; + use OnNotSuccessfulTestTrait; + /** * @param string $name * @param mixed $newService @@ -150,19 +170,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(); @@ -176,7 +183,7 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase { // further cleanup $hookExceptions = \OC_Hook::$thrownExceptions; \OC_Hook::$thrownExceptions = []; - \OC::$server->getLockingProvider()->releaseAll(); + \OC::$server->get(ILockingProvider::class)->releaseAll(); if (!empty($hookExceptions)) { throw $hookExceptions[0]; } @@ -242,6 +249,8 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase { } return $property->getValue(); + } elseif ($reflection->hasConstant($methodName)) { + return $reflection->getConstant($methodName); } return false; @@ -395,7 +404,7 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase { * Clean up the list of locks */ protected static function tearDownAfterClassCleanStrayLocks() { - \OC::$server->getLockingProvider()->releaseAll(); + \OC::$server->get(ILockingProvider::class)->releaseAll(); } /** @@ -501,7 +510,7 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase { protected function IsDatabaseAccessAllowed() { // on travis-ci.org we allow database access in any case - otherwise // this will break all apps right away - if (true == getenv('TRAVIS')) { + if (getenv('TRAVIS') == true) { return true; } $annotations = $this->getGroupAnnotations(); |