aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/Cache/FileCacheTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/Cache/FileCacheTest.php')
-rw-r--r--tests/lib/Cache/FileCacheTest.php108
1 files changed, 43 insertions, 65 deletions
diff --git a/tests/lib/Cache/FileCacheTest.php b/tests/lib/Cache/FileCacheTest.php
index c9eafeca280..4daa8d3b7ef 100644
--- a/tests/lib/Cache/FileCacheTest.php
+++ b/tests/lib/Cache/FileCacheTest.php
@@ -1,28 +1,25 @@
<?php
+
/**
- * ownCloud
- *
- * @author Robin Appelman
- * @copyright 2012 Robin Appelman icewind@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\Cache;
+use OC\Cache\File;
+use OC\Files\Filesystem;
use OC\Files\Storage\Local;
+use OC\Files\Storage\Storage;
+use OC\Files\Storage\Temporary;
+use OC\Files\View;
+use OCP\Files\LockNotAcquiredException;
+use OCP\Files\Mount\IMountManager;
+use OCP\ITempManager;
+use OCP\Lock\LockedException;
+use OCP\Server;
+use Test\Traits\UserTrait;
/**
* Class FileCacheTest
@@ -32,6 +29,8 @@ use OC\Files\Storage\Local;
* @package Test\Cache
*/
class FileCacheTest extends TestCache {
+ use UserTrait;
+
/**
* @var string
* */
@@ -41,11 +40,11 @@ class FileCacheTest extends TestCache {
* */
private $datadir;
/**
- * @var \OC\Files\Storage\Storage
+ * @var Storage
* */
private $storage;
/**
- * @var \OC\Files\View
+ * @var View
* */
private $rootView;
@@ -56,33 +55,27 @@ class FileCacheTest extends TestCache {
protected function setUp(): void {
parent::setUp();
- //clear all proxies and hooks so we can do clean testing
- \OC_Hook::clear('OC_Filesystem');
-
- //set up temporary storage
- $this->storage = \OC\Files\Filesystem::getStorage('/');
- \OC\Files\Filesystem::clearMounts();
- $storage = new \OC\Files\Storage\Temporary([]);
- \OC\Files\Filesystem::mount($storage,[],'/');
- $datadir = str_replace('local::', '', $storage->getId());
- $config = \OC::$server->getConfig();
- $this->datadir = $config->getSystemValue('cachedirectory', \OC::$SERVERROOT.'/data/cache');
- $config->setSystemValue('cachedirectory', $datadir);
-
- \OC_User::clearBackends();
- \OC_User::useBackend(new \Test\Util\User\Dummy());
-
//login
- \OC::$server->getUserManager()->createUser('test', 'test');
+ $this->createUser('test', 'test');
$this->user = \OC_User::getUser();
\OC_User::setUserId('test');
+ //clear all proxies and hooks so we can do clean testing
+ \OC_Hook::clear('OC_Filesystem');
+
+ /** @var IMountManager $manager */
+ $manager = Server::get(IMountManager::class);
+ $manager->removeMount('/test');
+
+ $storage = new Temporary([]);
+ Filesystem::mount($storage, [], '/test/cache');
+
//set up the users dir
- $this->rootView = new \OC\Files\View('');
+ $this->rootView = new View('');
$this->rootView->mkdir('/test');
- $this->instance = new \OC\Cache\File();
+ $this->instance = new File();
// forces creation of cache folder for subsequent tests
$this->instance->set('hack', 'hack');
@@ -94,36 +87,27 @@ class FileCacheTest extends TestCache {
}
\OC_User::setUserId($this->user);
- \OC::$server->getConfig()->setSystemValue('cachedirectory', $this->datadir);
if ($this->instance) {
$this->instance->clear();
$this->instance = null;
}
- //tear down the users dir aswell
- $user = \OC::$server->getUserManager()->get('test');
- $user->delete();
-
- // Restore the original mount point
- \OC\Files\Filesystem::clearMounts();
- \OC\Files\Filesystem::mount($this->storage, [], '/');
-
parent::tearDown();
}
private function setupMockStorage() {
$mockStorage = $this->getMockBuilder(Local::class)
- ->setMethods(['filemtime', 'unlink'])
- ->setConstructorArgs([['datadir' => \OC::$server->getTempManager()->getTemporaryFolder()]])
+ ->onlyMethods(['filemtime', 'unlink'])
+ ->setConstructorArgs([['datadir' => Server::get(ITempManager::class)->getTemporaryFolder()]])
->getMock();
- \OC\Files\Filesystem::mount($mockStorage, [], '/test/cache');
+ Filesystem::mount($mockStorage, [], '/test/cache');
return $mockStorage;
}
- public function testGarbageCollectOldKeys() {
+ public function testGarbageCollectOldKeys(): void {
$mockStorage = $this->setupMockStorage();
$mockStorage->expects($this->atLeastOnce())
@@ -138,7 +122,7 @@ class FileCacheTest extends TestCache {
$this->instance->gc();
}
- public function testGarbageCollectLeaveRecentKeys() {
+ public function testGarbageCollectLeaveRecentKeys(): void {
$mockStorage = $this->setupMockStorage();
$mockStorage->expects($this->atLeastOnce())
@@ -151,28 +135,22 @@ class FileCacheTest extends TestCache {
$this->instance->gc();
}
- public function lockExceptionProvider() {
+ public static function lockExceptionProvider(): array {
return [
- [new \OCP\Lock\LockedException('key1')],
- [new \OCP\Files\LockNotAcquiredException('key1', 1)],
+ [new LockedException('key1')],
+ [new LockNotAcquiredException('key1', 1)],
];
}
- /**
- * @dataProvider lockExceptionProvider
- */
- public function testGarbageCollectIgnoreLockedKeys($testException) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('lockExceptionProvider')]
+ public function testGarbageCollectIgnoreLockedKeys($testException): void {
$mockStorage = $this->setupMockStorage();
$mockStorage->expects($this->atLeastOnce())
->method('filemtime')
->willReturn(100);
$mockStorage->expects($this->atLeastOnce())
- ->method('unlink')
- ->will($this->onConsecutiveCalls(
- $this->throwException($testException),
- $this->returnValue(true)
- ));
+ ->method('unlink')->willReturnOnConsecutiveCalls($this->throwException($testException), $this->returnValue(true));
$this->instance->set('key1', 'value1');
$this->instance->set('key2', 'value2');