aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_external/tests/Service
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_external/tests/Service')
-rw-r--r--apps/files_external/tests/Service/BackendServiceTest.php100
-rw-r--r--apps/files_external/tests/Service/DBConfigServiceTest.php64
-rw-r--r--apps/files_external/tests/Service/GlobalStoragesServiceTest.php133
-rw-r--r--apps/files_external/tests/Service/StoragesServiceTestCase.php (renamed from apps/files_external/tests/Service/StoragesServiceTest.php)132
-rw-r--r--apps/files_external/tests/Service/UserGlobalStoragesServiceTest.php83
-rw-r--r--apps/files_external/tests/Service/UserStoragesServiceTest.php49
6 files changed, 252 insertions, 309 deletions
diff --git a/apps/files_external/tests/Service/BackendServiceTest.php b/apps/files_external/tests/Service/BackendServiceTest.php
index bda96550317..ef545688040 100644
--- a/apps/files_external/tests/Service/BackendServiceTest.php
+++ b/apps/files_external/tests/Service/BackendServiceTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -12,54 +13,45 @@ use OCA\Files_External\Lib\Backend\Backend;
use OCA\Files_External\Lib\Config\IAuthMechanismProvider;
use OCA\Files_External\Lib\Config\IBackendProvider;
use OCA\Files_External\Service\BackendService;
-use OCP\IConfig;
+use OCP\IAppConfig;
+use PHPUnit\Framework\MockObject\MockObject;
class BackendServiceTest extends \Test\TestCase {
-
- /** @var \OCP\IConfig|\PHPUnit\Framework\MockObject\MockObject */
- protected $config;
+ protected IAppConfig&MockObject $appConfig;
protected function setUp(): void {
- $this->config = $this->createMock(IConfig::class);
+ $this->appConfig = $this->createMock(IAppConfig::class);
}
/**
- * @param string $class
- *
- * @return \OCA\Files_External\Lib\Backend\Backend|\PHPUnit\Framework\MockObject\MockObject
+ * @return \OCA\Files_External\Lib\Backend\Backend&MockObject
*/
- protected function getBackendMock($class) {
- $backend = $this->getMockBuilder(Backend::class)
- ->disableOriginalConstructor()
- ->getMock();
- $backend->method('getIdentifier')->willReturn('identifier:'.$class);
- $backend->method('getIdentifierAliases')->willReturn(['identifier:'.$class]);
+ protected function getBackendMock(string $class) {
+ $backend = $this->createMock(Backend::class);
+ $backend->method('getIdentifier')->willReturn('identifier:' . $class);
+ $backend->method('getIdentifierAliases')->willReturn(['identifier:' . $class]);
return $backend;
}
/**
* @param string $class
*
- * @return \OCA\Files_External\Lib\Auth\AuthMechanism|\PHPUnit\Framework\MockObject\MockObject
+ * @return AuthMechanism&MockObject
*/
protected function getAuthMechanismMock($class) {
- $backend = $this->getMockBuilder(AuthMechanism::class)
- ->disableOriginalConstructor()
- ->getMock();
- $backend->method('getIdentifier')->willReturn('identifier:'.$class);
- $backend->method('getIdentifierAliases')->willReturn(['identifier:'.$class]);
+ $backend = $this->createMock(AuthMechanism::class);
+ $backend->method('getIdentifier')->willReturn('identifier:' . $class);
+ $backend->method('getIdentifierAliases')->willReturn(['identifier:' . $class]);
return $backend;
}
- public function testRegisterBackend() {
- $service = new BackendService($this->config);
+ public function testRegisterBackend(): void {
+ $service = new BackendService($this->appConfig);
$backend = $this->getBackendMock('\Foo\Bar');
- /** @var \OCA\Files_External\Lib\Backend\Backend|\PHPUnit\Framework\MockObject\MockObject $backendAlias */
- $backendAlias = $this->getMockBuilder(Backend::class)
- ->disableOriginalConstructor()
- ->getMock();
+ /** @var \OCA\Files_External\Lib\Backend\Backend&MockObject $backendAlias */
+ $backendAlias = $this->createMock(Backend::class);
$backendAlias->method('getIdentifierAliases')
->willReturn(['identifier_real', 'identifier_alias']);
$backendAlias->method('getIdentifier')
@@ -79,13 +71,13 @@ class BackendServiceTest extends \Test\TestCase {
$this->assertArrayNotHasKey('identifier_alias', $backends);
}
- public function testBackendProvider() {
- $service = new BackendService($this->config);
+ public function testBackendProvider(): void {
+ $service = new BackendService($this->appConfig);
$backend1 = $this->getBackendMock('\Foo\Bar');
$backend2 = $this->getBackendMock('\Bar\Foo');
- /** @var IBackendProvider|\PHPUnit\Framework\MockObject\MockObject $providerMock */
+ /** @var IBackendProvider&MockObject $providerMock */
$providerMock = $this->createMock(IBackendProvider::class);
$providerMock->expects($this->once())
->method('getBackends')
@@ -98,13 +90,13 @@ class BackendServiceTest extends \Test\TestCase {
$this->assertCount(2, $service->getBackends());
}
- public function testAuthMechanismProvider() {
- $service = new BackendService($this->config);
+ public function testAuthMechanismProvider(): void {
+ $service = new BackendService($this->appConfig);
$backend1 = $this->getAuthMechanismMock('\Foo\Bar');
$backend2 = $this->getAuthMechanismMock('\Bar\Foo');
- /** @var IAuthMechanismProvider|\PHPUnit\Framework\MockObject\MockObject $providerMock */
+ /** @var IAuthMechanismProvider&MockObject $providerMock */
$providerMock = $this->createMock(IAuthMechanismProvider::class);
$providerMock->expects($this->once())
->method('getAuthMechanisms')
@@ -117,21 +109,21 @@ class BackendServiceTest extends \Test\TestCase {
$this->assertCount(2, $service->getAuthMechanisms());
}
- public function testMultipleBackendProviders() {
- $service = new BackendService($this->config);
+ public function testMultipleBackendProviders(): void {
+ $service = new BackendService($this->appConfig);
$backend1a = $this->getBackendMock('\Foo\Bar');
$backend1b = $this->getBackendMock('\Bar\Foo');
$backend2 = $this->getBackendMock('\Dead\Beef');
- /** @var IBackendProvider|\PHPUnit\Framework\MockObject\MockObject $provider1Mock */
+ /** @var IBackendProvider&MockObject $provider1Mock */
$provider1Mock = $this->createMock(IBackendProvider::class);
$provider1Mock->expects($this->once())
->method('getBackends')
->willReturn([$backend1a, $backend1b]);
$service->registerBackendProvider($provider1Mock);
- /** @var IBackendProvider|\PHPUnit\Framework\MockObject\MockObject $provider2Mock */
+ /** @var IBackendProvider&MockObject $provider2Mock */
$provider2Mock = $this->createMock(IBackendProvider::class);
$provider2Mock->expects($this->once())
->method('getBackends')
@@ -145,15 +137,17 @@ class BackendServiceTest extends \Test\TestCase {
$this->assertCount(3, $service->getBackends());
}
- public function testUserMountingBackends() {
- $this->config->expects($this->exactly(2))
- ->method('getAppValue')
- ->willReturnMap([
- ['files_external', 'allow_user_mounting', 'yes', 'yes'],
- ['files_external', 'user_mounting_backends', '', 'identifier:\User\Mount\Allowed,identifier_alias']
- ]);
+ public function testUserMountingBackends(): void {
+ $this->appConfig->expects($this->once())
+ ->method('getValueString')
+ ->with('files_external', 'user_mounting_backends')
+ ->willReturn('identifier:\User\Mount\Allowed,identifier_alias');
+ $this->appConfig->expects($this->once())
+ ->method('getValueBool')
+ ->with('files_external', 'allow_user_mounting')
+ ->willReturn(true);
- $service = new BackendService($this->config);
+ $service = new BackendService($this->appConfig);
$backendAllowed = $this->getBackendMock('\User\Mount\Allowed');
$backendAllowed->expects($this->never())
@@ -176,8 +170,8 @@ class BackendServiceTest extends \Test\TestCase {
$service->registerBackend($backendAlias);
}
- public function testGetAvailableBackends() {
- $service = new BackendService($this->config);
+ public function testGetAvailableBackends(): void {
+ $service = new BackendService($this->appConfig);
$backendAvailable = $this->getBackendMock('\Backend\Available');
$backendAvailable->expects($this->once())
@@ -200,7 +194,7 @@ class BackendServiceTest extends \Test\TestCase {
$this->assertArrayNotHasKey('identifier:\Backend\NotAvailable', $availableBackends);
}
- public function invalidConfigPlaceholderProvider() {
+ public static function invalidConfigPlaceholderProvider(): array {
return [
[['@user']],
[['$user']],
@@ -214,13 +208,11 @@ class BackendServiceTest extends \Test\TestCase {
];
}
- /**
- * @dataProvider invalidConfigPlaceholderProvider
- */
- public function testRegisterConfigHandlerInvalid(array $placeholders) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('invalidConfigPlaceholderProvider')]
+ public function testRegisterConfigHandlerInvalid(array $placeholders): void {
$this->expectException(\RuntimeException::class);
- $service = new BackendService($this->config);
+ $service = new BackendService($this->appConfig);
$mock = $this->createMock(IConfigHandler::class);
$cb = function () use ($mock) {
return $mock;
@@ -230,8 +222,8 @@ class BackendServiceTest extends \Test\TestCase {
}
}
- public function testConfigHandlers() {
- $service = new BackendService($this->config);
+ public function testConfigHandlers(): void {
+ $service = new BackendService($this->appConfig);
$mock = $this->createMock(IConfigHandler::class);
$mock->expects($this->exactly(3))
->method('handle');
diff --git a/apps/files_external/tests/Service/DBConfigServiceTest.php b/apps/files_external/tests/Service/DBConfigServiceTest.php
index 1c2cafc93f0..85d8b70fda7 100644
--- a/apps/files_external/tests/Service/DBConfigServiceTest.php
+++ b/apps/files_external/tests/Service/DBConfigServiceTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -8,28 +10,23 @@ namespace OCA\Files_External\Tests\Service;
use OCA\Files_External\Service\DBConfigService;
use OCP\IDBConnection;
+use OCP\Security\ICrypto;
+use OCP\Server;
use Test\TestCase;
/**
* @group DB
*/
class DBConfigServiceTest extends TestCase {
- /**
- * @var DBConfigService
- */
- private $dbConfig;
-
- /**
- * @var IDBConnection
- */
- private $connection;
+ private IDBConnection $connection;
+ private DBConfigService $dbConfig;
- private $mounts = [];
+ private array $mounts = [];
protected function setUp(): void {
parent::setUp();
- $this->connection = \OC::$server->getDatabaseConnection();
- $this->dbConfig = new DBConfigService($this->connection, \OC::$server->getCrypto());
+ $this->connection = Server::get(IDBConnection::class);
+ $this->dbConfig = new DBConfigService($this->connection, Server::get(ICrypto::class));
}
protected function tearDown(): void {
@@ -37,15 +34,16 @@ class DBConfigServiceTest extends TestCase {
$this->dbConfig->removeMount($mount);
}
$this->mounts = [];
+ parent::tearDown();
}
- private function addMount($mountPoint, $storageBackend, $authBackend, $priority, $type) {
+ private function addMount(string $mountPoint, string $storageBackend, string $authBackend, int $priority, int $type) {
$id = $this->dbConfig->addMount($mountPoint, $storageBackend, $authBackend, $priority, $type);
$this->mounts[] = $id;
return $id;
}
- public function testAddSimpleMount() {
+ public function testAddSimpleMount(): void {
$id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
$mount = $this->dbConfig->getMountById($id);
@@ -59,7 +57,7 @@ class DBConfigServiceTest extends TestCase {
$this->assertEquals([], $mount['options']);
}
- public function testAddApplicable() {
+ public function testAddApplicable(): void {
$id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
$this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, 'test');
@@ -72,14 +70,14 @@ class DBConfigServiceTest extends TestCase {
$this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_GLOBAL, null);
$mount = $this->dbConfig->getMountById($id);
- $this->assertEquals([
+ $this->assertEqualsCanonicalizing([
['type' => DBConfigService::APPLICABLE_TYPE_USER, 'value' => 'test', 'mount_id' => $id],
['type' => DBConfigService::APPLICABLE_TYPE_GROUP, 'value' => 'bar', 'mount_id' => $id],
['type' => DBConfigService::APPLICABLE_TYPE_GLOBAL, 'value' => null, 'mount_id' => $id]
], $mount['applicable']);
}
- public function testAddApplicableDouble() {
+ public function testAddApplicableDouble(): void {
$id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
$this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, 'test');
$this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, 'test');
@@ -90,7 +88,7 @@ class DBConfigServiceTest extends TestCase {
], $mount['applicable']);
}
- public function testDeleteMount() {
+ public function testDeleteMount(): void {
$id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
$this->dbConfig->removeMount($id);
@@ -99,7 +97,7 @@ class DBConfigServiceTest extends TestCase {
$this->assertEquals(null, $mount);
}
- public function testRemoveApplicable() {
+ public function testRemoveApplicable(): void {
$id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
$this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, 'test');
$this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, 'test');
@@ -108,7 +106,7 @@ class DBConfigServiceTest extends TestCase {
$this->assertEquals([], $mount['applicable']);
}
- public function testRemoveApplicableGlobal() {
+ public function testRemoveApplicableGlobal(): void {
$id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
$this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_GLOBAL, null);
$this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_GLOBAL, null);
@@ -120,7 +118,7 @@ class DBConfigServiceTest extends TestCase {
], $mount['applicable']);
}
- public function testSetConfig() {
+ public function testSetConfig(): void {
$id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
$this->dbConfig->setConfig($id, 'foo', 'bar');
@@ -133,7 +131,7 @@ class DBConfigServiceTest extends TestCase {
$this->assertEquals(['foo' => 'bar', 'foo2' => 'bar2'], $mount['config']);
}
- public function testSetConfigOverwrite() {
+ public function testSetConfigOverwrite(): void {
$id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
$this->dbConfig->setConfig($id, 'foo', 'bar');
$this->dbConfig->setConfig($id, 'asd', '1');
@@ -143,7 +141,7 @@ class DBConfigServiceTest extends TestCase {
$this->assertEquals(['foo' => 'qwerty', 'asd' => '1'], $mount['config']);
}
- public function testSetOption() {
+ public function testSetOption(): void {
$id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
$this->dbConfig->setOption($id, 'foo', 'bar');
@@ -156,7 +154,7 @@ class DBConfigServiceTest extends TestCase {
$this->assertEquals(['foo' => 'bar', 'foo2' => 'bar2'], $mount['options']);
}
- public function testSetOptionOverwrite() {
+ public function testSetOptionOverwrite(): void {
$id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
$this->dbConfig->setOption($id, 'foo', 'bar');
$this->dbConfig->setOption($id, 'asd', '1');
@@ -166,7 +164,7 @@ class DBConfigServiceTest extends TestCase {
$this->assertEquals(['foo' => 'qwerty', 'asd' => '1'], $mount['options']);
}
- public function testGetMountsFor() {
+ public function testGetMountsFor(): void {
$mounts = $this->dbConfig->getMountsFor(DBConfigService::APPLICABLE_TYPE_USER, 'test');
$this->assertEquals([], $mounts);
@@ -179,7 +177,7 @@ class DBConfigServiceTest extends TestCase {
$this->assertEquals([['type' => DBConfigService::APPLICABLE_TYPE_USER, 'value' => 'test', 'mount_id' => $id]], $mounts[0]['applicable']);
}
- public function testGetAdminMounts() {
+ public function testGetAdminMounts(): void {
$id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
$this->addMount('/test2', 'foo2', 'bar2', 100, DBConfigService::MOUNT_TYPE_PERSONAL);
@@ -188,7 +186,7 @@ class DBConfigServiceTest extends TestCase {
$this->assertEquals($id1, $mounts[0]['mount_id']);
}
- public function testGetAdminMountsFor() {
+ public function testGetAdminMountsFor(): void {
$id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
$this->addMount('/test2', 'foo2', 'bar2', 100, DBConfigService::MOUNT_TYPE_ADMIN);
$id3 = $this->addMount('/test3', 'foo3', 'bar3', 100, DBConfigService::MOUNT_TYPE_PERSONAL);
@@ -202,7 +200,7 @@ class DBConfigServiceTest extends TestCase {
$this->assertEquals([['type' => DBConfigService::APPLICABLE_TYPE_USER, 'value' => 'test', 'mount_id' => $id1]], $mounts[0]['applicable']);
}
- public function testGetUserMountsFor() {
+ public function testGetUserMountsFor(): void {
$id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
$this->addMount('/test2', 'foo2', 'bar2', 100, DBConfigService::MOUNT_TYPE_PERSONAL);
$id3 = $this->addMount('/test3', 'foo3', 'bar3', 100, DBConfigService::MOUNT_TYPE_PERSONAL);
@@ -216,7 +214,7 @@ class DBConfigServiceTest extends TestCase {
$this->assertEquals([['type' => DBConfigService::APPLICABLE_TYPE_USER, 'value' => 'test', 'mount_id' => $id3]], $mounts[0]['applicable']);
}
- public function testGetAdminMountsForGlobal() {
+ public function testGetAdminMountsForGlobal(): void {
$id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
$this->dbConfig->addApplicable($id1, DBConfigService::APPLICABLE_TYPE_GLOBAL, null);
@@ -227,7 +225,7 @@ class DBConfigServiceTest extends TestCase {
$this->assertEquals([['type' => DBConfigService::APPLICABLE_TYPE_GLOBAL, 'value' => null, 'mount_id' => $id1]], $mounts[0]['applicable']);
}
- public function testSetMountPoint() {
+ public function testSetMountPoint(): void {
$id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
$id2 = $this->addMount('/foo', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
@@ -241,7 +239,7 @@ class DBConfigServiceTest extends TestCase {
$this->assertEquals('/foo', $mount['mount_point']);
}
- public function testSetAuthBackend() {
+ public function testSetAuthBackend(): void {
$id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
$id2 = $this->addMount('/foo', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
@@ -255,7 +253,7 @@ class DBConfigServiceTest extends TestCase {
$this->assertEquals('bar', $mount['auth_backend']);
}
- public function testGetMountsForDuplicateByGroup() {
+ public function testGetMountsForDuplicateByGroup(): void {
$id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
$this->dbConfig->addApplicable($id1, DBConfigService::APPLICABLE_TYPE_GROUP, 'group1');
@@ -266,7 +264,7 @@ class DBConfigServiceTest extends TestCase {
$this->assertEquals($id1, $mounts[0]['mount_id']);
}
- public function testGetAllMounts() {
+ public function testGetAllMounts(): void {
$id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
$id2 = $this->addMount('/test2', 'foo2', 'bar2', 100, DBConfigService::MOUNT_TYPE_PERSONAL);
diff --git a/apps/files_external/tests/Service/GlobalStoragesServiceTest.php b/apps/files_external/tests/Service/GlobalStoragesServiceTest.php
index 18fd9d174f2..0a3749981c8 100644
--- a/apps/files_external/tests/Service/GlobalStoragesServiceTest.php
+++ b/apps/files_external/tests/Service/GlobalStoragesServiceTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -7,13 +9,14 @@
namespace OCA\Files_External\Tests\Service;
use OC\Files\Filesystem;
+use OCA\Files_External\MountConfig;
use OCA\Files_External\Service\GlobalStoragesService;
/**
* @group DB
*/
-class GlobalStoragesServiceTest extends StoragesServiceTest {
+class GlobalStoragesServiceTest extends StoragesServiceTestCase {
protected function setUp(): void {
parent::setUp();
$this->service = new GlobalStoragesService($this->backendService, $this->dbConfig, $this->mountCache, $this->eventDispatcher);
@@ -43,7 +46,7 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
]);
}
- public function storageDataProvider() {
+ public static function storageDataProvider(): array {
return [
// all users
[
@@ -112,10 +115,8 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
];
}
- /**
- * @dataProvider storageDataProvider
- */
- public function testAddStorage($storageParams) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('storageDataProvider')]
+ public function testAddStorage($storageParams): void {
$storage = $this->makeStorageConfig($storageParams);
$newStorage = $this->service->addStorage($storage);
@@ -136,10 +137,8 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
$this->assertEquals($baseId + 1, $nextStorage->getId());
}
- /**
- * @dataProvider storageDataProvider
- */
- public function testUpdateStorage($updatedStorageParams) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('storageDataProvider')]
+ public function testUpdateStorage($updatedStorageParams): void {
$updatedStorage = $this->makeStorageConfig($updatedStorageParams);
$storage = $this->makeStorageConfig([
'mountPoint' => 'mountpoint',
@@ -165,13 +164,13 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
$this->assertEquals($updatedStorage->getMountPoint(), $newStorage->getMountPoint());
$this->assertEquals($updatedStorage->getBackendOptions()['password'], $newStorage->getBackendOptions()['password']);
- $this->assertEquals($updatedStorage->getApplicableUsers(), $newStorage->getApplicableUsers());
+ $this->assertEqualsCanonicalizing($updatedStorage->getApplicableUsers(), $newStorage->getApplicableUsers());
$this->assertEquals($updatedStorage->getApplicableGroups(), $newStorage->getApplicableGroups());
$this->assertEquals($updatedStorage->getPriority(), $newStorage->getPriority());
$this->assertEquals(0, $newStorage->getStatus());
}
- public function hooksAddStorageDataProvider() {
+ public static function hooksAddStorageDataProvider(): array {
return [
// applicable all
[
@@ -181,7 +180,7 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
[
[
Filesystem::signal_create_mount,
- \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
+ MountConfig::MOUNT_TYPE_USER,
'all'
],
],
@@ -194,7 +193,7 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
[
[
Filesystem::signal_create_mount,
- \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
+ MountConfig::MOUNT_TYPE_USER,
'user1',
],
],
@@ -207,7 +206,7 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
[
[
Filesystem::signal_create_mount,
- \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
+ MountConfig::MOUNT_TYPE_GROUP,
'group1',
],
],
@@ -219,12 +218,12 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
[
[
Filesystem::signal_create_mount,
- \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
+ MountConfig::MOUNT_TYPE_USER,
'user1',
],
[
Filesystem::signal_create_mount,
- \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
+ MountConfig::MOUNT_TYPE_USER,
'user2',
],
],
@@ -237,12 +236,12 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
[
[
Filesystem::signal_create_mount,
- \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
+ MountConfig::MOUNT_TYPE_GROUP,
'group1'
],
[
Filesystem::signal_create_mount,
- \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
+ MountConfig::MOUNT_TYPE_GROUP,
'group2'
],
],
@@ -255,22 +254,22 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
[
[
Filesystem::signal_create_mount,
- \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
+ MountConfig::MOUNT_TYPE_USER,
'user1',
],
[
Filesystem::signal_create_mount,
- \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
+ MountConfig::MOUNT_TYPE_USER,
'user2',
],
[
Filesystem::signal_create_mount,
- \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
+ MountConfig::MOUNT_TYPE_GROUP,
'group1'
],
[
Filesystem::signal_create_mount,
- \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
+ MountConfig::MOUNT_TYPE_GROUP,
'group2'
],
],
@@ -278,10 +277,8 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
];
}
- /**
- * @dataProvider hooksAddStorageDataProvider
- */
- public function testHooksAddStorage($applicableUsers, $applicableGroups, $expectedCalls) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('hooksAddStorageDataProvider')]
+ public function testHooksAddStorage($applicableUsers, $applicableGroups, $expectedCalls): void {
$storage = $this->makeTestStorageData();
$storage->setApplicableUsers($applicableUsers);
$storage->setApplicableGroups($applicableGroups);
@@ -300,7 +297,7 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
}
}
- public function hooksUpdateStorageDataProvider() {
+ public static function hooksUpdateStorageDataProvider(): array {
return [
[
// nothing to multiple users and groups
@@ -313,27 +310,27 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
// delete the "all entry"
[
Filesystem::signal_delete_mount,
- \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
+ MountConfig::MOUNT_TYPE_USER,
'all',
],
[
Filesystem::signal_create_mount,
- \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
+ MountConfig::MOUNT_TYPE_USER,
'user1',
],
[
Filesystem::signal_create_mount,
- \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
+ MountConfig::MOUNT_TYPE_USER,
'user2',
],
[
Filesystem::signal_create_mount,
- \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
+ MountConfig::MOUNT_TYPE_GROUP,
'group1'
],
[
Filesystem::signal_create_mount,
- \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
+ MountConfig::MOUNT_TYPE_GROUP,
'group2'
],
],
@@ -348,12 +345,12 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
[
[
Filesystem::signal_create_mount,
- \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
+ MountConfig::MOUNT_TYPE_USER,
'user2',
],
[
Filesystem::signal_create_mount,
- \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
+ MountConfig::MOUNT_TYPE_GROUP,
'group2'
],
],
@@ -368,12 +365,12 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
[
[
Filesystem::signal_delete_mount,
- \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
+ MountConfig::MOUNT_TYPE_USER,
'user2',
],
[
Filesystem::signal_delete_mount,
- \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
+ MountConfig::MOUNT_TYPE_GROUP,
'group2'
],
],
@@ -388,18 +385,18 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
[
[
Filesystem::signal_delete_mount,
- \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
+ MountConfig::MOUNT_TYPE_USER,
'user1',
],
[
Filesystem::signal_delete_mount,
- \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
+ MountConfig::MOUNT_TYPE_GROUP,
'group1'
],
// create the "all" entry
[
Filesystem::signal_create_mount,
- \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
+ MountConfig::MOUNT_TYPE_USER,
'all'
],
],
@@ -416,15 +413,14 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
];
}
- /**
- * @dataProvider hooksUpdateStorageDataProvider
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('hooksUpdateStorageDataProvider')]
public function testHooksUpdateStorage(
- $sourceApplicableUsers,
- $sourceApplicableGroups,
- $updatedApplicableUsers,
- $updatedApplicableGroups,
- $expectedCalls) {
+ array $sourceApplicableUsers,
+ array $sourceApplicableGroups,
+ array $updatedApplicableUsers,
+ array $updatedApplicableGroups,
+ array $expectedCalls,
+ ): void {
$storage = $this->makeTestStorageData();
$storage->setApplicableUsers($sourceApplicableUsers);
$storage->setApplicableGroups($sourceApplicableGroups);
@@ -452,7 +448,7 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
}
- public function testHooksRenameMountPoint() {
+ public function testHooksRenameMountPoint(): void {
$storage = $this->makeTestStorageData();
$storage->setApplicableUsers(['user1', 'user2']);
$storage->setApplicableGroups(['group1', 'group2']);
@@ -470,50 +466,50 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
[
Filesystem::signal_delete_mount,
'/mountpoint',
- \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
+ MountConfig::MOUNT_TYPE_USER,
'user1',
],
[
Filesystem::signal_delete_mount,
'/mountpoint',
- \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
+ MountConfig::MOUNT_TYPE_USER,
'user2',
],
[
Filesystem::signal_delete_mount,
'/mountpoint',
- \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
+ MountConfig::MOUNT_TYPE_GROUP,
'group1',
],
[
Filesystem::signal_delete_mount,
'/mountpoint',
- \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
+ MountConfig::MOUNT_TYPE_GROUP,
'group2',
],
// creates new one
[
Filesystem::signal_create_mount,
'/renamedMountpoint',
- \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
+ MountConfig::MOUNT_TYPE_USER,
'user1',
],
[
Filesystem::signal_create_mount,
'/renamedMountpoint',
- \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
+ MountConfig::MOUNT_TYPE_USER,
'user2',
],
[
Filesystem::signal_create_mount,
'/renamedMountpoint',
- \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
+ MountConfig::MOUNT_TYPE_GROUP,
'group1',
],
[
Filesystem::signal_create_mount,
'/renamedMountpoint',
- \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
+ MountConfig::MOUNT_TYPE_GROUP,
'group2',
],
];
@@ -531,7 +527,7 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
}
}
- public function hooksDeleteStorageDataProvider() {
+ public static function hooksDeleteStorageDataProvider(): array {
return [
[
['user1', 'user2'],
@@ -540,22 +536,22 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
[
[
Filesystem::signal_delete_mount,
- \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
+ MountConfig::MOUNT_TYPE_USER,
'user1',
],
[
Filesystem::signal_delete_mount,
- \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
+ MountConfig::MOUNT_TYPE_USER,
'user2',
],
[
Filesystem::signal_delete_mount,
- \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
+ MountConfig::MOUNT_TYPE_GROUP,
'group1'
],
[
Filesystem::signal_delete_mount,
- \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
+ MountConfig::MOUNT_TYPE_GROUP,
'group2'
],
],
@@ -567,7 +563,7 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
[
[
Filesystem::signal_delete_mount,
- \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
+ MountConfig::MOUNT_TYPE_USER,
'all',
],
],
@@ -575,13 +571,12 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
];
}
- /**
- * @dataProvider hooksDeleteStorageDataProvider
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('hooksDeleteStorageDataProvider')]
public function testHooksDeleteStorage(
- $sourceApplicableUsers,
- $sourceApplicableGroups,
- $expectedCalls) {
+ array $sourceApplicableUsers,
+ array $sourceApplicableGroups,
+ array $expectedCalls,
+ ): void {
$storage = $this->makeTestStorageData();
$storage->setApplicableUsers($sourceApplicableUsers);
$storage->setApplicableGroups($sourceApplicableGroups);
diff --git a/apps/files_external/tests/Service/StoragesServiceTest.php b/apps/files_external/tests/Service/StoragesServiceTestCase.php
index 705d5fa276f..b41eb409468 100644
--- a/apps/files_external/tests/Service/StoragesServiceTest.php
+++ b/apps/files_external/tests/Service/StoragesServiceTestCase.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -6,13 +8,16 @@
*/
namespace OCA\Files_External\Tests\Service;
+use OC\Files\Cache\Storage;
use OC\Files\Filesystem;
-
use OCA\Files_External\Lib\Auth\AuthMechanism;
use OCA\Files_External\Lib\Auth\InvalidAuth;
+use OCA\Files_External\Lib\Auth\NullMechanism;
use OCA\Files_External\Lib\Backend\Backend;
use OCA\Files_External\Lib\Backend\InvalidBackend;
+use OCA\Files_External\Lib\Backend\SMB;
use OCA\Files_External\Lib\StorageConfig;
+use OCA\Files_External\MountConfig;
use OCA\Files_External\NotFoundException;
use OCA\Files_External\Service\BackendService;
use OCA\Files_External\Service\DBConfigService;
@@ -23,12 +28,16 @@ use OCP\Files\Cache\ICache;
use OCP\Files\Config\IUserMountCache;
use OCP\Files\Mount\IMountPoint;
use OCP\Files\Storage\IStorage;
+use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IUser;
+use OCP\Security\ICrypto;
use OCP\Server;
+use OCP\Util;
+use PHPUnit\Framework\MockObject\MockObject;
class CleaningDBConfig extends DBConfigService {
- private $mountIds = [];
+ private array $mountIds = [];
public function addMount($mountPoint, $storageBackend, $authBackend, $priority, $type) {
$id = parent::addMount($mountPoint, $storageBackend, $authBackend, $priority, $type); // TODO: Change the autogenerated stub
@@ -46,61 +55,31 @@ class CleaningDBConfig extends DBConfigService {
/**
* @group DB
*/
-abstract class StoragesServiceTest extends \Test\TestCase {
- /**
- * @var StoragesService
- */
- protected $service;
-
- /** @var BackendService */
- protected $backendService;
-
- /**
- * Data directory
- *
- * @var string
- */
- protected $dataDir;
-
- /** @var CleaningDBConfig */
- protected $dbConfig;
-
- /**
- * Hook calls
- *
- * @var array
- */
- protected static $hookCalls;
-
- /**
- * @var \PHPUnit\Framework\MockObject\MockObject|\OCP\Files\Config\IUserMountCache
- */
- protected $mountCache;
-
- /**
- * @var \PHPUnit\Framework\MockObject\MockObject|IEventDispatcher
- */
- protected IEventDispatcher $eventDispatcher;
+abstract class StoragesServiceTestCase extends \Test\TestCase {
+ protected StoragesService $service;
+ protected BackendService $backendService;
+ protected string $dataDir;
+ protected CleaningDBConfig $dbConfig;
+ protected static array $hookCalls;
+ protected IUserMountCache&MockObject $mountCache;
+ protected IEventDispatcher&MockObject $eventDispatcher;
protected function setUp(): void {
parent::setUp();
- $this->dbConfig = new CleaningDBConfig(\OC::$server->getDatabaseConnection(), \OC::$server->getCrypto());
+ $this->dbConfig = new CleaningDBConfig(Server::get(IDBConnection::class), Server::get(ICrypto::class));
self::$hookCalls = [];
- $config = \OC::$server->getConfig();
+ $config = Server::get(IConfig::class);
$this->dataDir = $config->getSystemValue(
'datadirectory',
\OC::$SERVERROOT . '/data/'
);
- \OCA\Files_External\MountConfig::$skipTest = true;
+ MountConfig::$skipTest = true;
$this->mountCache = $this->createMock(IUserMountCache::class);
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
// prepare BackendService mock
- $this->backendService =
- $this->getMockBuilder('\OCA\Files_External\Service\BackendService')
- ->disableOriginalConstructor()
- ->getMock();
+ $this->backendService = $this->createMock(BackendService::class);
$authMechanisms = [
'identifier:\Auth\Mechanism' => $this->getAuthMechMock('null', '\Auth\Mechanism'),
@@ -143,11 +122,11 @@ abstract class StoragesServiceTest extends \Test\TestCase {
->willReturn($backends);
$this->overwriteService(BackendService::class, $this->backendService);
- \OCP\Util::connectHook(
+ Util::connectHook(
Filesystem::CLASSNAME,
Filesystem::signal_create_mount,
get_class($this), 'createHookCallback');
- \OCP\Util::connectHook(
+ Util::connectHook(
Filesystem::CLASSNAME,
Filesystem::signal_delete_mount,
get_class($this), 'deleteHookCallback');
@@ -162,17 +141,16 @@ abstract class StoragesServiceTest extends \Test\TestCase {
}
protected function tearDown(): void {
- \OCA\Files_External\MountConfig::$skipTest = false;
+ MountConfig::$skipTest = false;
self::$hookCalls = [];
if ($this->dbConfig) {
$this->dbConfig->clean();
}
+ parent::tearDown();
}
- protected function getBackendMock($class = '\OCA\Files_External\Lib\Backend\SMB', $storageClass = '\OCA\Files_External\Lib\Storage\SMB') {
- $backend = $this->getMockBuilder(Backend::class)
- ->disableOriginalConstructor()
- ->getMock();
+ protected function getBackendMock($class = SMB::class, $storageClass = \OCA\Files_External\Lib\Storage\SMB::class) {
+ $backend = $this->createMock(Backend::class);
$backend->method('getStorageClass')
->willReturn($storageClass);
$backend->method('getIdentifier')
@@ -180,10 +158,8 @@ abstract class StoragesServiceTest extends \Test\TestCase {
return $backend;
}
- protected function getAuthMechMock($scheme = 'null', $class = '\OCA\Files_External\Lib\Auth\NullMechanism') {
- $authMech = $this->getMockBuilder(AuthMechanism::class)
- ->disableOriginalConstructor()
- ->getMock();
+ protected function getAuthMechMock($scheme = 'null', $class = NullMechanism::class) {
+ $authMech = $this->createMock(AuthMechanism::class);
$authMech->method('getScheme')
->willReturn($scheme);
$authMech->method('getIdentifier')
@@ -194,12 +170,8 @@ abstract class StoragesServiceTest extends \Test\TestCase {
/**
* Creates a StorageConfig instance based on array data
- *
- * @param array $data
- *
- * @return StorageConfig storage config instance
*/
- protected function makeStorageConfig($data) {
+ protected function makeStorageConfig(array $data): StorageConfig {
$storage = new StorageConfig();
if (isset($data['id'])) {
$storage->setId($data['id']);
@@ -248,13 +220,13 @@ abstract class StoragesServiceTest extends \Test\TestCase {
$this->service->updateStorage($storage);
}
- public function testNonExistingStorage() {
- $this->expectException(\OCA\Files_External\NotFoundException::class);
+ public function testNonExistingStorage(): void {
+ $this->expectException(NotFoundException::class);
$this->ActualNonExistingStorageTest();
}
- public function deleteStorageDataProvider() {
+ public static function deleteStorageDataProvider(): array {
return [
// regular case, can properly delete the oc_storages entry
[
@@ -278,10 +250,8 @@ abstract class StoragesServiceTest extends \Test\TestCase {
];
}
- /**
- * @dataProvider deleteStorageDataProvider
- */
- public function testDeleteStorage($backendOptions, $rustyStorageId) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('deleteStorageDataProvider')]
+ public function testDeleteStorage(array $backendOptions, string $rustyStorageId): void {
$backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\DAV');
$authMechanism = $this->backendService->getAuthMechanism('identifier:\Auth\Mechanism');
$storage = new StorageConfig(255);
@@ -295,10 +265,10 @@ abstract class StoragesServiceTest extends \Test\TestCase {
// manually trigger storage entry because normally it happens on first
// access, which isn't possible within this test
- $storageCache = new \OC\Files\Cache\Storage($rustyStorageId, true, Server::get(IDBConnection::class));
+ $storageCache = new Storage($rustyStorageId, true, Server::get(IDBConnection::class));
/** @var IUserMountCache $mountCache */
- $mountCache = \OC::$server->get(IUserMountCache::class);
+ $mountCache = Server::get(IUserMountCache::class);
$mountCache->clear();
$user = $this->createMock(IUser::class);
$user->method('getUID')->willReturn('test');
@@ -337,7 +307,7 @@ abstract class StoragesServiceTest extends \Test\TestCase {
$this->assertTrue($caught);
// storage id was removed from oc_storages
- $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder();
+ $qb = Server::get(IDBConnection::class)->getQueryBuilder();
$storageCheckQuery = $qb->select('*')
->from('storages')
->where($qb->expr()->eq('numeric_id', $qb->expr()->literal($numericId)));
@@ -345,20 +315,20 @@ abstract class StoragesServiceTest extends \Test\TestCase {
$result = $storageCheckQuery->execute();
$storages = $result->fetchAll();
$result->closeCursor();
- $this->assertCount(0, $storages, "expected 0 storages, got " . json_encode($storages));
+ $this->assertCount(0, $storages, 'expected 0 storages, got ' . json_encode($storages));
}
protected function actualDeletedUnexistingStorageTest() {
$this->service->removeStorage(255);
}
- public function testDeleteUnexistingStorage() {
- $this->expectException(\OCA\Files_External\NotFoundException::class);
+ public function testDeleteUnexistingStorage(): void {
+ $this->expectException(NotFoundException::class);
$this->actualDeletedUnexistingStorageTest();
}
- public function testCreateStorage() {
+ public function testCreateStorage(): void {
$mountPoint = 'mount';
$backendIdentifier = 'identifier:\OCA\Files_External\Lib\Backend\SMB';
$authMechanismIdentifier = 'identifier:\Auth\Mechanism';
@@ -392,7 +362,7 @@ abstract class StoragesServiceTest extends \Test\TestCase {
$this->assertEquals($priority, $storage->getPriority());
}
- public function testCreateStorageInvalidClass() {
+ public function testCreateStorageInvalidClass(): void {
$storage = $this->service->createStorage(
'mount',
'identifier:\OC\Not\A\Backend',
@@ -402,7 +372,7 @@ abstract class StoragesServiceTest extends \Test\TestCase {
$this->assertInstanceOf(InvalidBackend::class, $storage->getBackend());
}
- public function testCreateStorageInvalidAuthMechanismClass() {
+ public function testCreateStorageInvalidAuthMechanismClass(): void {
$storage = $this->service->createStorage(
'mount',
'identifier:\OCA\Files_External\Lib\Backend\SMB',
@@ -412,7 +382,7 @@ abstract class StoragesServiceTest extends \Test\TestCase {
$this->assertInstanceOf(InvalidAuth::class, $storage->getAuthMechanism());
}
- public function testGetStoragesBackendNotVisible() {
+ public function testGetStoragesBackendNotVisible(): void {
$backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB');
$backend->expects($this->once())
->method('isVisibleFor')
@@ -435,7 +405,7 @@ abstract class StoragesServiceTest extends \Test\TestCase {
$this->assertEmpty($this->service->getStorages());
}
- public function testGetStoragesAuthMechanismNotVisible() {
+ public function testGetStoragesAuthMechanismNotVisible(): void {
$backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB');
$backend->method('isVisibleFor')
->with($this->service->getVisibilityType())
@@ -458,14 +428,14 @@ abstract class StoragesServiceTest extends \Test\TestCase {
$this->assertEmpty($this->service->getStorages());
}
- public static function createHookCallback($params) {
+ public static function createHookCallback($params): void {
self::$hookCalls[] = [
'signal' => Filesystem::signal_create_mount,
'params' => $params
];
}
- public static function deleteHookCallback($params) {
+ public static function deleteHookCallback($params): void {
self::$hookCalls[] = [
'signal' => Filesystem::signal_delete_mount,
'params' => $params
@@ -498,7 +468,7 @@ abstract class StoragesServiceTest extends \Test\TestCase {
);
}
- public function testUpdateStorageMountPoint() {
+ public function testUpdateStorageMountPoint(): void {
$backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB');
$authMechanism = $this->backendService->getAuthMechanism('identifier:\Auth\Mechanism');
diff --git a/apps/files_external/tests/Service/UserGlobalStoragesServiceTest.php b/apps/files_external/tests/Service/UserGlobalStoragesServiceTest.php
index e08f3bd4d7d..2a2f4596fda 100644
--- a/apps/files_external/tests/Service/UserGlobalStoragesServiceTest.php
+++ b/apps/files_external/tests/Service/UserGlobalStoragesServiceTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -6,6 +7,7 @@
*/
namespace OCA\Files_External\Tests\Service;
+use OC\User\User;
use OCA\Files_External\Lib\StorageConfig;
use OCA\Files_External\NotFoundException;
use OCA\Files_External\Service\StoragesService;
@@ -14,6 +16,8 @@ use OCP\EventDispatcher\IEventDispatcher;
use OCP\IGroupManager;
use OCP\IUser;
use OCP\IUserSession;
+use OCP\Server;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\Traits\UserTrait;
/**
@@ -22,20 +26,9 @@ use Test\Traits\UserTrait;
class UserGlobalStoragesServiceTest extends GlobalStoragesServiceTest {
use UserTrait;
- /** @var \OCP\IGroupManager|\PHPUnit\Framework\MockObject\MockObject groupManager */
- protected $groupManager;
-
- /**
- * @var StoragesService
- */
- protected $globalStoragesService;
-
- /**
- * @var UserGlobalStoragesService
- */
- protected $service;
-
- protected $user;
+ protected IGroupManager&MockObject $groupManager;
+ protected StoragesService $globalStoragesService;
+ protected User $user;
public const USER_ID = 'test_user';
public const GROUP_ID = 'test_group';
@@ -46,8 +39,8 @@ class UserGlobalStoragesServiceTest extends GlobalStoragesServiceTest {
$this->globalStoragesService = $this->service;
- $this->user = new \OC\User\User(self::USER_ID, null, \OC::$server->get(IEventDispatcher::class));
- /** @var \OCP\IUserSession|\PHPUnit\Framework\MockObject\MockObject $userSession */
+ $this->user = new User(self::USER_ID, null, Server::get(IEventDispatcher::class));
+ /** @var IUserSession&MockObject $userSession */
$userSession = $this->createMock(IUserSession::class);
$userSession
->expects($this->any())
@@ -85,7 +78,7 @@ class UserGlobalStoragesServiceTest extends GlobalStoragesServiceTest {
);
}
- public function applicableStorageProvider() {
+ public static function applicableStorageProvider(): array {
return [
[[], [], true],
@@ -105,10 +98,8 @@ class UserGlobalStoragesServiceTest extends GlobalStoragesServiceTest {
];
}
- /**
- * @dataProvider applicableStorageProvider
- */
- public function testGetStorageWithApplicable($applicableUsers, $applicableGroups, $isVisible) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('applicableStorageProvider')]
+ public function testGetStorageWithApplicable($applicableUsers, $applicableGroups, $isVisible): void {
$backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB');
$authMechanism = $this->backendService->getAuthMechanism('identifier:\Auth\Mechanism');
@@ -139,7 +130,7 @@ class UserGlobalStoragesServiceTest extends GlobalStoragesServiceTest {
}
- public function testAddStorage($storageParams = null) {
+ public function testAddStorage($storageParams = null): void {
$this->expectException(\DomainException::class);
$backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB');
@@ -155,7 +146,7 @@ class UserGlobalStoragesServiceTest extends GlobalStoragesServiceTest {
}
- public function testUpdateStorage($storageParams = null) {
+ public function testUpdateStorage($storageParams = null): void {
$this->expectException(\DomainException::class);
$backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB');
@@ -175,16 +166,14 @@ class UserGlobalStoragesServiceTest extends GlobalStoragesServiceTest {
}
- public function testNonExistingStorage() {
+ public function testNonExistingStorage(): void {
$this->expectException(\DomainException::class);
$this->ActualNonExistingStorageTest();
}
- /**
- * @dataProvider deleteStorageDataProvider
- */
- public function testDeleteStorage($backendOptions, $rustyStorageId) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('deleteStorageDataProvider')]
+ public function testDeleteStorage($backendOptions, $rustyStorageId): void {
$this->expectException(\DomainException::class);
$backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB');
@@ -203,13 +192,13 @@ class UserGlobalStoragesServiceTest extends GlobalStoragesServiceTest {
}
- public function testDeleteUnexistingStorage() {
+ public function testDeleteUnexistingStorage(): void {
$this->expectException(\DomainException::class);
$this->actualDeletedUnexistingStorageTest();
}
- public function getUniqueStoragesProvider() {
+ public static function getUniqueStoragesProvider(): array {
return [
// 'all' vs group
[100, [], [], 100, [], [self::GROUP_ID], 2],
@@ -237,14 +226,12 @@ class UserGlobalStoragesServiceTest extends GlobalStoragesServiceTest {
];
}
- /**
- * @dataProvider getUniqueStoragesProvider
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('getUniqueStoragesProvider')]
public function testGetUniqueStorages(
$priority1, $applicableUsers1, $applicableGroups1,
$priority2, $applicableUsers2, $applicableGroups2,
- $expectedPrecedence
- ) {
+ $expectedPrecedence,
+ ): void {
$backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB');
$backend->method('isVisibleFor')
->willReturn(true);
@@ -284,67 +271,67 @@ class UserGlobalStoragesServiceTest extends GlobalStoragesServiceTest {
}
}
- public function testGetStoragesBackendNotVisible() {
+ public function testGetStoragesBackendNotVisible(): void {
// we don't test this here
$this->addToAssertionCount(1);
}
- public function testGetStoragesAuthMechanismNotVisible() {
+ public function testGetStoragesAuthMechanismNotVisible(): void {
// we don't test this here
$this->addToAssertionCount(1);
}
- public function testHooksAddStorage($a = null, $b = null, $c = null) {
+ public function testHooksAddStorage($a = null, $b = null, $c = null): void {
// we don't test this here
$this->addToAssertionCount(1);
}
- public function testHooksUpdateStorage($a = null, $b = null, $c = null, $d = null, $e = null) {
+ public function testHooksUpdateStorage($a = null, $b = null, $c = null, $d = null, $e = null): void {
// we don't test this here
$this->addToAssertionCount(1);
}
- public function testHooksRenameMountPoint() {
+ public function testHooksRenameMountPoint(): void {
// we don't test this here
$this->addToAssertionCount(1);
}
- public function testHooksDeleteStorage($a = null, $b = null, $c = null) {
+ public function testHooksDeleteStorage($a = null, $b = null, $c = null): void {
// we don't test this here
$this->addToAssertionCount(1);
}
- public function testLegacyConfigConversionApplicableAll() {
+ public function testLegacyConfigConversionApplicableAll(): void {
// we don't test this here
$this->addToAssertionCount(1);
}
- public function testLegacyConfigConversionApplicableUserAndGroup() {
+ public function testLegacyConfigConversionApplicableUserAndGroup(): void {
// we don't test this here
$this->addToAssertionCount(1);
}
- public function testReadLegacyConfigAndGenerateConfigId() {
+ public function testReadLegacyConfigAndGenerateConfigId(): void {
// we don't test this here
$this->addToAssertionCount(1);
}
- public function testReadLegacyConfigNoAuthMechanism() {
+ public function testReadLegacyConfigNoAuthMechanism(): void {
// we don't test this here
$this->addToAssertionCount(1);
}
- public function testReadLegacyConfigClass() {
+ public function testReadLegacyConfigClass(): void {
// we don't test this here
$this->addToAssertionCount(1);
}
- public function testReadEmptyMountPoint() {
+ public function testReadEmptyMountPoint(): void {
// we don't test this here
$this->addToAssertionCount(1);
}
- public function testUpdateStorageMountPoint() {
+ public function testUpdateStorageMountPoint(): void {
// we don't test this here
$this->addToAssertionCount(1);
}
diff --git a/apps/files_external/tests/Service/UserStoragesServiceTest.php b/apps/files_external/tests/Service/UserStoragesServiceTest.php
index 370b34245c2..0a2f291f6e4 100644
--- a/apps/files_external/tests/Service/UserStoragesServiceTest.php
+++ b/apps/files_external/tests/Service/UserStoragesServiceTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -7,28 +8,30 @@
namespace OCA\Files_External\Tests\Service;
use OC\Files\Filesystem;
-
+use OC\User\User;
use OCA\Files_External\Lib\StorageConfig;
+use OCA\Files_External\MountConfig;
+use OCA\Files_External\NotFoundException;
use OCA\Files_External\Service\GlobalStoragesService;
+
use OCA\Files_External\Service\StoragesService;
use OCA\Files_External\Service\UserStoragesService;
+use OCP\IUserManager;
use OCP\IUserSession;
+use OCP\Server;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\Traits\UserTrait;
/**
* @group DB
*/
-class UserStoragesServiceTest extends StoragesServiceTest {
+class UserStoragesServiceTest extends StoragesServiceTestCase {
use UserTrait;
- private $user;
-
- private $userId;
+ protected User $user;
- /**
- * @var StoragesService
- */
- protected $globalStoragesService;
+ protected string $userId;
+ protected StoragesService $globalStoragesService;
protected function setUp(): void {
parent::setUp();
@@ -37,9 +40,9 @@ class UserStoragesServiceTest extends StoragesServiceTest {
$this->userId = $this->getUniqueID('user_');
$this->createUser($this->userId, $this->userId);
- $this->user = \OC::$server->getUserManager()->get($this->userId);
+ $this->user = Server::get(IUserManager::class)->get($this->userId);
- /** @var \OCP\IUserSession|\PHPUnit\Framework\MockObject\MockObject $userSession */
+ /** @var IUserSession&MockObject $userSession */
$userSession = $this->createMock(IUserSession::class);
$userSession
->expects($this->any())
@@ -65,7 +68,7 @@ class UserStoragesServiceTest extends StoragesServiceTest {
]);
}
- public function testAddStorage() {
+ public function testAddStorage(): void {
$storage = $this->makeTestStorageData();
$newStorage = $this->service->addStorage($storage);
@@ -85,7 +88,7 @@ class UserStoragesServiceTest extends StoragesServiceTest {
current(self::$hookCalls),
Filesystem::signal_create_mount,
$storage->getMountPoint(),
- \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
+ MountConfig::MOUNT_TYPE_USER,
$this->userId
);
@@ -93,7 +96,7 @@ class UserStoragesServiceTest extends StoragesServiceTest {
$this->assertEquals($id + 1, $nextStorage->getId());
}
- public function testUpdateStorage() {
+ public function testUpdateStorage(): void {
$storage = $this->makeStorageConfig([
'mountPoint' => 'mountpoint',
'backendIdentifier' => 'identifier:\OCA\Files_External\Lib\Backend\SMB',
@@ -125,10 +128,8 @@ class UserStoragesServiceTest extends StoragesServiceTest {
$this->assertEmpty(self::$hookCalls);
}
- /**
- * @dataProvider deleteStorageDataProvider
- */
- public function testDeleteStorage($backendOptions, $rustyStorageId) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('deleteStorageDataProvider')]
+ public function testDeleteStorage($backendOptions, $rustyStorageId): void {
parent::testDeleteStorage($backendOptions, $rustyStorageId);
// hook called once for user (first one was during test creation)
@@ -136,12 +137,12 @@ class UserStoragesServiceTest extends StoragesServiceTest {
self::$hookCalls[1],
Filesystem::signal_delete_mount,
'/mountpoint',
- \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
+ MountConfig::MOUNT_TYPE_USER,
$this->userId
);
}
- public function testHooksRenameMountPoint() {
+ public function testHooksRenameMountPoint(): void {
$storage = $this->makeTestStorageData();
$storage = $this->service->addStorage($storage);
@@ -157,21 +158,21 @@ class UserStoragesServiceTest extends StoragesServiceTest {
self::$hookCalls[0],
Filesystem::signal_delete_mount,
'/mountpoint',
- \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
+ MountConfig::MOUNT_TYPE_USER,
$this->userId
);
$this->assertHookCall(
self::$hookCalls[1],
Filesystem::signal_create_mount,
'/renamedMountpoint',
- \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
+ MountConfig::MOUNT_TYPE_USER,
$this->userId
);
}
- public function testGetAdminStorage() {
- $this->expectException(\OCA\Files_External\NotFoundException::class);
+ public function testGetAdminStorage(): void {
+ $this->expectException(NotFoundException::class);
$backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB');
$authMechanism = $this->backendService->getAuthMechanism('identifier:\Auth\Mechanism');