diff options
Diffstat (limited to 'tests/lib/Lock')
-rw-r--r-- | tests/lib/Lock/DBLockingProviderTest.php | 38 | ||||
-rw-r--r-- | tests/lib/Lock/LockingProvider.php | 103 | ||||
-rw-r--r-- | tests/lib/Lock/MemcacheLockingProviderTest.php | 33 | ||||
-rw-r--r-- | tests/lib/Lock/NonCachingDBLockingProviderTest.php | 31 |
4 files changed, 82 insertions, 123 deletions
diff --git a/tests/lib/Lock/DBLockingProviderTest.php b/tests/lib/Lock/DBLockingProviderTest.php index 860e8d73cf0..32a223b4913 100644 --- a/tests/lib/Lock/DBLockingProviderTest.php +++ b/tests/lib/Lock/DBLockingProviderTest.php @@ -1,28 +1,18 @@ <?php + /** - * @author Robin Appelman <icewind@owncloud.com> - * - * @copyright Copyright (c) 2015, ownCloud, Inc. - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program 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, version 3, - * along with this program. 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-only */ namespace Test\Lock; +use OC\Lock\DBLockingProvider; use OCP\AppFramework\Utility\ITimeFactory; +use OCP\IDBConnection; use OCP\Lock\ILockingProvider; +use OCP\Server; /** * Class DBLockingProvider @@ -38,12 +28,12 @@ class DBLockingProviderTest extends LockingProvider { protected $instance; /** - * @var \OCP\IDBConnection + * @var IDBConnection */ protected $connection; /** - * @var \OCP\AppFramework\Utility\ITimeFactory + * @var ITimeFactory */ protected $timeFactory; @@ -61,11 +51,11 @@ class DBLockingProviderTest extends LockingProvider { } /** - * @return \OCP\Lock\ILockingProvider + * @return ILockingProvider */ protected function getInstance() { - $this->connection = \OC::$server->getDatabaseConnection(); - return new \OC\Lock\DBLockingProvider($this->connection, $this->timeFactory, 3600); + $this->connection = Server::get(IDBConnection::class); + return new DBLockingProvider($this->connection, $this->timeFactory, 3600); } protected function tearDown(): void { @@ -73,7 +63,7 @@ class DBLockingProviderTest extends LockingProvider { parent::tearDown(); } - public function testCleanEmptyLocks() { + public function testCleanEmptyLocks(): void { $this->currentTime = 100; $this->instance->acquireLock('foo', ILockingProvider::LOCK_EXCLUSIVE); $this->instance->acquireLock('asd', ILockingProvider::LOCK_EXCLUSIVE); @@ -110,7 +100,7 @@ class DBLockingProviderTest extends LockingProvider { return $rows; } - public function testDoubleShared() { + public function testDoubleShared(): void { $this->instance->acquireLock('foo', ILockingProvider::LOCK_SHARED); $this->instance->acquireLock('foo', ILockingProvider::LOCK_SHARED); diff --git a/tests/lib/Lock/LockingProvider.php b/tests/lib/Lock/LockingProvider.php index 93eba367af2..2827f2c9160 100644 --- a/tests/lib/Lock/LockingProvider.php +++ b/tests/lib/Lock/LockingProvider.php @@ -1,22 +1,9 @@ <?php + /** - * @author Robin Appelman <icewind@owncloud.com> - * - * @copyright Copyright (c) 2015, ownCloud, Inc. - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program 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, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * + * SPDX-FileCopyrightText: 2018-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only */ namespace Test\Lock; @@ -27,12 +14,12 @@ use Test\TestCase; abstract class LockingProvider extends TestCase { /** - * @var \OCP\Lock\ILockingProvider + * @var ILockingProvider */ protected $instance; /** - * @return \OCP\Lock\ILockingProvider + * @return ILockingProvider */ abstract protected function getInstance(); @@ -41,19 +28,19 @@ abstract class LockingProvider extends TestCase { $this->instance = $this->getInstance(); } - public function testExclusiveLock() { + public function testExclusiveLock(): void { $this->instance->acquireLock('foo', ILockingProvider::LOCK_EXCLUSIVE); $this->assertTrue($this->instance->isLocked('foo', ILockingProvider::LOCK_EXCLUSIVE)); $this->assertFalse($this->instance->isLocked('foo', ILockingProvider::LOCK_SHARED)); } - public function testSharedLock() { + public function testSharedLock(): void { $this->instance->acquireLock('foo', ILockingProvider::LOCK_SHARED); $this->assertFalse($this->instance->isLocked('foo', ILockingProvider::LOCK_EXCLUSIVE)); $this->assertTrue($this->instance->isLocked('foo', ILockingProvider::LOCK_SHARED)); } - public function testDoubleSharedLock() { + public function testDoubleSharedLock(): void { $this->instance->acquireLock('foo', ILockingProvider::LOCK_SHARED); $this->assertFalse($this->instance->isLocked('foo', ILockingProvider::LOCK_EXCLUSIVE)); $this->assertTrue($this->instance->isLocked('foo', ILockingProvider::LOCK_SHARED)); @@ -61,7 +48,7 @@ abstract class LockingProvider extends TestCase { $this->assertTrue($this->instance->isLocked('foo', ILockingProvider::LOCK_SHARED)); } - public function testReleaseSharedLock() { + public function testReleaseSharedLock(): void { $this->instance->acquireLock('foo', ILockingProvider::LOCK_SHARED); $this->assertFalse($this->instance->isLocked('foo', ILockingProvider::LOCK_EXCLUSIVE)); $this->assertTrue($this->instance->isLocked('foo', ILockingProvider::LOCK_SHARED)); @@ -73,16 +60,16 @@ abstract class LockingProvider extends TestCase { $this->assertFalse($this->instance->isLocked('foo', ILockingProvider::LOCK_SHARED)); } - - public function testDoubleExclusiveLock() { - $this->expectException(\OCP\Lock\LockedException::class); + + public function testDoubleExclusiveLock(): void { + $this->expectException(LockedException::class); $this->instance->acquireLock('foo', ILockingProvider::LOCK_EXCLUSIVE); $this->assertTrue($this->instance->isLocked('foo', ILockingProvider::LOCK_EXCLUSIVE)); $this->instance->acquireLock('foo', ILockingProvider::LOCK_EXCLUSIVE); } - public function testReleaseExclusiveLock() { + public function testReleaseExclusiveLock(): void { $this->instance->acquireLock('foo', ILockingProvider::LOCK_EXCLUSIVE); $this->assertTrue($this->instance->isLocked('foo', ILockingProvider::LOCK_EXCLUSIVE)); $this->instance->releaseLock('foo', ILockingProvider::LOCK_EXCLUSIVE); @@ -90,16 +77,16 @@ abstract class LockingProvider extends TestCase { $this->instance->acquireLock('foo', ILockingProvider::LOCK_EXCLUSIVE); } - - public function testExclusiveLockAfterShared() { - $this->expectException(\OCP\Lock\LockedException::class); + + public function testExclusiveLockAfterShared(): void { + $this->expectException(LockedException::class); $this->instance->acquireLock('foo', ILockingProvider::LOCK_SHARED); $this->assertTrue($this->instance->isLocked('foo', ILockingProvider::LOCK_SHARED)); $this->instance->acquireLock('foo', ILockingProvider::LOCK_EXCLUSIVE); } - public function testExclusiveLockAfterSharedReleased() { + public function testExclusiveLockAfterSharedReleased(): void { $this->instance->acquireLock('foo', ILockingProvider::LOCK_SHARED); $this->assertTrue($this->instance->isLocked('foo', ILockingProvider::LOCK_SHARED)); $this->instance->releaseLock('foo', ILockingProvider::LOCK_SHARED); @@ -107,7 +94,7 @@ abstract class LockingProvider extends TestCase { $this->assertTrue($this->instance->isLocked('foo', ILockingProvider::LOCK_EXCLUSIVE)); } - public function testReleaseAll() { + public function testReleaseAll(): void { $this->instance->acquireLock('foo', ILockingProvider::LOCK_SHARED); $this->instance->acquireLock('foo', ILockingProvider::LOCK_SHARED); $this->instance->acquireLock('bar', ILockingProvider::LOCK_SHARED); @@ -122,7 +109,7 @@ abstract class LockingProvider extends TestCase { $this->assertFalse($this->instance->isLocked('fizz#A=23', ILockingProvider::LOCK_EXCLUSIVE)); } - public function testReleaseAllAfterChange() { + public function testReleaseAllAfterChange(): void { $this->instance->acquireLock('foo', ILockingProvider::LOCK_SHARED); $this->instance->acquireLock('foo', ILockingProvider::LOCK_SHARED); $this->instance->acquireLock('bar', ILockingProvider::LOCK_SHARED); @@ -138,7 +125,7 @@ abstract class LockingProvider extends TestCase { $this->assertFalse($this->instance->isLocked('asd', ILockingProvider::LOCK_EXCLUSIVE)); } - public function testReleaseAllAfterUnlock() { + public function testReleaseAllAfterUnlock(): void { $this->instance->acquireLock('foo', ILockingProvider::LOCK_SHARED); $this->instance->acquireLock('foo', ILockingProvider::LOCK_SHARED); $this->instance->acquireLock('bar', ILockingProvider::LOCK_SHARED); @@ -152,7 +139,7 @@ abstract class LockingProvider extends TestCase { $this->assertFalse($this->instance->isLocked('asd', ILockingProvider::LOCK_EXCLUSIVE)); } - public function testReleaseAfterReleaseAll() { + public function testReleaseAfterReleaseAll(): void { $this->instance->acquireLock('foo', ILockingProvider::LOCK_SHARED); $this->instance->acquireLock('foo', ILockingProvider::LOCK_SHARED); @@ -164,16 +151,16 @@ abstract class LockingProvider extends TestCase { } - - public function testSharedLockAfterExclusive() { - $this->expectException(\OCP\Lock\LockedException::class); + + public function testSharedLockAfterExclusive(): void { + $this->expectException(LockedException::class); $this->instance->acquireLock('foo', ILockingProvider::LOCK_EXCLUSIVE); $this->assertTrue($this->instance->isLocked('foo', ILockingProvider::LOCK_EXCLUSIVE)); $this->instance->acquireLock('foo', ILockingProvider::LOCK_SHARED); } - public function testLockedExceptionHasPathForShared() { + public function testLockedExceptionHasPathForShared(): void { try { $this->instance->acquireLock('foo', ILockingProvider::LOCK_EXCLUSIVE); $this->assertTrue($this->instance->isLocked('foo', ILockingProvider::LOCK_EXCLUSIVE)); @@ -185,7 +172,7 @@ abstract class LockingProvider extends TestCase { } } - public function testLockedExceptionHasPathForExclusive() { + public function testLockedExceptionHasPathForExclusive(): void { try { $this->instance->acquireLock('foo', ILockingProvider::LOCK_EXCLUSIVE); $this->assertTrue($this->instance->isLocked('foo', ILockingProvider::LOCK_EXCLUSIVE)); @@ -197,60 +184,60 @@ abstract class LockingProvider extends TestCase { } } - public function testChangeLockToExclusive() { + public function testChangeLockToExclusive(): void { $this->instance->acquireLock('foo', ILockingProvider::LOCK_SHARED); $this->instance->changeLock('foo', ILockingProvider::LOCK_EXCLUSIVE); $this->assertFalse($this->instance->isLocked('foo', ILockingProvider::LOCK_SHARED)); $this->assertTrue($this->instance->isLocked('foo', ILockingProvider::LOCK_EXCLUSIVE)); } - public function testChangeLockToShared() { + public function testChangeLockToShared(): void { $this->instance->acquireLock('foo', ILockingProvider::LOCK_EXCLUSIVE); $this->instance->changeLock('foo', ILockingProvider::LOCK_SHARED); $this->assertFalse($this->instance->isLocked('foo', ILockingProvider::LOCK_EXCLUSIVE)); $this->assertTrue($this->instance->isLocked('foo', ILockingProvider::LOCK_SHARED)); } - - public function testChangeLockToExclusiveDoubleShared() { - $this->expectException(\OCP\Lock\LockedException::class); + + public function testChangeLockToExclusiveDoubleShared(): void { + $this->expectException(LockedException::class); $this->instance->acquireLock('foo', ILockingProvider::LOCK_SHARED); $this->instance->acquireLock('foo', ILockingProvider::LOCK_SHARED); $this->instance->changeLock('foo', ILockingProvider::LOCK_EXCLUSIVE); } - - public function testChangeLockToExclusiveNoShared() { - $this->expectException(\OCP\Lock\LockedException::class); + + public function testChangeLockToExclusiveNoShared(): void { + $this->expectException(LockedException::class); $this->instance->changeLock('foo', ILockingProvider::LOCK_EXCLUSIVE); } - - public function testChangeLockToExclusiveFromExclusive() { - $this->expectException(\OCP\Lock\LockedException::class); + + public function testChangeLockToExclusiveFromExclusive(): void { + $this->expectException(LockedException::class); $this->instance->acquireLock('foo', ILockingProvider::LOCK_EXCLUSIVE); $this->instance->changeLock('foo', ILockingProvider::LOCK_EXCLUSIVE); } - - public function testChangeLockToSharedNoExclusive() { - $this->expectException(\OCP\Lock\LockedException::class); + + public function testChangeLockToSharedNoExclusive(): void { + $this->expectException(LockedException::class); $this->instance->changeLock('foo', ILockingProvider::LOCK_SHARED); } - - public function testChangeLockToSharedFromShared() { - $this->expectException(\OCP\Lock\LockedException::class); + + public function testChangeLockToSharedFromShared(): void { + $this->expectException(LockedException::class); $this->instance->acquireLock('foo', ILockingProvider::LOCK_SHARED); $this->instance->changeLock('foo', ILockingProvider::LOCK_SHARED); } - public function testReleaseNonExistingShared() { + public function testReleaseNonExistingShared(): void { $this->instance->acquireLock('foo', ILockingProvider::LOCK_SHARED); $this->instance->releaseLock('foo', ILockingProvider::LOCK_SHARED); diff --git a/tests/lib/Lock/MemcacheLockingProviderTest.php b/tests/lib/Lock/MemcacheLockingProviderTest.php index b67be799d59..ea7b3c26b3c 100644 --- a/tests/lib/Lock/MemcacheLockingProviderTest.php +++ b/tests/lib/Lock/MemcacheLockingProviderTest.php @@ -1,40 +1,33 @@ <?php + /** - * @author Robin Appelman <icewind@owncloud.com> - * - * @copyright Copyright (c) 2015, ownCloud, Inc. - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program 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, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * + * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only */ namespace Test\Lock; +use OC\Lock\MemcacheLockingProvider; use OC\Memcache\ArrayCache; +use OCP\AppFramework\Utility\ITimeFactory; +use OCP\IMemcache; +use OCP\Lock\ILockingProvider; +use OCP\Server; class MemcacheLockingProviderTest extends LockingProvider { /** - * @var \OCP\IMemcache + * @var IMemcache */ private $memcache; /** - * @return \OCP\Lock\ILockingProvider + * @return ILockingProvider */ protected function getInstance() { $this->memcache = new ArrayCache(); - return new \OC\Lock\MemcacheLockingProvider($this->memcache); + $timeProvider = Server::get(ITimeFactory::class); + return new MemcacheLockingProvider($this->memcache, $timeProvider); } protected function tearDown(): void { diff --git a/tests/lib/Lock/NonCachingDBLockingProviderTest.php b/tests/lib/Lock/NonCachingDBLockingProviderTest.php index 349a175b566..4f05f0ba892 100644 --- a/tests/lib/Lock/NonCachingDBLockingProviderTest.php +++ b/tests/lib/Lock/NonCachingDBLockingProviderTest.php @@ -1,27 +1,16 @@ <?php + /** - * @copyright Copyright (c) 2018 Robin Appelman <robin@icewind.nl> - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program 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 program. If not, see <http://www.gnu.org/licenses/>. - * + * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace Test\Lock; +use OC\Lock\DBLockingProvider; +use OCP\IDBConnection; use OCP\Lock\ILockingProvider; +use OCP\Server; /** * @group DB @@ -30,14 +19,14 @@ use OCP\Lock\ILockingProvider; */ class NonCachingDBLockingProviderTest extends DBLockingProviderTest { /** - * @return \OCP\Lock\ILockingProvider + * @return ILockingProvider */ protected function getInstance() { - $this->connection = \OC::$server->getDatabaseConnection(); - return new \OC\Lock\DBLockingProvider($this->connection, $this->timeFactory, 3600, false); + $this->connection = Server::get(IDBConnection::class); + return new DBLockingProvider($this->connection, $this->timeFactory, 3600, false); } - public function testDoubleShared() { + public function testDoubleShared(): void { $this->instance->acquireLock('foo', ILockingProvider::LOCK_SHARED); $this->instance->acquireLock('foo', ILockingProvider::LOCK_SHARED); |