diff options
Diffstat (limited to 'tests/lib/Cache')
-rw-r--r-- | tests/lib/Cache/CappedMemoryCacheTest.php | 7 | ||||
-rw-r--r-- | tests/lib/Cache/FileCacheTest.php | 42 | ||||
-rw-r--r-- | tests/lib/Cache/TestCache.php | 7 |
3 files changed, 33 insertions, 23 deletions
diff --git a/tests/lib/Cache/CappedMemoryCacheTest.php b/tests/lib/Cache/CappedMemoryCacheTest.php index f2ed1a5ee0d..b9731c7cdde 100644 --- a/tests/lib/Cache/CappedMemoryCacheTest.php +++ b/tests/lib/Cache/CappedMemoryCacheTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -7,6 +8,8 @@ namespace Test\Cache; +use OCP\Cache\CappedMemoryCache; + /** * Class CappedMemoryCacheTest * @@ -15,11 +18,11 @@ namespace Test\Cache; class CappedMemoryCacheTest extends TestCache { protected function setUp(): void { parent::setUp(); - $this->instance = new \OCP\Cache\CappedMemoryCache(); + $this->instance = new CappedMemoryCache(); } public function testSetOverCap(): void { - $instance = new \OCP\Cache\CappedMemoryCache(3); + $instance = new CappedMemoryCache(3); $instance->set('1', 'a'); $instance->set('2', 'b'); diff --git a/tests/lib/Cache/FileCacheTest.php b/tests/lib/Cache/FileCacheTest.php index 8d3db539dd0..4daa8d3b7ef 100644 --- a/tests/lib/Cache/FileCacheTest.php +++ b/tests/lib/Cache/FileCacheTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -7,8 +8,17 @@ 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; /** @@ -30,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; @@ -55,17 +65,17 @@ class FileCacheTest extends TestCache { \OC_Hook::clear('OC_Filesystem'); /** @var IMountManager $manager */ - $manager = \OC::$server->get(IMountManager::class); + $manager = Server::get(IMountManager::class); $manager->removeMount('/test'); - $storage = new \OC\Files\Storage\Temporary([]); - \OC\Files\Filesystem::mount($storage, [], '/test/cache'); + $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'); @@ -89,10 +99,10 @@ class FileCacheTest extends TestCache { private function setupMockStorage() { $mockStorage = $this->getMockBuilder(Local::class) ->onlyMethods(['filemtime', 'unlink']) - ->setConstructorArgs([['datadir' => \OC::$server->getTempManager()->getTemporaryFolder()]]) + ->setConstructorArgs([['datadir' => Server::get(ITempManager::class)->getTemporaryFolder()]]) ->getMock(); - \OC\Files\Filesystem::mount($mockStorage, [], '/test/cache'); + Filesystem::mount($mockStorage, [], '/test/cache'); return $mockStorage; } @@ -127,14 +137,12 @@ class FileCacheTest extends TestCache { 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 - */ + #[\PHPUnit\Framework\Attributes\DataProvider('lockExceptionProvider')] public function testGarbageCollectIgnoreLockedKeys($testException): void { $mockStorage = $this->setupMockStorage(); @@ -142,11 +150,7 @@ class FileCacheTest extends TestCache { ->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'); diff --git a/tests/lib/Cache/TestCache.php b/tests/lib/Cache/TestCache.php index 3245cd90a38..ec150152816 100644 --- a/tests/lib/Cache/TestCache.php +++ b/tests/lib/Cache/TestCache.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -7,9 +8,11 @@ namespace Test\Cache; +use OCP\ICache; + abstract class TestCache extends \Test\TestCase { /** - * @var \OCP\ICache cache; + * @var ICache cache; */ protected $instance; @@ -24,7 +27,7 @@ abstract class TestCache extends \Test\TestCase { public function testSimple(): void { $this->assertNull($this->instance->get('value1')); $this->assertFalse($this->instance->hasKey('value1')); - + $value = 'foobar'; $this->instance->set('value1', $value); $this->assertTrue($this->instance->hasKey('value1')); |