aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_external/tests/Controller
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_external/tests/Controller')
-rw-r--r--apps/files_external/tests/Controller/AjaxControllerTest.php32
-rw-r--r--apps/files_external/tests/Controller/GlobalStoragesControllerTest.php9
-rw-r--r--apps/files_external/tests/Controller/StoragesControllerTestCase.php (renamed from apps/files_external/tests/Controller/StoragesControllerTest.php)72
-rw-r--r--apps/files_external/tests/Controller/UserStoragesControllerTest.php18
4 files changed, 59 insertions, 72 deletions
diff --git a/apps/files_external/tests/Controller/AjaxControllerTest.php b/apps/files_external/tests/Controller/AjaxControllerTest.php
index 005e6e9714c..b1ea7a2b1b1 100644
--- a/apps/files_external/tests/Controller/AjaxControllerTest.php
+++ b/apps/files_external/tests/Controller/AjaxControllerTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -14,32 +16,22 @@ use OCP\IL10N;
use OCP\IRequest;
use OCP\IUser;
use OCP\IUserSession;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class AjaxControllerTest extends TestCase {
- /** @var IRequest */
- private $request;
- /** @var RSA */
- private $rsa;
- /** @var GlobalAuth */
- private $globalAuth;
- /** @var IUserSession */
- private $userSession;
- /** @var IGroupManager */
- private $groupManager;
- /** @var AjaxController */
- private $ajaxController;
- /** @var IL10N */
- private $l10n;
+ private IRequest&MockObject $request;
+ private RSA&MockObject $rsa;
+ private GlobalAuth&MockObject $globalAuth;
+ private IUserSession&MockObject $userSession;
+ private IGroupManager&MockObject $groupManager;
+ private IL10N&MockObject $l10n;
+ private AjaxController $ajaxController;
protected function setUp(): void {
$this->request = $this->createMock(IRequest::class);
- $this->rsa = $this->getMockBuilder('\\OCA\\Files_External\\Lib\\Auth\\PublicKey\\RSA')
- ->disableOriginalConstructor()
- ->getMock();
- $this->globalAuth = $this->getMockBuilder('\\OCA\\Files_External\\Lib\\Auth\\Password\GlobalAuth')
- ->disableOriginalConstructor()
- ->getMock();
+ $this->rsa = $this->createMock(RSA::class);
+ $this->globalAuth = $this->createMock(GlobalAuth::class);
$this->userSession = $this->createMock(IUserSession::class);
$this->groupManager = $this->createMock(IGroupManager::class);
$this->l10n = $this->createMock(IL10N::class);
diff --git a/apps/files_external/tests/Controller/GlobalStoragesControllerTest.php b/apps/files_external/tests/Controller/GlobalStoragesControllerTest.php
index 4c318951d1b..2edc3ea3efc 100644
--- a/apps/files_external/tests/Controller/GlobalStoragesControllerTest.php
+++ b/apps/files_external/tests/Controller/GlobalStoragesControllerTest.php
@@ -9,6 +9,7 @@ namespace OCA\Files_External\Tests\Controller;
use OC\User\User;
use OCA\Files_External\Controller\GlobalStoragesController;
use OCA\Files_External\Service\BackendService;
+use OCA\Files_External\Service\GlobalStoragesService;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
use OCP\IGroupManager;
@@ -17,13 +18,11 @@ use OCP\IRequest;
use OCP\IUserSession;
use Psr\Log\LoggerInterface;
-class GlobalStoragesControllerTest extends StoragesControllerTest {
+class GlobalStoragesControllerTest extends StoragesControllerTestCase {
protected function setUp(): void {
parent::setUp();
- $this->service = $this->getMockBuilder('\OCA\Files_External\Service\GlobalStoragesService')
- ->disableOriginalConstructor()
- ->getMock();
+ $this->service = $this->createMock(GlobalStoragesService::class);
$this->service->method('getVisibilityType')
->willReturn(BackendService::VISIBILITY_ADMIN);
@@ -31,7 +30,7 @@ class GlobalStoragesControllerTest extends StoragesControllerTest {
$this->controller = $this->createController(true);
}
- private function createController($allowCreateLocal = true) {
+ private function createController(bool $allowCreateLocal = true): GlobalStoragesController {
$session = $this->createMock(IUserSession::class);
$session->method('getUser')
->willReturn(new User('test', null, $this->createMock(IEventDispatcher::class)));
diff --git a/apps/files_external/tests/Controller/StoragesControllerTest.php b/apps/files_external/tests/Controller/StoragesControllerTestCase.php
index 0d604ff2d47..bb29904ab0d 100644
--- a/apps/files_external/tests/Controller/StoragesControllerTest.php
+++ b/apps/files_external/tests/Controller/StoragesControllerTestCase.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -7,10 +9,12 @@
namespace OCA\Files_External\Tests\Controller;
use OCA\Files_External\Controller\GlobalStoragesController;
+use OCA\Files_External\Controller\UserStoragesController;
use OCA\Files_External\Lib\Auth\AuthMechanism;
+use OCA\Files_External\Lib\Auth\NullMechanism;
use OCA\Files_External\Lib\Backend\Backend;
+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\GlobalStoragesService;
@@ -18,33 +22,25 @@ use OCA\Files_External\Service\UserStoragesService;
use OCP\AppFramework\Http;
use PHPUnit\Framework\MockObject\MockObject;
-abstract class StoragesControllerTest extends \Test\TestCase {
-
- /**
- * @var GlobalStoragesController
- */
- protected $controller;
-
- /**
- * @var GlobalStoragesService|UserStoragesService|MockObject
- */
- protected $service;
+abstract class StoragesControllerTestCase extends \Test\TestCase {
+ protected GlobalStoragesController|UserStoragesController $controller;
+ protected GlobalStoragesService|UserStoragesService|MockObject $service;
protected function setUp(): void {
+ parent::setUp();
MountConfig::$skipTest = true;
}
protected function tearDown(): void {
MountConfig::$skipTest = false;
+ parent::tearDown();
}
/**
- * @return \OCA\Files_External\Lib\Backend\Backend|MockObject
+ * @return \OCA\Files_External\Lib\Backend\Backend&MockObject
*/
- 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')
@@ -57,10 +53,8 @@ abstract class StoragesControllerTest extends \Test\TestCase {
/**
* @return AuthMechanism|MockObject
*/
- 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')
@@ -98,8 +92,8 @@ abstract class StoragesControllerTest extends \Test\TestCase {
$response = $this->controller->create(
'mount',
- '\OCA\Files_External\Lib\Storage\SMB',
- '\OCA\Files_External\Lib\Auth\NullMechanism',
+ \OCA\Files_External\Lib\Storage\SMB::class,
+ NullMechanism::class,
[],
[],
[],
@@ -130,7 +124,7 @@ abstract class StoragesControllerTest extends \Test\TestCase {
$response = $this->controller->create(
'mount',
'local',
- '\OCA\Files_External\Lib\Auth\NullMechanism',
+ NullMechanism::class,
[],
[],
[],
@@ -170,8 +164,8 @@ abstract class StoragesControllerTest extends \Test\TestCase {
$response = $this->controller->update(
1,
'mount',
- '\OCA\Files_External\Lib\Storage\SMB',
- '\OCA\Files_External\Lib\Auth\NullMechanism',
+ \OCA\Files_External\Lib\Storage\SMB::class,
+ NullMechanism::class,
[],
[],
[],
@@ -184,7 +178,7 @@ abstract class StoragesControllerTest extends \Test\TestCase {
$this->assertEquals($storageConfig->jsonSerialize(), $data);
}
- public function mountPointNamesProvider() {
+ public static function mountPointNamesProvider(): array {
return [
[''],
['/'],
@@ -212,8 +206,8 @@ abstract class StoragesControllerTest extends \Test\TestCase {
$response = $this->controller->create(
$mountPoint,
- '\OCA\Files_External\Lib\Storage\SMB',
- '\OCA\Files_External\Lib\Auth\NullMechanism',
+ \OCA\Files_External\Lib\Storage\SMB::class,
+ NullMechanism::class,
[],
[],
[],
@@ -226,8 +220,8 @@ abstract class StoragesControllerTest extends \Test\TestCase {
$response = $this->controller->update(
1,
$mountPoint,
- '\OCA\Files_External\Lib\Storage\SMB',
- '\OCA\Files_External\Lib\Auth\NullMechanism',
+ \OCA\Files_External\Lib\Storage\SMB::class,
+ NullMechanism::class,
[],
[],
[],
@@ -250,7 +244,7 @@ abstract class StoragesControllerTest extends \Test\TestCase {
$response = $this->controller->create(
'mount',
'\OC\Files\Storage\InvalidStorage',
- '\OCA\Files_External\Lib\Auth\NullMechanism',
+ NullMechanism::class,
[],
[],
[],
@@ -264,7 +258,7 @@ abstract class StoragesControllerTest extends \Test\TestCase {
1,
'mount',
'\OC\Files\Storage\InvalidStorage',
- '\OCA\Files_External\Lib\Auth\NullMechanism',
+ NullMechanism::class,
[],
[],
[],
@@ -303,8 +297,8 @@ abstract class StoragesControllerTest extends \Test\TestCase {
$response = $this->controller->update(
255,
'mount',
- '\OCA\Files_External\Lib\Storage\SMB',
- '\OCA\Files_External\Lib\Auth\NullMechanism',
+ \OCA\Files_External\Lib\Storage\SMB::class,
+ NullMechanism::class,
[],
[],
[],
@@ -354,7 +348,7 @@ abstract class StoragesControllerTest extends \Test\TestCase {
$this->assertEquals($expected, $response->getData());
}
- public function validateStorageProvider() {
+ public static function validateStorageProvider(): array {
return [
[true, true, true],
[false, true, false],
@@ -366,7 +360,7 @@ abstract class StoragesControllerTest extends \Test\TestCase {
/**
* @dataProvider validateStorageProvider
*/
- public function testValidateStorage($backendValidate, $authMechValidate, $expectSuccess): void {
+ public function testValidateStorage(bool $backendValidate, bool $authMechValidate, bool $expectSuccess): void {
$backend = $this->getBackendMock();
$backend->method('validateStorage')
->willReturn($backendValidate);
@@ -401,8 +395,8 @@ abstract class StoragesControllerTest extends \Test\TestCase {
$response = $this->controller->create(
'mount',
- '\OCA\Files_External\Lib\Storage\SMB',
- '\OCA\Files_External\Lib\Auth\NullMechanism',
+ \OCA\Files_External\Lib\Storage\SMB::class,
+ NullMechanism::class,
[],
[],
[],
diff --git a/apps/files_external/tests/Controller/UserStoragesControllerTest.php b/apps/files_external/tests/Controller/UserStoragesControllerTest.php
index c15ded48ea7..3e8d89ec060 100644
--- a/apps/files_external/tests/Controller/UserStoragesControllerTest.php
+++ b/apps/files_external/tests/Controller/UserStoragesControllerTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -8,8 +10,10 @@ namespace OCA\Files_External\Tests\Controller;
use OC\User\User;
use OCA\Files_External\Controller\UserStoragesController;
+use OCA\Files_External\Lib\Storage\SMB;
use OCA\Files_External\Lib\StorageConfig;
use OCA\Files_External\Service\BackendService;
+use OCA\Files_External\Service\UserStoragesService;
use OCP\AppFramework\Http;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
@@ -19,18 +23,16 @@ use OCP\IRequest;
use OCP\IUserSession;
use Psr\Log\LoggerInterface;
-class UserStoragesControllerTest extends StoragesControllerTest {
+class UserStoragesControllerTest extends StoragesControllerTestCase {
/**
* @var array
*/
- private $oldAllowedBackends;
+ private array $oldAllowedBackends;
protected function setUp(): void {
parent::setUp();
- $this->service = $this->getMockBuilder('\OCA\Files_External\Service\UserStoragesService')
- ->disableOriginalConstructor()
- ->getMock();
+ $this->service = $this->createMock(UserStoragesService::class);
$this->service->method('getVisibilityType')
->willReturn(BackendService::VISIBILITY_PERSONAL);
@@ -38,7 +40,7 @@ class UserStoragesControllerTest extends StoragesControllerTest {
$this->controller = $this->createController(true);
}
- private function createController($allowCreateLocal = true) {
+ private function createController(bool $allowCreateLocal = true) {
$session = $this->createMock(IUserSession::class);
$session->method('getUser')
->willReturn(new User('test', null, $this->createMock(IEventDispatcher::class)));
@@ -88,7 +90,7 @@ class UserStoragesControllerTest extends StoragesControllerTest {
$response = $this->controller->create(
'mount',
- '\OCA\Files_External\Lib\Storage\SMB',
+ SMB::class,
'\Auth\Mechanism',
[],
[],
@@ -102,7 +104,7 @@ class UserStoragesControllerTest extends StoragesControllerTest {
$response = $this->controller->update(
1,
'mount',
- '\OCA\Files_External\Lib\Storage\SMB',
+ SMB::class,
'\Auth\Mechanism',
[],
[],