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.php51
1 files changed, 28 insertions, 23 deletions
diff --git a/tests/lib/TestCase.php b/tests/lib/TestCase.php
index 9ca2606ce72..da1313d3697 100644
--- a/tests/lib/TestCase.php
+++ b/tests/lib/TestCase.php
@@ -10,6 +10,7 @@ namespace Test;
use DOMDocument;
use DOMNode;
use OC\Command\QueueBus;
+use OC\Files\Cache\Storage;
use OC\Files\Config\MountProviderCollection;
use OC\Files\Filesystem;
use OC\Files\Mount\CacheMountProvider;
@@ -24,8 +25,12 @@ use OCP\Defaults;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IL10N;
+use OCP\IUserManager;
+use OCP\IUserSession;
use OCP\Lock\ILockingProvider;
+use OCP\Lock\LockedException;
use OCP\Security\ISecureRandom;
+use OCP\Server;
if (version_compare(\PHPUnit\Runner\Version::id(), 10, '>=')) {
trait OnNotSuccessfulTestTrait {
@@ -84,7 +89,7 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase {
return false;
}
- $this->services[$name] = \OC::$server->query($name);
+ $this->services[$name] = Server::get($name);
$container = \OC::$server->getAppContainerForService($name);
$container = $container ?? \OC::$server;
@@ -154,9 +159,9 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase {
if (!$this->IsDatabaseAccessAllowed()) {
self::$wasDatabaseAllowed = false;
if (is_null(self::$realDatabase)) {
- self::$realDatabase = \OC::$server->getDatabaseConnection();
+ self::$realDatabase = Server::get(IDBConnection::class);
}
- \OC::$server->registerService(IDBConnection::class, function () {
+ \OC::$server->registerService(IDBConnection::class, function (): void {
$this->fail('Your test case is not allowed to access the database.');
});
}
@@ -183,7 +188,7 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase {
// further cleanup
$hookExceptions = \OC_Hook::$thrownExceptions;
\OC_Hook::$thrownExceptions = [];
- \OC::$server->get(ILockingProvider::class)->releaseAll();
+ Server::get(ILockingProvider::class)->releaseAll();
if (!empty($hookExceptions)) {
throw $hookExceptions[0];
}
@@ -196,7 +201,7 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase {
}
if ($this->IsDatabaseAccessAllowed()) {
- \OC\Files\Cache\Storage::getGlobalCache()->clearCache();
+ Storage::getGlobalCache()->clearCache();
}
// tearDown the traits
@@ -264,7 +269,7 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase {
* @return string
*/
protected static function getUniqueID($prefix = '', $length = 13) {
- return $prefix . \OC::$server->get(ISecureRandom::class)->generate(
+ return $prefix . Server::get(ISecureRandom::class)->generate(
$length,
// Do not use dots and slashes as we use the value for file names
ISecureRandom::CHAR_DIGITS . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER
@@ -303,9 +308,9 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase {
return self::$realDatabase;
});
}
- $dataDir = \OC::$server->getConfig()->getSystemValueString('datadirectory', \OC::$SERVERROOT . '/data-autotest');
- if (self::$wasDatabaseAllowed && \OC::$server->getDatabaseConnection()) {
- $db = \OC::$server->getDatabaseConnection();
+ $dataDir = Server::get(IConfig::class)->getSystemValueString('datadirectory', \OC::$SERVERROOT . '/data-autotest');
+ if (self::$wasDatabaseAllowed && Server::get(IDBConnection::class)) {
+ $db = Server::get(IDBConnection::class);
if ($db->inTransaction()) {
$db->rollBack();
throw new \Exception('There was a transaction still in progress and needed to be rolled back. Please fix this in your test.');
@@ -321,18 +326,18 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase {
self::tearDownAfterClassCleanStrayLocks();
/** @var SetupManager $setupManager */
- $setupManager = \OC::$server->get(SetupManager::class);
+ $setupManager = Server::get(SetupManager::class);
$setupManager->tearDown();
/** @var MountProviderCollection $mountProviderCollection */
- $mountProviderCollection = \OC::$server->get(MountProviderCollection::class);
+ $mountProviderCollection = Server::get(MountProviderCollection::class);
$mountProviderCollection->clearProviders();
/** @var IConfig $config */
- $config = \OC::$server->get(IConfig::class);
+ $config = Server::get(IConfig::class);
$mountProviderCollection->registerProvider(new CacheMountProvider($config));
$mountProviderCollection->registerHomeProvider(new LocalHomeMountProvider());
- $objectStoreConfig = \OC::$server->get(PrimaryObjectStoreConfig::class);
+ $objectStoreConfig = Server::get(PrimaryObjectStoreConfig::class);
$mountProviderCollection->registerRootProvider(new RootMountProvider($objectStoreConfig, $config));
$setupManager->setupRoot();
@@ -404,7 +409,7 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase {
protected static function tearDownAfterClassCleanStrayDataUnlinkDir($dir) {
if ($dh = @opendir($dir)) {
while (($file = readdir($dh)) !== false) {
- if (\OC\Files\Filesystem::isIgnoredDir($file)) {
+ if (Filesystem::isIgnoredDir($file)) {
continue;
}
$path = $dir . '/' . $file;
@@ -430,7 +435,7 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase {
* Clean up the list of locks
*/
protected static function tearDownAfterClassCleanStrayLocks() {
- \OC::$server->get(ILockingProvider::class)->releaseAll();
+ Server::get(ILockingProvider::class)->releaseAll();
}
/**
@@ -441,14 +446,14 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase {
*/
protected static function loginAsUser($user = '') {
self::logout();
- \OC\Files\Filesystem::tearDown();
+ Filesystem::tearDown();
\OC_User::setUserId($user);
- $userObject = \OC::$server->getUserManager()->get($user);
+ $userObject = Server::get(IUserManager::class)->get($user);
if (!is_null($userObject)) {
$userObject->updateLastLoginTimestamp();
}
\OC_Util::setupFS($user);
- if (\OC::$server->getUserManager()->userExists($user)) {
+ if (Server::get(IUserManager::class)->userExists($user)) {
\OC::$server->getUserFolder($user);
}
}
@@ -460,7 +465,7 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase {
\OC_Util::tearDownFS();
\OC_User::setUserId('');
// needed for fully logout
- \OC::$server->getUserSession()->setUser(null);
+ Server::get(IUserSession::class)->setUser(null);
}
/**
@@ -501,12 +506,12 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase {
// the format of the lock key depends on the storage implementation
// (in our case mostly md5)
- if ($type === \OCP\Lock\ILockingProvider::LOCK_SHARED) {
+ if ($type === ILockingProvider::LOCK_SHARED) {
// to check if the file has a shared lock, try acquiring an exclusive lock
- $checkType = \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE;
+ $checkType = ILockingProvider::LOCK_EXCLUSIVE;
} else {
// a shared lock cannot be set if exclusive lock is in place
- $checkType = \OCP\Lock\ILockingProvider::LOCK_SHARED;
+ $checkType = ILockingProvider::LOCK_SHARED;
}
try {
$view->lockFile($path, $checkType, $onMountPoint);
@@ -514,7 +519,7 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase {
// clean up
$view->unlockFile($path, $checkType, $onMountPoint);
return false;
- } catch (\OCP\Lock\LockedException $e) {
+ } catch (LockedException $e) {
// we could not acquire the counter-lock, which means
// the lock of $type was in place
return true;