aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2025-05-30 00:15:03 +0200
committerJoas Schilling <coding@schilljs.com>2025-05-30 00:15:03 +0200
commita1b7cc98ee639c5143c55bcaae09c4d2a65a29c3 (patch)
treea11c7622953ce03d329676f45bec06585edb4ea8
parent8b2f8b8c35ce9703577519a54728c74aff65638a (diff)
downloadnextcloud-server-tests/noid/files_sharing-1.tar.gz
nextcloud-server-tests/noid/files_sharing-1.zip
test: Migrate first half to PHPUnit 10tests/noid/files_sharing-1
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r--apps/files_sharing/tests/ApplicationTest.php11
-rw-r--r--apps/files_sharing/tests/Collaboration/ShareRecipientSorterTest.php48
-rw-r--r--apps/files_sharing/tests/Command/CleanupRemoteStoragesTest.php55
-rw-r--r--apps/files_sharing/tests/Command/FixShareOwnersTest.php20
-rw-r--r--apps/files_sharing/tests/Controller/ExternalShareControllerTest.php21
-rw-r--r--apps/files_sharing/tests/Controller/PublicPreviewControllerTest.php10
-rw-r--r--apps/files_sharing/tests/Controller/ShareAPIControllerTest.php626
-rw-r--r--apps/files_sharing/tests/Controller/ShareControllerTest.php18
-rw-r--r--apps/files_sharing/tests/Controller/ShareInfoControllerTest.php13
-rw-r--r--apps/files_sharing/tests/Controller/ShareesAPIControllerTest.php104
-rw-r--r--apps/files_sharing/tests/External/CacheTest.php34
-rw-r--r--apps/files_sharing/tests/External/ManagerTest.php81
-rw-r--r--apps/files_sharing/tests/External/ScannerTest.php17
-rw-r--r--apps/files_sharing/tests/Middleware/OCSShareAPIMiddlewareTest.php59
-rw-r--r--apps/files_sharing/tests/Middleware/ShareInfoMiddlewareTest.php11
-rw-r--r--apps/files_sharing/tests/Middleware/SharingCheckMiddlewareTest.php33
-rw-r--r--apps/files_sharing/tests/Migration/SetPasswordColumnTest.php21
-rw-r--r--apps/files_sharing/tests/TestCase.php5
18 files changed, 322 insertions, 865 deletions
diff --git a/apps/files_sharing/tests/ApplicationTest.php b/apps/files_sharing/tests/ApplicationTest.php
index b1a635406b2..c28aaf5298b 100644
--- a/apps/files_sharing/tests/ApplicationTest.php
+++ b/apps/files_sharing/tests/ApplicationTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -19,16 +21,13 @@ use OCP\IUser;
use OCP\IUserSession;
use OCP\Share\IAttributes;
use OCP\Share\IShare;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class ApplicationTest extends TestCase {
private Application $application;
-
- /** @var IUserSession */
- private $userSession;
-
- /** @var IRootFolder */
- private $rootFolder;
+ private IUserSession&MockObject $userSession;
+ private IRootFolder&MockObject $rootFolder;
protected function setUp(): void {
diff --git a/apps/files_sharing/tests/Collaboration/ShareRecipientSorterTest.php b/apps/files_sharing/tests/Collaboration/ShareRecipientSorterTest.php
index 2bef0b0e922..a5b5ed3ba00 100644
--- a/apps/files_sharing/tests/Collaboration/ShareRecipientSorterTest.php
+++ b/apps/files_sharing/tests/Collaboration/ShareRecipientSorterTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -12,17 +14,14 @@ use OCP\Files\Node;
use OCP\IUser;
use OCP\IUserSession;
use OCP\Share\IManager;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class ShareRecipientSorterTest extends TestCase {
- /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
- protected $shareManager;
- /** @var IRootFolder|\PHPUnit\Framework\MockObject\MockObject */
- protected $rootFolder;
- /** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */
- protected $userSession;
- /** @var ShareRecipientSorter */
- protected $sorter;
+ protected IManager&MockObject $shareManager;
+ protected IRootFolder&MockObject $rootFolder;
+ protected IUserSession&MockObject $userSession;
+ protected ShareRecipientSorter $sorter;
protected function setUp(): void {
parent::setUp();
@@ -36,12 +35,11 @@ class ShareRecipientSorterTest extends TestCase {
/**
* @dataProvider sortDataProvider
- * @param $data
*/
- public function testSort($data): void {
+ public function testSort(array $context, ?array $accessList, array $input, array $expected): void {
$node = $this->createMock(Node::class);
- /** @var Folder|\PHPUnit\Framework\MockObject\MockObject $folder */
+ /** @var Folder&MockObject $folder */
$folder = $this->createMock(Folder::class);
$this->rootFolder->expects($this->any())
->method('getUserFolder')
@@ -52,20 +50,20 @@ class ShareRecipientSorterTest extends TestCase {
->method('getUID')
->willReturn('yvonne');
- $this->userSession->expects($this->once())
- ->method('getUser')
- ->willReturn($user);
+ if ($context['itemType'] === 'files') {
+ $this->userSession->expects($this->once())
+ ->method('getUser')
+ ->willReturn($user);
- if ($data['context']['itemType'] === 'files') {
$folder->expects($this->once())
->method('getFirstNodeById')
- ->with($data['context']['itemId'])
+ ->with($context['itemId'])
->willReturn($node);
$this->shareManager->expects($this->once())
->method('getAccessList')
->with($node)
- ->willReturn($data['accessList']);
+ ->willReturn($accessList);
} else {
$folder->expects($this->never())
->method('getFirstNodeById');
@@ -73,14 +71,14 @@ class ShareRecipientSorterTest extends TestCase {
->method('getAccessList');
}
- $workArray = $data['input'];
- $this->sorter->sort($workArray, $data['context']);
+ $workArray = $input;
+ $this->sorter->sort($workArray, $context);
- $this->assertEquals($data['expected'], $workArray);
+ $this->assertEquals($expected, $workArray);
}
public function testSortNoNodes(): void {
- /** @var Folder|\PHPUnit\Framework\MockObject\MockObject $folder */
+ /** @var Folder&MockObject $folder */
$folder = $this->createMock(Folder::class);
$this->rootFolder->expects($this->any())
->method('getUserFolder')
@@ -114,8 +112,8 @@ class ShareRecipientSorterTest extends TestCase {
$this->assertEquals($originalArray, $workArray);
}
- public function sortDataProvider() {
- return [[
+ public static function sortDataProvider(): array {
+ return [
[
#0 – sort properly and otherwise keep existing order
'context' => ['itemType' => 'files', 'itemId' => '42'],
@@ -191,7 +189,7 @@ class ShareRecipientSorterTest extends TestCase {
],
],
[
- #2 – unsupported item type
+ #2 – unsupported item type
'context' => ['itemType' => 'announcements', 'itemId' => '42'],
'accessList' => null, // not needed
'input' => [
@@ -234,6 +232,6 @@ class ShareRecipientSorterTest extends TestCase {
'input' => [],
'expected' => [],
],
- ]];
+ ];
}
}
diff --git a/apps/files_sharing/tests/Command/CleanupRemoteStoragesTest.php b/apps/files_sharing/tests/Command/CleanupRemoteStoragesTest.php
index 888b2cdd596..d24d7d92cbf 100644
--- a/apps/files_sharing/tests/Command/CleanupRemoteStoragesTest.php
+++ b/apps/files_sharing/tests/Command/CleanupRemoteStoragesTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud GmbH.
@@ -11,6 +13,7 @@ use OCP\Federation\ICloudId;
use OCP\Federation\ICloudIdManager;
use OCP\IDBConnection;
use OCP\Server;
+use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Test\TestCase;
@@ -23,23 +26,11 @@ use Test\TestCase;
* @package OCA\Files_Sharing\Tests\Command
*/
class CleanupRemoteStoragesTest extends TestCase {
+ private CleanupRemoteStorages $command;
+ private IDBConnection $connection;
+ private ICloudIdManager&MockObject $cloudIdManager;
- /**
- * @var CleanupRemoteStorages
- */
- private $command;
-
- /**
- * @var IDBConnection
- */
- private $connection;
-
- /**
- * @var ICloudIdManager|\PHPUnit\Framework\MockObject\MockObject
- */
- private $cloudIdManager;
-
- private $storages = [
+ private array $storages = [
['id' => 'shared::7b4a322b22f9d0047c38d77d471ce3cf', 'share_token' => 'f2c69dad1dc0649f26976fd210fc62e1', 'remote' => 'https://hostname.tld/owncloud1', 'user' => 'user1'],
['id' => 'shared::efe3b456112c3780da6155d3a9b9141c', 'share_token' => 'f2c69dad1dc0649f26976fd210fc62e2', 'remote' => 'https://hostname.tld/owncloud2', 'user' => 'user2'],
['notExistingId' => 'shared::33323d9f4ca416a9e3525b435354bc6f', 'share_token' => 'f2c69dad1dc0649f26976fd210fc62e3', 'remote' => 'https://hostname.tld/owncloud3', 'user' => 'user3'],
@@ -77,7 +68,7 @@ class CleanupRemoteStoragesTest extends TestCase {
foreach ($this->storages as &$storage) {
if (isset($storage['id'])) {
$storageQuery->setParameter('id', $storage['id']);
- $storageQuery->execute();
+ $storageQuery->executeStatement();
$storage['numeric_id'] = $storageQuery->getLastInsertId();
}
@@ -134,7 +125,7 @@ class CleanupRemoteStoragesTest extends TestCase {
parent::tearDown();
}
- private function doesStorageExist($numericId) {
+ private function doesStorageExist(int $numericId): bool {
$qb = Server::get(IDBConnection::class)->getQueryBuilder();
$qb->select('*')
->from('storages')
@@ -166,27 +157,29 @@ class CleanupRemoteStoragesTest extends TestCase {
* Test cleanup of orphaned storages
*/
public function testCleanup(): void {
- $input = $this->getMockBuilder(InputInterface::class)
- ->disableOriginalConstructor()
- ->getMock();
- $output = $this->getMockBuilder(OutputInterface::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $input = $this->createMock(InputInterface::class);
+ $output = $this->createMock(OutputInterface::class);
// parent folder, `files`, ´test` and `welcome.txt` => 4 elements
-
+ $calls = [
+ '5 remote storage(s) need(s) to be checked',
+ '5 remote share(s) exist',
+ null,
+ ];
$output
->expects($this->any())
->method('writeln')
- ->withConsecutive(
- ['5 remote storage(s) need(s) to be checked'],
- ['5 remote share(s) exist'],
- );
+ ->willReturnCallback(function ($output) use (&$calls) {
+ $expected = array_shift($calls);
+ if ($expected !== null) {
+ $this->assertEquals($expected, $output);
+ }
+ });
$this->cloudIdManager
->expects($this->any())
->method('getCloudId')
- ->will($this->returnCallback(function (string $user, string $remote) {
+ ->willReturnCallback(function (string $user, string $remote) {
$cloudIdMock = $this->createMock(ICloudId::class);
// The remotes are already sanitized in the original data, so
@@ -197,7 +190,7 @@ class CleanupRemoteStoragesTest extends TestCase {
->willReturn($remote);
return $cloudIdMock;
- }));
+ });
$this->command->execute($input, $output);
diff --git a/apps/files_sharing/tests/Command/FixShareOwnersTest.php b/apps/files_sharing/tests/Command/FixShareOwnersTest.php
index 939fad03d7c..26eeb267bb3 100644
--- a/apps/files_sharing/tests/Command/FixShareOwnersTest.php
+++ b/apps/files_sharing/tests/Command/FixShareOwnersTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-only
@@ -7,6 +9,7 @@ namespace OCA\Files_Sharing\Tests\Command;
use OCA\Files_Sharing\Command\FixShareOwners;
use OCA\Files_Sharing\OrphanHelper;
+use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Test\TestCase;
@@ -17,15 +20,8 @@ use Test\TestCase;
* @package OCA\Files_Sharing\Tests\Command
*/
class FixShareOwnersTest extends TestCase {
- /**
- * @var FixShareOwners
- */
- private $command;
-
- /**
- * @var OrphanHelper|\PHPUnit\Framework\MockObject\MockObject
- */
- private $orphanHelper;
+ private FixShareOwners $command;
+ private OrphanHelper&MockObject $orphanHelper;
protected function setUp(): void {
parent::setUp();
@@ -34,7 +30,7 @@ class FixShareOwnersTest extends TestCase {
$this->command = new FixShareOwners($this->orphanHelper);
}
- public function testExecuteNoSharesDetected() {
+ public function testExecuteNoSharesDetected(): void {
$this->orphanHelper->expects($this->once())
->method('getAllShares')
->willReturn([
@@ -54,7 +50,7 @@ class FixShareOwnersTest extends TestCase {
$this->command->execute($input, $output);
}
- public function testExecuteSharesDetected() {
+ public function testExecuteSharesDetected(): void {
$this->orphanHelper->expects($this->once())
->method('getAllShares')
->willReturn([
@@ -82,7 +78,7 @@ class FixShareOwnersTest extends TestCase {
$this->command->execute($input, $output);
}
- public function testExecuteSharesDetectedDryRun() {
+ public function testExecuteSharesDetectedDryRun(): void {
$this->orphanHelper->expects($this->once())
->method('getAllShares')
->willReturn([
diff --git a/apps/files_sharing/tests/Controller/ExternalShareControllerTest.php b/apps/files_sharing/tests/Controller/ExternalShareControllerTest.php
index 5e8e32c06d8..6baaba662b1 100644
--- a/apps/files_sharing/tests/Controller/ExternalShareControllerTest.php
+++ b/apps/files_sharing/tests/Controller/ExternalShareControllerTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -20,33 +22,20 @@ use PHPUnit\Framework\MockObject\MockObject;
* @package OCA\Files_Sharing\Controllers
*/
class ExternalShareControllerTest extends \Test\TestCase {
- /** @var IRequest */
- private $request;
- /** @var \OCA\Files_Sharing\External\Manager */
- private $externalManager;
- /** @var IConfig|MockObject */
- private $config;
- /** @var IClientService */
- private $clientService;
+ private IRequest $request;
+ private Manager $externalManager;
protected function setUp(): void {
parent::setUp();
$this->request = $this->createMock(IRequest::class);
$this->externalManager = $this->createMock(Manager::class);
- $this->clientService = $this->createMock(IClientService::class);
- $this->config = $this->createMock(IConfig::class);
}
- /**
- * @return ExternalSharesController
- */
- public function getExternalShareController() {
+ public function getExternalShareController(): ExternalSharesController {
return new ExternalSharesController(
'files_sharing',
$this->request,
$this->externalManager,
- $this->clientService,
- $this->config,
);
}
diff --git a/apps/files_sharing/tests/Controller/PublicPreviewControllerTest.php b/apps/files_sharing/tests/Controller/PublicPreviewControllerTest.php
index 9750274ff62..28d398397a1 100644
--- a/apps/files_sharing/tests/Controller/PublicPreviewControllerTest.php
+++ b/apps/files_sharing/tests/Controller/PublicPreviewControllerTest.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
@@ -105,7 +107,7 @@ class PublicPreviewControllerTest extends TestCase {
$this->assertEquals($expected, $res);
}
- public function testShareNoDownload() {
+ public function testShareNoDownload(): void {
$share = $this->createMock(IShare::class);
$this->shareManager->method('getShareByToken')
->with($this->equalTo('token'))
@@ -127,7 +129,7 @@ class PublicPreviewControllerTest extends TestCase {
$this->assertEquals($expected, $res);
}
- public function testShareNoDownloadButPreviewHeader() {
+ public function testShareNoDownloadButPreviewHeader(): void {
$share = $this->createMock(IShare::class);
$this->shareManager->method('getShareByToken')
->with($this->equalTo('token'))
@@ -167,7 +169,7 @@ class PublicPreviewControllerTest extends TestCase {
$this->assertEquals($expected, $res);
}
- public function testShareWithAttributes() {
+ public function testShareWithAttributes(): void {
$share = $this->createMock(IShare::class);
$this->shareManager->method('getShareByToken')
->with($this->equalTo('token'))
@@ -207,7 +209,7 @@ class PublicPreviewControllerTest extends TestCase {
$this->assertEquals($expected, $res);
}
- public function testPreviewFile() {
+ public function testPreviewFile(): void {
$share = $this->createMock(IShare::class);
$this->shareManager->method('getShareByToken')
->with($this->equalTo('token'))
diff --git a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
index 02c133ee5d1..ebb3bde6b6d 100644
--- a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
+++ b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -48,6 +50,7 @@ use PHPUnit\Framework\MockObject\MockObject;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
use Test\TestCase;
+use OCA\Files_Sharing\External\Storage;
/**
* Class ShareAPIControllerTest
@@ -88,7 +91,8 @@ class ShareAPIControllerTest extends TestCase {
->willReturn(true);
$this->shareManager
->expects($this->any())
- ->method('shareProviderExists')->willReturn(true);
+ ->method('shareProviderExists')
+ ->willReturn(true);
$this->groupManager = $this->createMock(IGroupManager::class);
$this->userManager = $this->createMock(IUserManager::class);
$this->request = $this->createMock(IRequest::class);
@@ -164,11 +168,12 @@ class ShareAPIControllerTest extends TestCase {
$this->mailer,
$this->tagManager,
$this->currentUser,
- ])->onlyMethods(['formatShare'])
+ ])
+ ->onlyMethods(['formatShare'])
->getMock();
}
- private function newShare() {
+ private function newShare(): IShare {
return Server::get(IManager::class)->newShare();
}
@@ -183,8 +188,11 @@ class ShareAPIControllerTest extends TestCase {
];
$shareAttributes = $this->createMock(IShareAttributes::class);
- $shareAttributes->method('toArray')->willReturn($formattedShareAttributes);
- $shareAttributes->method('getAttribute')->with('permissions', 'download')->willReturn(true);
+ $shareAttributes->method('toArray')
+ ->willReturn($formattedShareAttributes);
+ $shareAttributes->method('getAttribute')
+ ->with('permissions', 'download')
+ ->willReturn(true);
// send both IShare attributes class and expected json string
return [$shareAttributes, \json_encode($formattedShareAttributes)];
@@ -207,11 +215,11 @@ class ShareAPIControllerTest extends TestCase {
$this->shareManager->method('outgoingServer2ServerSharesAllowed')->willReturn(true);
- $this->ocs->deleteShare(42);
+ $this->ocs->deleteShare('42');
}
public function testDeleteShare(): void {
- $node = $this->getMockBuilder(File::class)->getMock();
+ $node = $this->createMock(File::class);
$share = $this->newShare();
$share->setSharedBy($this->currentUser)
@@ -231,7 +239,7 @@ class ShareAPIControllerTest extends TestCase {
->with(ILockingProvider::LOCK_SHARED);
$expected = new DataResponse();
- $result = $this->ocs->deleteShare(42);
+ $result = $this->ocs->deleteShare('42');
$this->assertInstanceOf(get_class($expected), $result);
$this->assertEquals($expected->getData(), $result->getData());
@@ -242,13 +250,13 @@ class ShareAPIControllerTest extends TestCase {
$this->expectException(OCSNotFoundException::class);
$this->expectExceptionMessage('Could not delete share');
- $node = $this->getMockBuilder(File::class)->getMock();
+ $node = $this->createMock(File::class);
$node->method('getId')->willReturn(1);
$share = $this->newShare();
$share->setNode($node);
- $userFolder = $this->getMockBuilder(Folder::class)->getMock();
+ $userFolder = $this->createMock(Folder::class);
$this->rootFolder->method('getUserFolder')
->with($this->currentUser)
->willReturn($userFolder);
@@ -273,17 +281,17 @@ class ShareAPIControllerTest extends TestCase {
->with(ILockingProvider::LOCK_SHARED)
->will($this->throwException(new LockedException('mypath')));
- $this->assertFalse($this->invokePrivate($this->ocs, 'canDeleteFromSelf', [$share]));
- $this->assertFalse($this->invokePrivate($this->ocs, 'canDeleteShare', [$share]));
+ $this->assertFalse(self::invokePrivate($this->ocs, 'canDeleteFromSelf', [$share]));
+ $this->assertFalse(self::invokePrivate($this->ocs, 'canDeleteShare', [$share]));
- $this->ocs->deleteShare(42);
+ $this->ocs->deleteShare('42');
}
/**
* You can always remove a share that was shared with you
*/
public function testDeleteShareWithMe(): void {
- $node = $this->getMockBuilder(File::class)->getMock();
+ $node = $this->createMock(File::class);
$share = $this->newShare();
$share->setSharedWith($this->currentUser)
@@ -305,17 +313,17 @@ class ShareAPIControllerTest extends TestCase {
->method('lock')
->with(ILockingProvider::LOCK_SHARED);
- $this->assertFalse($this->invokePrivate($this->ocs, 'canDeleteFromSelf', [$share]));
- $this->assertTrue($this->invokePrivate($this->ocs, 'canDeleteShare', [$share]));
+ $this->assertFalse(self::invokePrivate($this->ocs, 'canDeleteFromSelf', [$share]));
+ $this->assertTrue(self::invokePrivate($this->ocs, 'canDeleteShare', [$share]));
- $this->ocs->deleteShare(42);
+ $this->ocs->deleteShare('42');
}
/**
* You can always delete a share you own
*/
public function testDeleteShareOwner(): void {
- $node = $this->getMockBuilder(File::class)->getMock();
+ $node = $this->createMock(File::class);
$share = $this->newShare();
$share->setSharedBy($this->currentUser)
@@ -336,10 +344,10 @@ class ShareAPIControllerTest extends TestCase {
->method('lock')
->with(ILockingProvider::LOCK_SHARED);
- $this->assertFalse($this->invokePrivate($this->ocs, 'canDeleteFromSelf', [$share]));
- $this->assertTrue($this->invokePrivate($this->ocs, 'canDeleteShare', [$share]));
+ $this->assertFalse(self::invokePrivate($this->ocs, 'canDeleteFromSelf', [$share]));
+ $this->assertTrue(self::invokePrivate($this->ocs, 'canDeleteShare', [$share]));
- $this->ocs->deleteShare(42);
+ $this->ocs->deleteShare('42');
}
/**
@@ -347,7 +355,7 @@ class ShareAPIControllerTest extends TestCase {
* the file path it belong to
*/
public function testDeleteShareFileOwner(): void {
- $node = $this->getMockBuilder(File::class)->getMock();
+ $node = $this->createMock(File::class);
$node->method('getId')->willReturn(1);
$share = $this->newShare();
@@ -369,10 +377,10 @@ class ShareAPIControllerTest extends TestCase {
->method('lock')
->with(ILockingProvider::LOCK_SHARED);
- $this->assertFalse($this->invokePrivate($this->ocs, 'canDeleteFromSelf', [$share]));
- $this->assertTrue($this->invokePrivate($this->ocs, 'canDeleteShare', [$share]));
+ $this->assertFalse(self::invokePrivate($this->ocs, 'canDeleteFromSelf', [$share]));
+ $this->assertTrue(self::invokePrivate($this->ocs, 'canDeleteShare', [$share]));
- $this->ocs->deleteShare(42);
+ $this->ocs->deleteShare('42');
}
/**
@@ -380,7 +388,7 @@ class ShareAPIControllerTest extends TestCase {
* a share if you're in the group the share is shared with
*/
public function testDeleteSharedWithMyGroup(): void {
- $node = $this->getMockBuilder(File::class)->getMock();
+ $node = $this->createMock(File::class);
$node->method('getId')->willReturn(1);
$share = $this->newShare();
@@ -396,7 +404,7 @@ class ShareAPIControllerTest extends TestCase {
// canDeleteShareFromSelf
$user = $this->createMock(IUser::class);
- $group = $this->getMockBuilder(IGroup::class)->getMock();
+ $group = $this->createMock(IGroup::class);
$this->groupManager
->method('get')
->with('group')
@@ -413,7 +421,7 @@ class ShareAPIControllerTest extends TestCase {
->method('lock')
->with(ILockingProvider::LOCK_SHARED);
- $userFolder = $this->getMockBuilder(Folder::class)->getMock();
+ $userFolder = $this->createMock(Folder::class);
$this->rootFolder->method('getUserFolder')
->with($this->currentUser)
->willReturn($userFolder);
@@ -429,10 +437,10 @@ class ShareAPIControllerTest extends TestCase {
$this->shareManager->expects($this->never())
->method('deleteShare');
- $this->assertTrue($this->invokePrivate($this->ocs, 'canDeleteShareFromSelf', [$share]));
- $this->assertFalse($this->invokePrivate($this->ocs, 'canDeleteShare', [$share]));
+ $this->assertTrue(self::invokePrivate($this->ocs, 'canDeleteShareFromSelf', [$share]));
+ $this->assertFalse(self::invokePrivate($this->ocs, 'canDeleteShare', [$share]));
- $this->ocs->deleteShare(42);
+ $this->ocs->deleteShare('42');
}
/**
@@ -443,7 +451,7 @@ class ShareAPIControllerTest extends TestCase {
$this->expectException(OCSNotFoundException::class);
$this->expectExceptionMessage('Wrong share ID, share does not exist');
- $node = $this->getMockBuilder(File::class)->getMock();
+ $node = $this->createMock(File::class);
$node->method('getId')->willReturn(42);
$share = $this->newShare();
@@ -459,7 +467,7 @@ class ShareAPIControllerTest extends TestCase {
// canDeleteShareFromSelf
$user = $this->createMock(IUser::class);
- $group = $this->getMockBuilder(IGroup::class)->getMock();
+ $group = $this->createMock(IGroup::class);
$this->groupManager
->method('get')
->with('group')
@@ -476,7 +484,7 @@ class ShareAPIControllerTest extends TestCase {
->method('lock')
->with(ILockingProvider::LOCK_SHARED);
- $userFolder = $this->getMockBuilder(Folder::class)->getMock();
+ $userFolder = $this->createMock(Folder::class);
$this->rootFolder->method('getUserFolder')
->with($this->currentUser)
->willReturn($userFolder);
@@ -491,10 +499,10 @@ class ShareAPIControllerTest extends TestCase {
$this->shareManager->expects($this->never())
->method('deleteShare');
- $this->assertFalse($this->invokePrivate($this->ocs, 'canDeleteShareFromSelf', [$share]));
- $this->assertFalse($this->invokePrivate($this->ocs, 'canDeleteShare', [$share]));
+ $this->assertFalse(self::invokePrivate($this->ocs, 'canDeleteShareFromSelf', [$share]));
+ $this->assertFalse(self::invokePrivate($this->ocs, 'canDeleteShare', [$share]));
- $this->ocs->deleteShare(42);
+ $this->ocs->deleteShare('42');
}
public function testDeleteShareOwnerless(): void {
@@ -550,7 +558,7 @@ class ShareAPIControllerTest extends TestCase {
->method('deleteShare')
->with($share);
- $result = $ocs->deleteShare(1);
+ $result = $ocs->deleteShare('1');
$this->assertInstanceOf(DataResponse::class, $result);
}
@@ -572,7 +580,7 @@ class ShareAPIControllerTest extends TestCase {
public function createShare($id, $shareType, $sharedWith, $sharedBy, $shareOwner, $path, $permissions,
$shareTime, $expiration, $parent, $target, $mail_send, $note = '', $token = null,
$password = null, $label = '', $attributes = null) {
- $share = $this->getMockBuilder(IShare::class)->getMock();
+ $share = $this->createMock(IShare::class);
$share->method('getId')->willReturn($id);
$share->method('getShareType')->willReturn($shareType);
$share->method('getSharedWith')->willReturn($sharedWith);
@@ -604,23 +612,19 @@ class ShareAPIControllerTest extends TestCase {
public function dataGetShare() {
$data = [];
- $cache = $this->getMockBuilder('OC\Files\Cache\Cache')
- ->disableOriginalConstructor()
- ->getMock();
+ $cache = $this->createMock(\OC\Files\Cache\Cache::class);
$cache->method('getNumericStorageId')->willReturn(101);
- $storage = $this->getMockBuilder(IStorage::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $storage = $this->createMock(IStorage::class);
$storage->method('getId')->willReturn('STORAGE');
$storage->method('getCache')->willReturn($cache);
- $parentFolder = $this->getMockBuilder(Folder::class)->getMock();
+ $parentFolder = $this->createMock(Folder::class);
$parentFolder->method('getId')->willReturn(3);
$mountPoint = $this->createMock(IMountPoint::class);
$mountPoint->method('getMountType')->willReturn('');
- $file = $this->getMockBuilder('OCP\Files\File')->getMock();
+ $file = $this->createMock(\OCP\Files\File::class);
$file->method('getId')->willReturn(1);
$file->method('getPath')->willReturn('file');
$file->method('getStorage')->willReturn($storage);
@@ -909,7 +913,7 @@ class ShareAPIControllerTest extends TestCase {
]);
$this->dateTimeZone->method('getTimezone')->willReturn(new \DateTimeZone('UTC'));
- $data = $ocs->getShare($share->getId())->getData()[0];
+ $data = $ocs->getShare((string)$share->getId())->getData()[0];
$this->assertEquals($result, $data);
}
@@ -934,7 +938,7 @@ class ShareAPIControllerTest extends TestCase {
->with($this->currentUser)
->willReturn($userFolder);
- $this->ocs->getShare(42);
+ $this->ocs->getShare('42');
}
public function dataGetShares() {
@@ -1545,16 +1549,16 @@ class ShareAPIControllerTest extends TestCase {
public function testCanAccessShare(): void {
$share = $this->getMockBuilder(IShare::class)->getMock();
$share->method('getShareOwner')->willReturn($this->currentUser);
- $this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
+ $this->assertTrue(self::invokePrivate($this->ocs, 'canAccessShare', [$share]));
$share = $this->getMockBuilder(IShare::class)->getMock();
$share->method('getSharedBy')->willReturn($this->currentUser);
- $this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
+ $this->assertTrue(self::invokePrivate($this->ocs, 'canAccessShare', [$share]));
$share = $this->getMockBuilder(IShare::class)->getMock();
$share->method('getShareType')->willReturn(IShare::TYPE_USER);
$share->method('getSharedWith')->willReturn($this->currentUser);
- $this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
+ $this->assertTrue(self::invokePrivate($this->ocs, 'canAccessShare', [$share]));
$file = $this->getMockBuilder(File::class)->getMock();
@@ -1571,19 +1575,26 @@ class ShareAPIControllerTest extends TestCase {
->willReturn([$file]);
$file->method('getPermissions')
- ->will($this->onConsecutiveCalls(Constants::PERMISSION_SHARE, Constants::PERMISSION_READ));
+ ->will($this->onConsecutiveCalls(
+ Constants::PERMISSION_SHARE,
+ Constants::PERMISSION_READ,
+ Constants::PERMISSION_READ,
+ Constants::PERMISSION_READ,
+ Constants::PERMISSION_READ,
+ Constants::PERMISSION_READ,
+ ));
// getPermissions -> share
$share = $this->getMockBuilder(IShare::class)->getMock();
$share->method('getShareType')->willReturn(IShare::TYPE_USER);
$share->method('getSharedWith')->willReturn($this->getMockBuilder(IUser::class)->getMock());
- $this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
+ $this->assertTrue(self::invokePrivate($this->ocs, 'canAccessShare', [$share]));
// getPermissions -> read
$share = $this->getMockBuilder(IShare::class)->getMock();
$share->method('getShareType')->willReturn(IShare::TYPE_USER);
$share->method('getSharedWith')->willReturn($this->getMockBuilder(IUser::class)->getMock());
- $this->assertFalse($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
+ $this->assertFalse(self::invokePrivate($this->ocs, 'canAccessShare', [$share]));
$share = $this->getMockBuilder(IShare::class)->getMock();
$share->method('getShareType')->willReturn(IShare::TYPE_GROUP);
@@ -1604,93 +1615,24 @@ class ShareAPIControllerTest extends TestCase {
['group2', $group2],
['groupnull', null],
]);
- $this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
+ $this->assertTrue(self::invokePrivate($this->ocs, 'canAccessShare', [$share]));
$share = $this->createMock(IShare::class);
$share->method('getShareType')->willReturn(IShare::TYPE_GROUP);
$share->method('getSharedWith')->willReturn('group2');
- $this->assertFalse($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
+ $this->assertFalse(self::invokePrivate($this->ocs, 'canAccessShare', [$share]));
// null group
$share = $this->createMock(IShare::class);
$share->method('getShareType')->willReturn(IShare::TYPE_GROUP);
$share->method('getSharedWith')->willReturn('groupnull');
- $this->assertFalse($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
+ $this->assertFalse(self::invokePrivate($this->ocs, 'canAccessShare', [$share]));
$share = $this->createMock(IShare::class);
$share->method('getShareType')->willReturn(IShare::TYPE_LINK);
- $this->assertFalse($this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
- }
-
- public function dataCanAccessRoomShare() {
- $result = [];
-
- $share = $this->createMock(IShare::class);
- $share->method('getShareType')->willReturn(IShare::TYPE_ROOM);
- $share->method('getSharedWith')->willReturn('recipientRoom');
-
- $result[] = [
- false, $share, false, false
- ];
-
- $result[] = [
- false, $share, false, true
- ];
-
- $result[] = [
- true, $share, true, true
- ];
-
- $result[] = [
- false, $share, true, false
- ];
-
- return $result;
- }
-
- /**
- * @dataProvider dataCanAccessRoomShare
- *
- * @param bool $expects
- * @param IShare $share
- * @param bool helperAvailable
- * @param bool canAccessShareByHelper
- */
- public function testCanAccessRoomShare(bool $expected, IShare $share, bool $helperAvailable, bool $canAccessShareByHelper): void {
- $userFolder = $this->getMockBuilder(Folder::class)->getMock();
- $this->rootFolder->method('getUserFolder')
- ->with($this->currentUser)
- ->willReturn($userFolder);
-
- $userFolder->method('getById')
- ->with($share->getNodeId())
- ->willReturn([$share->getNode()]);
-
- if (!$helperAvailable) {
- $this->appManager->method('isEnabledForUser')
- ->with('spreed')
- ->willReturn(false);
- } else {
- $this->appManager->method('isEnabledForUser')
- ->with('spreed')
- ->willReturn(true);
-
- $helper = $this->getMockBuilder('\OCA\Talk\Share\Helper\ShareAPIController')
- ->setMethods(['canAccessShare'])
- ->getMock();
- $helper->method('canAccessShare')
- ->with($share, $this->currentUser)
- ->willReturn($canAccessShareByHelper);
-
- $this->serverContainer->method('get')
- ->with('\OCA\Talk\Share\Helper\ShareAPIController')
- ->willReturn($helper);
- }
-
- $this->assertEquals($expected, $this->invokePrivate($this->ocs, 'canAccessShare', [$share]));
+ $this->assertFalse(self::invokePrivate($this->ocs, 'canAccessShare', [$share]));
}
-
public function testCreateShareNoPath(): void {
$this->expectException(OCSNotFoundException::class);
$this->expectExceptionMessage('Please specify a file or folder path');
@@ -2077,7 +2019,7 @@ class ShareAPIControllerTest extends TestCase {
$file = $this->createMock(File::class);
$file->method('getId')->willReturn(42);
$file->method('getStorage')->willReturn($storage);
-
+
$this->rootFolder->method('getUserFolder')->with($this->currentUser)->willReturnSelf();
$this->rootFolder->method('get')->with('valid-path')->willReturn($file);
$this->rootFolder->method('getById')
@@ -2465,163 +2407,6 @@ class ShareAPIControllerTest extends TestCase {
$this->assertEquals($expected->getData(), $result->getData());
}
- public function testCreateShareRoom(): void {
- $ocs = $this->mockFormatShare();
-
- $share = $this->newShare();
- $this->shareManager->method('newShare')->willReturn($share);
-
- [$userFolder, $path] = $this->getNonSharedUserFile();
- $this->rootFolder->expects($this->exactly(2))
- ->method('getUserFolder')
- ->with('currentUser')
- ->willReturn($userFolder);
-
- $userFolder->expects($this->once())
- ->method('get')
- ->with('valid-path')
- ->willReturn($path);
- $userFolder->method('getById')
- ->willReturn([]);
-
- $path->expects($this->once())
- ->method('lock')
- ->with(ILockingProvider::LOCK_SHARED);
-
- $this->appManager->method('isEnabledForUser')
- ->with('spreed')
- ->willReturn(true);
-
- $helper = $this->getMockBuilder('\OCA\Talk\Share\Helper\ShareAPIController')
- ->setMethods(['createShare'])
- ->getMock();
- $helper->method('createShare')
- ->with(
- $share,
- 'recipientRoom',
- Constants::PERMISSION_ALL &
- ~Constants::PERMISSION_DELETE &
- ~Constants::PERMISSION_CREATE,
- ''
- )->willReturnCallback(
- function ($share): void {
- $share->setSharedWith('recipientRoom');
- $share->setPermissions(Constants::PERMISSION_ALL);
- }
- );
-
- $this->serverContainer->method('get')
- ->with('\OCA\Talk\Share\Helper\ShareAPIController')
- ->willReturn($helper);
-
- $this->shareManager->method('createShare')
- ->with($this->callback(function (IShare $share) use ($path) {
- return $share->getNode() === $path
- && $share->getPermissions() === Constants::PERMISSION_ALL
- && $share->getShareType() === IShare::TYPE_ROOM
- && $share->getSharedWith() === 'recipientRoom'
- && $share->getSharedBy() === 'currentUser';
- }))
- ->willReturnArgument(0);
-
- $expected = new DataResponse([]);
- $result = $ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_ROOM, 'recipientRoom');
-
- $this->assertInstanceOf(get_class($expected), $result);
- $this->assertEquals($expected->getData(), $result->getData());
- }
-
-
- public function testCreateShareRoomHelperNotAvailable(): void {
- $this->expectException(OCSForbiddenException::class);
- $this->expectExceptionMessage('Sharing valid-path failed because the back end does not support room shares');
-
- $ocs = $this->mockFormatShare();
-
- $share = $this->newShare();
- $this->shareManager->method('newShare')->willReturn($share);
-
- [$userFolder, $path] = $this->getNonSharedUserFolder();
- $this->rootFolder->method('getUserFolder')
- ->with('currentUser')
- ->willReturn($userFolder);
-
- $path->method('getPath')->willReturn('valid-path');
- $userFolder->expects($this->once())
- ->method('get')
- ->with('valid-path')
- ->willReturn($path);
- $userFolder->method('getById')
- ->willReturn([]);
-
- $path->expects($this->once())
- ->method('lock')
- ->with(ILockingProvider::LOCK_SHARED);
-
- $this->appManager->method('isEnabledForUser')
- ->with('spreed')
- ->willReturn(false);
-
- $this->shareManager->expects($this->never())->method('createShare');
-
- $ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_ROOM, 'recipientRoom');
- }
-
-
- public function testCreateShareRoomHelperThrowException(): void {
- $this->expectException(OCSNotFoundException::class);
- $this->expectExceptionMessage('Exception thrown by the helper');
-
- $ocs = $this->mockFormatShare();
-
- $share = $this->newShare();
- $share->setSharedBy('currentUser');
- $this->shareManager->method('newShare')->willReturn($share);
-
- [$userFolder, $path] = $this->getNonSharedUserFile();
- $this->rootFolder->method('getUserFolder')
- ->with('currentUser')
- ->willReturn($userFolder);
-
- $userFolder->expects($this->once())
- ->method('get')
- ->with('valid-path')
- ->willReturn($path);
- $userFolder->method('getById')
- ->willReturn([]);
-
- $path->expects($this->once())
- ->method('lock')
- ->with(ILockingProvider::LOCK_SHARED);
-
- $this->appManager->method('isEnabledForUser')
- ->with('spreed')
- ->willReturn(true);
-
- $helper = $this->getMockBuilder('\OCA\Talk\Share\Helper\ShareAPIController')
- ->addMethods(['createShare'])
- ->getMock();
- $helper->method('createShare')
- ->with(
- $share,
- 'recipientRoom',
- Constants::PERMISSION_ALL & ~(Constants::PERMISSION_CREATE | Constants::PERMISSION_DELETE),
- ''
- )->willReturnCallback(
- function ($share): void {
- throw new OCSNotFoundException('Exception thrown by the helper');
- }
- );
-
- $this->serverContainer->method('get')
- ->with('\OCA\Talk\Share\Helper\ShareAPIController')
- ->willReturn($helper);
-
- $this->shareManager->expects($this->never())->method('createShare');
-
- $ocs->createShare('valid-path', Constants::PERMISSION_ALL, IShare::TYPE_ROOM, 'recipientRoom');
- }
-
/**
* Test for https://github.com/owncloud/core/issues/22587
* TODO: Remove once proper solution is in place
@@ -2717,7 +2502,7 @@ class ShareAPIControllerTest extends TestCase {
->with($share->getNodeId())
->willReturn([$share->getNode()]);
- $this->ocs->updateShare(42);
+ $this->ocs->updateShare('42');
}
@@ -2738,7 +2523,7 @@ class ShareAPIControllerTest extends TestCase {
$this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
- $this->ocs->updateShare(42);
+ $this->ocs->updateShare('42');
}
@@ -2759,7 +2544,7 @@ class ShareAPIControllerTest extends TestCase {
$this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
- $this->ocs->updateShare(42);
+ $this->ocs->updateShare('42');
}
public function testUpdateLinkShareClear(): void {
@@ -2820,7 +2605,7 @@ class ShareAPIControllerTest extends TestCase {
->willReturn(42);
$expected = new DataResponse([]);
- $result = $ocs->updateShare(42, null, '', null, 'false', '', '', '', 'false');
+ $result = $ocs->updateShare('42', null, '', null, 'false', '', '', '', 'false');
$this->assertInstanceOf(get_class($expected), $result);
$this->assertEquals($expected->getData(), $result->getData());
@@ -2874,7 +2659,7 @@ class ShareAPIControllerTest extends TestCase {
->willReturn(42);
$expected = new DataResponse([]);
- $result = $ocs->updateShare(42, null, 'password', null, 'true', '2000-01-01', 'note', 'label', 'true');
+ $result = $ocs->updateShare('42', null, 'password', null, 'true', '2000-01-01', 'note', 'label', 'true');
$this->assertInstanceOf(get_class($expected), $result);
$this->assertEquals($expected->getData(), $result->getData());
@@ -2924,7 +2709,7 @@ class ShareAPIControllerTest extends TestCase {
->willReturn(42);
$expected = new DataResponse([]);
- $result = $ocs->updateShare(42, $permissions, $password, null, $publicUpload, $expireDate);
+ $result = $ocs->updateShare('42', $permissions, $password, null, $publicUpload, $expireDate);
$this->assertInstanceOf(get_class($expected), $result);
$this->assertEquals($expected->getData(), $result->getData());
@@ -2982,13 +2767,13 @@ class ShareAPIControllerTest extends TestCase {
->willReturn(42);
$expected = new DataResponse([]);
- $result = $ocs->updateShare(42, $permissions, 'password', null, null, null);
+ $result = $ocs->updateShare('42', $permissions, 'password', null, null, null);
$this->assertInstanceOf(get_class($expected), $result);
$this->assertEquals($expected->getData(), $result->getData());
}
- public function publicLinkInvalidPermissionsProvider1() {
+ public static function publicLinkInvalidPermissionsProvider1(): array {
return [
[Constants::PERMISSION_DELETE],
[Constants::PERMISSION_UPDATE],
@@ -2999,14 +2784,14 @@ class ShareAPIControllerTest extends TestCase {
/**
* @dataProvider publicLinkInvalidPermissionsProvider1
*/
- public function testUpdateLinkShareSetInvalidCRUDPermissions1($permissions): void {
+ public function testUpdateLinkShareSetInvalidCRUDPermissions1(int $permissions): void {
$this->expectException(OCSBadRequestException::class);
$this->expectExceptionMessage('Share must at least have READ or CREATE permissions');
$this->testUpdateLinkShareSetCRUDPermissions($permissions, null);
}
- public function publicLinkInvalidPermissionsProvider2() {
+ public static function publicLinkInvalidPermissionsProvider2(): array {
return [
[Constants::PERMISSION_CREATE | Constants::PERMISSION_DELETE],
[Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE],
@@ -3016,7 +2801,7 @@ class ShareAPIControllerTest extends TestCase {
/**
* @dataProvider publicLinkInvalidPermissionsProvider2
*/
- public function testUpdateLinkShareSetInvalidCRUDPermissions2($permissions): void {
+ public function testUpdateLinkShareSetInvalidCRUDPermissions2(int $permissions): void {
$this->expectException(OCSBadRequestException::class);
$this->expectExceptionMessage('Share must have READ permission if UPDATE or DELETE permission is set');
@@ -3048,7 +2833,7 @@ class ShareAPIControllerTest extends TestCase {
$this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
$this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);
- $ocs->updateShare(42, null, 'password', null, 'true', '2000-01-a');
+ $ocs->updateShare('42', null, 'password', null, 'true', '2000-01-a');
}
public function publicUploadParamsProvider() {
@@ -3094,7 +2879,7 @@ class ShareAPIControllerTest extends TestCase {
$this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
$this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(false);
- $ocs->updateShare(42, $permissions, $password, null, $publicUpload, $expireDate);
+ $ocs->updateShare('42', $permissions, $password, null, $publicUpload, $expireDate);
}
@@ -3133,7 +2918,7 @@ class ShareAPIControllerTest extends TestCase {
->with($share)
->willThrowException(new \InvalidArgumentException('File shares cannot have create or delete permissions'));
- $ocs->updateShare(42, null, 'password', null, 'true', '');
+ $ocs->updateShare('42', null, 'password', null, 'true', '');
}
public function testUpdateLinkSharePasswordDoesNotChangeOther(): void {
@@ -3182,7 +2967,7 @@ class ShareAPIControllerTest extends TestCase {
)->willReturnArgument(0);
$expected = new DataResponse([]);
- $result = $ocs->updateShare(42, null, 'newpassword', null, null, null, null, null, null);
+ $result = $ocs->updateShare('42', null, 'newpassword', null, null, null, null, null, null);
$this->assertInstanceOf(get_class($expected), $result);
$this->assertEquals($expected->getData(), $result->getData());
@@ -3236,7 +3021,7 @@ class ShareAPIControllerTest extends TestCase {
)->willReturnArgument(0);
$expected = new DataResponse([]);
- $result = $ocs->updateShare(42, null, null, 'true', null, null, null, null, null);
+ $result = $ocs->updateShare('42', null, null, 'true', null, null, null, null, null);
$this->assertInstanceOf(get_class($expected), $result);
$this->assertEquals($expected->getData(), $result->getData());
@@ -3283,7 +3068,7 @@ class ShareAPIControllerTest extends TestCase {
$this->shareManager->expects($this->never())->method('updateShare');
- $ocs->updateShare(42, null, null, 'true', null, null, null, null, null);
+ $ocs->updateShare('42', null, null, 'true', null, null, null, null, null);
}
public function testUpdateLinkShareDoNotSendPasswordByTalkDoesNotChangeOther(): void {
@@ -3334,7 +3119,7 @@ class ShareAPIControllerTest extends TestCase {
)->willReturnArgument(0);
$expected = new DataResponse([]);
- $result = $ocs->updateShare(42, null, null, 'false', null, null, null, null, null);
+ $result = $ocs->updateShare('42', null, null, 'false', null, null, null, null, null);
$this->assertInstanceOf(get_class($expected), $result);
$this->assertEquals($expected->getData(), $result->getData());
@@ -3404,7 +3189,7 @@ class ShareAPIControllerTest extends TestCase {
->willReturn(42);
$expected = new DataResponse([]);
- $result = $ocs->updateShare(42, null, null, 'false', null, null, null, null, null);
+ $result = $ocs->updateShare('42', null, null, 'false', null, null, null, null, null);
$this->assertInstanceOf(get_class($expected), $result);
$this->assertEquals($expected->getData(), $result->getData());
@@ -3466,7 +3251,7 @@ class ShareAPIControllerTest extends TestCase {
->willReturn(42);
$expected = new DataResponse([]);
- $result = $ocs->updateShare(42, null, null, null, null, '2010-12-23', null, null, null);
+ $result = $ocs->updateShare('42', null, null, null, null, '2010-12-23', null, null, null);
$this->assertInstanceOf(get_class($expected), $result);
$this->assertEquals($expected->getData(), $result->getData());
@@ -3527,7 +3312,7 @@ class ShareAPIControllerTest extends TestCase {
->willReturn(42);
$expected = new DataResponse([]);
- $result = $ocs->updateShare(42, null, null, null, 'true', null, null, null, null);
+ $result = $ocs->updateShare('42', null, null, null, 'true', null, null, null, null);
$this->assertInstanceOf(get_class($expected), $result);
$this->assertEquals($expected->getData(), $result->getData());
@@ -3587,7 +3372,7 @@ class ShareAPIControllerTest extends TestCase {
->willReturn(42);
$expected = new DataResponse([]);
- $result = $ocs->updateShare(42, 7, null, null, 'true', null, null, null, null);
+ $result = $ocs->updateShare('42', 7, null, null, 'true', null, null, null, null);
$this->assertInstanceOf(get_class($expected), $result);
$this->assertEquals($expected->getData(), $result->getData());
@@ -3649,7 +3434,7 @@ class ShareAPIControllerTest extends TestCase {
$this->shareManager->method('getSharedWith')->willReturn([]);
$expected = new DataResponse([]);
- $result = $ocs->updateShare(42, Constants::PERMISSION_ALL, null, null, null, null, null, null, null);
+ $result = $ocs->updateShare('42', Constants::PERMISSION_ALL, null, null, null, null, null, null, null);
$this->assertInstanceOf(get_class($expected), $result);
$this->assertEquals($expected->getData(), $result->getData());
@@ -3695,7 +3480,7 @@ class ShareAPIControllerTest extends TestCase {
->willReturn(42);
$expected = new DataResponse([]);
- $result = $ocs->updateShare(42, 31, null, null, null, null);
+ $result = $ocs->updateShare('42', 31, null, null, null, null);
$this->assertInstanceOf(get_class($expected), $result);
$this->assertEquals($expected->getData(), $result->getData());
@@ -3769,7 +3554,7 @@ class ShareAPIControllerTest extends TestCase {
->willThrowException(new GenericShareException('Cannot increase permissions of path/file', 'Cannot increase permissions of path/file', 404));
try {
- $ocs->updateShare(42, 31);
+ $ocs->updateShare('42', 31);
$this->fail();
} catch (OCSException $e) {
$this->assertEquals('Cannot increase permissions of path/file', $e->getMessage());
@@ -3833,7 +3618,7 @@ class ShareAPIControllerTest extends TestCase {
$mountPoint->method('getStorageRootId')
->willReturn(42);
- $result = $ocs->updateShare(42, 31);
+ $result = $ocs->updateShare('42', 31);
$this->assertInstanceOf(DataResponse::class, $result);
}
@@ -3891,11 +3676,11 @@ class ShareAPIControllerTest extends TestCase {
->with($share)
->willReturn($share);
- $result = $ocs->updateShare(1, Constants::PERMISSION_ALL);
+ $result = $ocs->updateShare('1', Constants::PERMISSION_ALL);
$this->assertInstanceOf(DataResponse::class, $result);
}
- public function dataFormatShare() {
+ public function dataFormatShare(): array {
$file = $this->getMockBuilder(File::class)->getMock();
$folder = $this->getMockBuilder(Folder::class)->getMock();
$parent = $this->getMockBuilder(Folder::class)->getMock();
@@ -4846,13 +4631,8 @@ class ShareAPIControllerTest extends TestCase {
/**
* @dataProvider dataFormatShare
- *
- * @param array $expects
- * @param IShare $share
- * @param array $users
- * @param $exception
*/
- public function testFormatShare(array $expects, IShare $share, array $users, $exception): void {
+ public function testFormatShare(array $expects, IShare $share, array $users, bool $exception): void {
$this->userManager->method('get')->willReturnMap($users);
$recipientGroup = $this->createMock(IGroup::class);
@@ -4916,7 +4696,7 @@ class ShareAPIControllerTest extends TestCase {
]);
try {
- $result = $this->invokePrivate($this->ocs, 'formatShare', [$share]);
+ $result = self::invokePrivate($this->ocs, 'formatShare', [$share]);
$this->assertFalse($exception);
$this->assertEquals($expects, $result);
} catch (NotFoundException $e) {
@@ -4924,205 +4704,17 @@ class ShareAPIControllerTest extends TestCase {
}
}
- public function dataFormatRoomShare() {
- $file = $this->getMockBuilder(File::class)->getMock();
- $parent = $this->getMockBuilder(Folder::class)->getMock();
-
- $file->method('getMimeType')->willReturn('myMimeType');
-
- $file->method('getPath')->willReturn('file');
-
- $parent->method('getId')->willReturn(1);
- $file->method('getId')->willReturn(3);
-
- $file->method('getParent')->willReturn($parent);
-
- $file->method('getSize')->willReturn(123456);
- $file->method('getMTime')->willReturn(1234567890);
-
- $mountPoint = $this->getMockBuilder(IMountPoint::class)->getMock();
- $mountPoint->method('getMountType')->willReturn('');
- $file->method('getMountPoint')->willReturn($mountPoint);
-
- $cache = $this->getMockBuilder('OCP\Files\Cache\ICache')->getMock();
- $cache->method('getNumericStorageId')->willReturn(100);
- $storage = $this->createMock(IStorage::class);
- $storage->method('getId')->willReturn('storageId');
- $storage->method('getCache')->willReturn($cache);
-
- $file->method('getStorage')->willReturn($storage);
-
- $result = [];
-
- $share = Server::get(IManager::class)->newShare();
- $share->setShareType(IShare::TYPE_ROOM)
- ->setSharedWith('recipientRoom')
- ->setSharedBy('initiator')
- ->setShareOwner('owner')
- ->setPermissions(Constants::PERMISSION_READ)
- ->setNode($file)
- ->setShareTime(new \DateTime('2000-01-01T00:01:02'))
- ->setTarget('myTarget')
- ->setNote('personal note')
- ->setId(42);
-
- $result[] = [
- [
- 'id' => '42',
- 'share_type' => IShare::TYPE_ROOM,
- 'uid_owner' => 'initiator',
- 'displayname_owner' => 'initiator',
- 'permissions' => 1,
- 'stime' => 946684862,
- 'parent' => null,
- 'expiration' => null,
- 'token' => null,
- 'uid_file_owner' => 'owner',
- 'displayname_file_owner' => 'owner',
- 'note' => 'personal note',
- 'path' => 'file',
- 'item_type' => 'file',
- 'storage_id' => 'storageId',
- 'storage' => 100,
- 'item_source' => 3,
- 'file_source' => 3,
- 'file_parent' => 1,
- 'file_target' => 'myTarget',
- 'share_with' => 'recipientRoom',
- 'share_with_displayname' => '',
- 'mail_send' => 0,
- 'mimetype' => 'myMimeType',
- 'has_preview' => false,
- 'hide_download' => 0,
- 'label' => '',
- 'can_edit' => false,
- 'can_delete' => false,
- 'item_size' => 123456,
- 'item_mtime' => 1234567890,
- 'is-mount-root' => false,
- 'mount-type' => '',
- 'attributes' => null,
- 'item_permissions' => 1,
- ], $share, false, []
- ];
-
- $share = Server::get(IManager::class)->newShare();
- $share->setShareType(IShare::TYPE_ROOM)
- ->setSharedWith('recipientRoom')
- ->setSharedBy('initiator')
- ->setShareOwner('owner')
- ->setPermissions(Constants::PERMISSION_READ)
- ->setNode($file)
- ->setShareTime(new \DateTime('2000-01-01T00:01:02'))
- ->setTarget('myTarget')
- ->setNote('personal note')
- ->setId(42);
-
- $result[] = [
- [
- 'id' => '42',
- 'share_type' => IShare::TYPE_ROOM,
- 'uid_owner' => 'initiator',
- 'displayname_owner' => 'initiator',
- 'permissions' => 1,
- 'stime' => 946684862,
- 'parent' => null,
- 'expiration' => null,
- 'token' => null,
- 'uid_file_owner' => 'owner',
- 'displayname_file_owner' => 'owner',
- 'note' => 'personal note',
- 'path' => 'file',
- 'item_type' => 'file',
- 'storage_id' => 'storageId',
- 'storage' => 100,
- 'item_source' => 3,
- 'file_source' => 3,
- 'file_parent' => 1,
- 'file_target' => 'myTarget',
- 'share_with' => 'recipientRoom',
- 'share_with_displayname' => 'recipientRoomName',
- 'mail_send' => 0,
- 'mimetype' => 'myMimeType',
- 'has_preview' => false,
- 'hide_download' => 0,
- 'label' => '',
- 'can_edit' => false,
- 'can_delete' => false,
- 'item_size' => 123456,
- 'item_mtime' => 1234567890,
- 'is-mount-root' => false,
- 'mount-type' => '',
- 'attributes' => null,
- 'item_permissions' => 9,
- ], $share, true, [
- 'share_with_displayname' => 'recipientRoomName'
- ]
- ];
-
- return $result;
- }
-
- /**
- * @dataProvider dataFormatRoomShare
- *
- * @param array $expects
- * @param IShare $share
- * @param bool $helperAvailable
- * @param array $formatShareByHelper
- */
- public function testFormatRoomShare(array $expects, IShare $share, bool $helperAvailable, array $formatShareByHelper): void {
- $this->rootFolder->method('getUserFolder')
- ->with($this->currentUser)
- ->willReturnSelf();
-
- $this->rootFolder->method('getFirstNodeById')
- ->with($share->getNodeId())
- ->willReturn($share->getNode());
-
- $this->rootFolder->method('getRelativePath')
- ->with($share->getNode()->getPath())
- ->willReturnArgument(0);
-
- if (!$helperAvailable) {
- $this->appManager->method('isEnabledForUser')
- ->with('spreed')
- ->willReturn(false);
- } else {
- $this->appManager->method('isEnabledForUser')
- ->with('spreed')
- ->willReturn(true);
-
- $helper = $this->getMockBuilder('\OCA\Talk\Share\Helper\ShareAPIController')
- ->setMethods(['formatShare', 'canAccessShare'])
- ->getMock();
- $helper->method('formatShare')
- ->with($share)
- ->willReturn($formatShareByHelper);
- $helper->method('canAccessShare')
- ->with($share)
- ->willReturn(true);
-
- $this->serverContainer->method('get')
- ->with('\OCA\Talk\Share\Helper\ShareAPIController')
- ->willReturn($helper);
- }
-
- $result = $this->invokePrivate($this->ocs, 'formatShare', [$share]);
- $this->assertEquals($expects, $result);
- }
-
/**
* @return list{Folder, Folder}
*/
private function getNonSharedUserFolder(): array {
- $node = $this->getMockBuilder(Folder::class)->getMock();
- $userFolder = $this->getMockBuilder(Folder::class)->getMock();
+ $node = $this->createMock(Folder::class);
+ $userFolder = $this->createMock(Folder::class);
$storage = $this->createMock(IStorage::class);
$storage->method('instanceOfStorage')
->willReturnMap([
- ['OCA\Files_Sharing\External\Storage', false],
- ['OCA\Files_Sharing\SharedStorage', false],
+ [Storage::class, false],
+ [\OCA\Files_Sharing\SharedStorage::class, false],
]);
$userFolder->method('getStorage')->willReturn($storage);
$node->method('getStorage')->willReturn($storage);
@@ -5137,13 +4729,13 @@ class ShareAPIControllerTest extends TestCase {
* @return list{Folder, File}
*/
private function getNonSharedUserFile(): array {
- $node = $this->getMockBuilder(File::class)->getMock();
- $userFolder = $this->getMockBuilder(Folder::class)->getMock();
+ $node = $this->createMock(File::class);
+ $userFolder = $this->createMock(Folder::class);
$storage = $this->createMock(IStorage::class);
$storage->method('instanceOfStorage')
->willReturnMap([
- ['OCA\Files_Sharing\External\Storage', false],
- ['OCA\Files_Sharing\SharedStorage', false],
+ [Storage::class, false],
+ [\OCA\Files_Sharing\SharedStorage::class, false],
]);
$userFolder->method('getStorage')->willReturn($storage);
$node->method('getStorage')->willReturn($storage);
diff --git a/apps/files_sharing/tests/Controller/ShareControllerTest.php b/apps/files_sharing/tests/Controller/ShareControllerTest.php
index a6bef1bed56..feb4c96d306 100644
--- a/apps/files_sharing/tests/Controller/ShareControllerTest.php
+++ b/apps/files_sharing/tests/Controller/ShareControllerTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -55,7 +57,7 @@ use PHPUnit\Framework\MockObject\MockObject;
class ShareControllerTest extends \Test\TestCase {
private string $user;
- private string $oldUser;
+ private string|false $oldUser;
private string $appName = 'files_sharing';
private ShareController $shareController;
@@ -164,7 +166,9 @@ class ShareControllerTest extends \Test\TestCase {
// Set old user
\OC_User::setUserId($this->oldUser);
- \OC_Util::setupFS($this->oldUser);
+ if ($this->oldUser !== false) {
+ \OC_Util::setupFS($this->oldUser);
+ }
parent::tearDown();
}
@@ -643,11 +647,11 @@ class ShareControllerTest extends \Test\TestCase {
$filename = 'file1.txt';
$this->shareController->setToken('token');
- $owner = $this->getMockBuilder(IUser::class)->getMock();
+ $owner = $this->createMock(IUser::class);
$owner->method('getDisplayName')->willReturn('ownerDisplay');
$owner->method('getUID')->willReturn('ownerUID');
- $file = $this->getMockBuilder('OCP\Files\File')->getMock();
+ $file = $this->createMock(File::class);
$file->method('getName')->willReturn($filename);
$file->method('getMimetype')->willReturn('text/plain');
$file->method('getSize')->willReturn(33);
@@ -688,7 +692,7 @@ class ShareControllerTest extends \Test\TestCase {
}
public function testDownloadShareWithCreateOnlyShare(): void {
- $share = $this->getMockBuilder(IShare::class)->getMock();
+ $share = $this->createMock(IShare::class);
$share->method('getPassword')->willReturn('password');
$share
->expects($this->once())
@@ -738,7 +742,7 @@ class ShareControllerTest extends \Test\TestCase {
public function testDisabledOwner(): void {
$this->shareController->setToken('token');
- $owner = $this->getMockBuilder(IUser::class)->getMock();
+ $owner = $this->createMock(IUser::class);
$owner->method('isEnabled')->willReturn(false);
$initiator = $this->createMock(IUser::class);
@@ -779,7 +783,7 @@ class ShareControllerTest extends \Test\TestCase {
public function testDisabledInitiator(): void {
$this->shareController->setToken('token');
- $owner = $this->getMockBuilder(IUser::class)->getMock();
+ $owner = $this->createMock(IUser::class);
$owner->method('isEnabled')->willReturn(false);
$initiator = $this->createMock(IUser::class);
diff --git a/apps/files_sharing/tests/Controller/ShareInfoControllerTest.php b/apps/files_sharing/tests/Controller/ShareInfoControllerTest.php
index f2df74fd01b..a05ef70a655 100644
--- a/apps/files_sharing/tests/Controller/ShareInfoControllerTest.php
+++ b/apps/files_sharing/tests/Controller/ShareInfoControllerTest.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
@@ -15,15 +17,12 @@ use OCP\IRequest;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IManager as ShareManager;
use OCP\Share\IShare;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class ShareInfoControllerTest extends TestCase {
-
- /** @var ShareInfoController */
- private $controller;
-
- /** @var ShareManager|\PHPUnit\Framework\MockObject\MockObject */
- private $shareManager;
+ private ShareInfoController $controller;
+ private ShareManager|MockObject $shareManager;
protected function setUp(): void {
@@ -37,7 +36,7 @@ class ShareInfoControllerTest extends TestCase {
$this->createMock(IRequest::class),
$this->shareManager
])
- ->setMethods(['addROWrapper'])
+ ->onlyMethods(['addROWrapper'])
->getMock();
}
diff --git a/apps/files_sharing/tests/Controller/ShareesAPIControllerTest.php b/apps/files_sharing/tests/Controller/ShareesAPIControllerTest.php
index c8113558f6c..050001dc5c6 100644
--- a/apps/files_sharing/tests/Controller/ShareesAPIControllerTest.php
+++ b/apps/files_sharing/tests/Controller/ShareesAPIControllerTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -27,23 +29,12 @@ use PHPUnit\Framework\MockObject\MockObject;
* @package OCA\Files_Sharing\Tests\API
*/
class ShareesAPIControllerTest extends TestCase {
- /** @var ShareesAPIController */
- protected $sharees;
-
- /** @var string */
- protected $uid;
-
- /** @var IRequest|MockObject */
- protected $request;
-
- /** @var IManager|MockObject */
- protected $shareManager;
-
- /** @var ISearch|MockObject */
- protected $collaboratorSearch;
-
- /** @var IConfig|MockObject */
- protected $config;
+ protected ShareesAPIController $sharees;
+ protected string $uid;
+ protected IRequest&MockObject $request;
+ protected IManager $shareManager;
+ protected ISearch&MockObject $collaboratorSearch;
+ protected IConfig&MockObject $config;
protected function setUp(): void {
parent::setUp();
@@ -52,10 +43,7 @@ class ShareesAPIControllerTest extends TestCase {
$this->request = $this->createMock(IRequest::class);
$this->shareManager = $this->createMock(IManager::class);
$this->config = $this->createMock(IConfig::class);
-
- /** @var IURLGenerator|MockObject $urlGeneratorMock */
$urlGeneratorMock = $this->createMock(IURLGenerator::class);
-
$this->collaboratorSearch = $this->createMock(ISearch::class);
$this->sharees = new ShareesAPIController(
@@ -69,7 +57,7 @@ class ShareesAPIControllerTest extends TestCase {
);
}
- public function dataSearch(): array {
+ public static function dataSearch(): array {
$noRemote = [IShare::TYPE_USER, IShare::TYPE_GROUP, IShare::TYPE_EMAIL];
$allTypes = [IShare::TYPE_USER, IShare::TYPE_GROUP, IShare::TYPE_REMOTE, IShare::TYPE_REMOTE_GROUP, IShare::TYPE_EMAIL];
@@ -84,7 +72,7 @@ class ShareesAPIControllerTest extends TestCase {
'search' => 'foobar',
], '', 'yes', false, true, true, true, $noRemote, false, true, true],
[[
- 'search' => 0,
+ 'search' => '0',
], '', 'yes', false, true, true, true, $noRemote, false, true, true],
// Test itemType
@@ -95,7 +83,7 @@ class ShareesAPIControllerTest extends TestCase {
'itemType' => 'folder',
], '', 'yes', false, true, true, true, $allTypes, false, true, true],
[[
- 'itemType' => 0,
+ 'itemType' => null,
], '', 'yes', false, true, true , true, $noRemote, false, true, true],
// Test shareType
[[
@@ -198,18 +186,6 @@ class ShareesAPIControllerTest extends TestCase {
/**
* @dataProvider dataSearch
- *
- * @param array $getData
- * @param string $apiSetting
- * @param string $enumSetting
- * @param bool $remoteSharingEnabled
- * @param bool $isRemoteGroupSharingEnabled
- * @param bool $emailSharingEnabled
- * @param array $shareTypes
- * @param bool $shareWithGroupOnly
- * @param bool $shareeEnumeration
- * @param bool $allowGroupSharing
- * @throws OCSBadRequestException
*/
public function testSearch(
array $getData,
@@ -236,21 +212,16 @@ class ShareesAPIControllerTest extends TestCase {
->willReturn(true);
$this->overwriteService(GlobalScaleIConfig::class, $globalConfig);
- /** @var IConfig|MockObject $config */
+ /** @var IConfig&MockObject $config */
$config = $this->createMock(IConfig::class);
$this->shareManager->expects($this->once())
->method('allowGroupSharing')
->willReturn($allowGroupSharing);
- /** @var string */
$uid = 'test123';
- /** @var IRequest|MockObject $request */
$request = $this->createMock(IRequest::class);
- /** @var IURLGenerator|MockObject $urlGenerator */
$urlGenerator = $this->createMock(IURLGenerator::class);
-
- /** @var MockObject|ShareesAPIController $sharees */
$sharees = $this->getMockBuilder(ShareesAPIController::class)
->setConstructorArgs([
'files_sharing',
@@ -301,16 +272,13 @@ class ShareesAPIControllerTest extends TestCase {
$this->assertInstanceOf(DataResponse::class, $sharees->search($search, $itemType, $page, $perPage, $shareType));
}
- public function dataSearchInvalid(): array {
+ public static function dataSearchInvalid(): array {
return [
// Test invalid pagination
[[
'page' => 0,
], 'Invalid page'],
[[
- 'page' => '0',
- ], 'Invalid page'],
- [[
'page' => -1,
], 'Invalid page'],
@@ -319,9 +287,6 @@ class ShareesAPIControllerTest extends TestCase {
'perPage' => 0,
], 'Invalid perPage argument'],
[[
- 'perPage' => '0',
- ], 'Invalid perPage argument'],
- [[
'perPage' => -1,
], 'Invalid perPage argument'],
];
@@ -329,28 +294,22 @@ class ShareesAPIControllerTest extends TestCase {
/**
* @dataProvider dataSearchInvalid
- *
- * @param array $getData
- * @param string $message
*/
- public function testSearchInvalid($getData, $message): void {
+ public function testSearchInvalid(array $getData, string $message): void {
$page = $getData['page'] ?? 1;
$perPage = $getData['perPage'] ?? 200;
- /** @var IConfig|MockObject $config */
+ /** @var IConfig&MockObject $config */
$config = $this->createMock(IConfig::class);
$config->expects($this->never())
->method('getAppValue');
- /** @var string */
$uid = 'test123';
- /** @var IRequest|MockObject $request */
$request = $this->createMock(IRequest::class);
- /** @var IURLGenerator|MockObject $urlGenerator */
$urlGenerator = $this->createMock(IURLGenerator::class);
- /** @var MockObject|ShareesAPIController $sharees */
- $sharees = $this->getMockBuilder('\OCA\Files_Sharing\Controller\ShareesAPIController')
+ /** @var ShareesAPIController&MockObject $sharees */
+ $sharees = $this->getMockBuilder(ShareesAPIController::class)
->setConstructorArgs([
'files_sharing',
$request,
@@ -376,7 +335,7 @@ class ShareesAPIControllerTest extends TestCase {
}
}
- public function dataIsRemoteSharingAllowed() {
+ public static function dataIsRemoteSharingAllowed(): array {
return [
['file', true],
['folder', true],
@@ -387,12 +346,9 @@ class ShareesAPIControllerTest extends TestCase {
/**
* @dataProvider dataIsRemoteSharingAllowed
- *
- * @param string $itemType
- * @param bool $expected
*/
- public function testIsRemoteSharingAllowed($itemType, $expected): void {
- $this->assertSame($expected, $this->invokePrivate($this->sharees, 'isRemoteSharingAllowed', [$itemType]));
+ public function testIsRemoteSharingAllowed(string $itemType, bool $expected): void {
+ $this->assertSame($expected, self::invokePrivate($this->sharees, 'isRemoteSharingAllowed', [$itemType]));
}
public function testSearchSharingDisabled(): void {
@@ -419,7 +375,7 @@ class ShareesAPIControllerTest extends TestCase {
$this->sharees->search('', null, 1, 10, [], false);
}
- public function dataGetPaginationLink() {
+ public static function dataGetPaginationLink(): array {
return [
[1, '/ocs/v1.php', ['perPage' => 2], '<?perPage=2&page=2>; rel="next"'],
[10, '/ocs/v2.php', ['perPage' => 2], '<?perPage=2&page=11>; rel="next"'],
@@ -428,21 +384,16 @@ class ShareesAPIControllerTest extends TestCase {
/**
* @dataProvider dataGetPaginationLink
- *
- * @param int $page
- * @param string $scriptName
- * @param array $params
- * @param array $expected
*/
- public function testGetPaginationLink($page, $scriptName, $params, $expected): void {
+ public function testGetPaginationLink(int $page, string $scriptName, array $params, string $expected): void {
$this->request->expects($this->once())
->method('getScriptName')
->willReturn($scriptName);
- $this->assertEquals($expected, $this->invokePrivate($this->sharees, 'getPaginationLink', [$page, $params]));
+ $this->assertEquals($expected, self::invokePrivate($this->sharees, 'getPaginationLink', [$page, $params]));
}
- public function dataIsV2() {
+ public static function dataIsV2(): array {
return [
['/ocs/v1.php', false],
['/ocs/v2.php', true],
@@ -451,15 +402,12 @@ class ShareesAPIControllerTest extends TestCase {
/**
* @dataProvider dataIsV2
- *
- * @param string $scriptName
- * @param bool $expected
*/
- public function testIsV2($scriptName, $expected): void {
+ public function testIsV2(string $scriptName, bool $expected): void {
$this->request->expects($this->once())
->method('getScriptName')
->willReturn($scriptName);
- $this->assertEquals($expected, $this->invokePrivate($this->sharees, 'isV2'));
+ $this->assertEquals($expected, self::invokePrivate($this->sharees, 'isV2'));
}
}
diff --git a/apps/files_sharing/tests/External/CacheTest.php b/apps/files_sharing/tests/External/CacheTest.php
index 5a862d8ddc0..1d7724afead 100644
--- a/apps/files_sharing/tests/External/CacheTest.php
+++ b/apps/files_sharing/tests/External/CacheTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -17,6 +19,7 @@ use OCP\Files\Cache\ICacheEntry;
use OCP\ICacheFactory;
use OCP\IURLGenerator;
use OCP\IUserManager;
+use PHPUnit\Framework\MockObject\MockObject;
/**
* Class Cache
@@ -26,26 +29,11 @@ use OCP\IUserManager;
* @package OCA\Files_Sharing\Tests\External
*/
class CacheTest extends TestCase {
- /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
- protected $contactsManager;
-
- /**
- * @var Storage
- **/
- private $storage;
-
- /**
- * @var Cache
- */
- private $cache;
-
- /**
- * @var string
- */
- private $remoteUser;
-
- /** @var ICloudIdManager */
- private $cloudIdManager;
+ protected IManager&MockObject $contactsManager;
+ private Storage $storage;
+ private Cache $cache;
+ private string $remoteUser;
+ private ICloudIdManager $cloudIdManager;
protected function setUp(): void {
parent::setUp();
@@ -61,9 +49,7 @@ class CacheTest extends TestCase {
);
$this->remoteUser = $this->getUniqueID('remoteuser');
- $this->storage = $this->getMockBuilder('\OCA\Files_Sharing\External\Storage')
- ->disableOriginalConstructor()
- ->getMock();
+ $this->storage = $this->createMock(\OCA\Files_Sharing\External\Storage::class);
$this->storage
->expects($this->any())
->method('getId')
@@ -127,7 +113,7 @@ class CacheTest extends TestCase {
);
$results = $this->cache->getFolderContentsById($dirId);
- $this->assertEquals(1, count($results));
+ $this->assertCount(1, $results);
$this->assertEquals(
$this->remoteUser . '@example.com/owncloud',
$results[0]['displayname_owner']
diff --git a/apps/files_sharing/tests/External/ManagerTest.php b/apps/files_sharing/tests/External/ManagerTest.php
index 611392c286e..1d59a797ea7 100644
--- a/apps/files_sharing/tests/External/ManagerTest.php
+++ b/apps/files_sharing/tests/External/ManagerTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -33,6 +35,7 @@ use OCP\IUserSession;
use OCP\OCS\IDiscoveryService;
use OCP\Server;
use OCP\Share\IShare;
+use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use Test\Traits\UserTrait;
@@ -46,42 +49,19 @@ use Test\Traits\UserTrait;
class ManagerTest extends TestCase {
use UserTrait;
- /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
- protected $contactsManager;
-
- /** @var Manager|\PHPUnit\Framework\MockObject\MockObject * */
- private $manager;
-
- /** @var \OC\Files\Mount\Manager */
- private $mountManager;
-
- /** @var IClientService|\PHPUnit\Framework\MockObject\MockObject */
- private $clientService;
-
- /** @var ICloudFederationProviderManager|\PHPUnit\Framework\MockObject\MockObject */
- private $cloudFederationProviderManager;
-
- /** @var ICloudFederationFactory|\PHPUnit\Framework\MockObject\MockObject */
- private $cloudFederationFactory;
-
- /** @var \PHPUnit\Framework\MockObject\MockObject|IGroupManager */
- private $groupManager;
-
- /** @var \PHPUnit\Framework\MockObject\MockObject|IUserManager */
- private $userManager;
-
- /** @var LoggerInterface */
- private $logger;
-
- private $uid;
-
- /**
- * @var IUser
- */
- private $user;
+ protected IManager&MockObject $contactsManager;
+ private Manager&MockObject $manager;
+ private \OC\Files\Mount\Manager $mountManager;
+ private IClientService&MockObject $clientService;
+ private ICloudFederationProviderManager&MockObject $cloudFederationProviderManager;
+ private ICloudFederationFactory&MockObject $cloudFederationFactory;
+ private IGroupManager&MockObject $groupManager;
+ private IUserManager&MockObject $userManager;
+ private LoggerInterface$logger;
+ private string $uid;
+ private IUser $user;
private $testMountProvider;
- /** @var IEventDispatcher|\PHPUnit\Framework\MockObject\MockObject */
- private $eventDispatcher;
+ private IEventDispatcher&MockObject $eventDispatcher;
protected function setUp(): void {
parent::setUp();
@@ -89,8 +69,7 @@ class ManagerTest extends TestCase {
$this->uid = $this->getUniqueID('user');
$this->user = $this->createUser($this->uid, '');
$this->mountManager = new \OC\Files\Mount\Manager($this->createMock(SetupManagerFactory::class));
- $this->clientService = $this->getMockBuilder(IClientService::class)
- ->disableOriginalConstructor()->getMock();
+ $this->clientService = $this->createMock(IClientService::class);
$this->cloudFederationProviderManager = $this->createMock(ICloudFederationProviderManager::class);
$this->cloudFederationFactory = $this->createMock(ICloudFederationFactory::class);
$this->groupManager = $this->createMock(IGroupManager::class);
@@ -129,17 +108,16 @@ class ManagerTest extends TestCase {
$this->userManager->expects($this->any())->method('get')->willReturn($this->user);
$this->groupManager->expects($this->any())->method(('getUserGroups'))->willReturn([$group1, $group2]);
$this->groupManager->expects($this->any())->method(('get'))
- ->will($this->returnValueMap([
+ ->willReturnMap([
['group1', $group1],
['group2', $group2],
- ]));
+ ]);
}
protected function tearDown(): void {
// clear the share external table to avoid side effects
- $query = Server::get(IDBConnection::class)->prepare('DELETE FROM `*PREFIX*share_external`');
- $result = $query->execute();
- $result->closeCursor();
+ $query = Server::get(IDBConnection::class)->getQueryBuilder()->delete('share_external');
+ $query->executeStatement();
parent::tearDown();
}
@@ -169,10 +147,12 @@ class ManagerTest extends TestCase {
$this->eventDispatcher,
$this->logger,
]
- )->setMethods(['tryOCMEndPoint'])->getMock();
+ )
+ ->onlyMethods(['tryOCMEndPoint'])
+ ->getMock();
}
- private function setupMounts() {
+ private function setupMounts(): void {
$this->clearMounts();
$mounts = $this->testMountProvider->getMountsForUser($this->user, new StorageFactory());
foreach ($mounts as $mount) {
@@ -180,7 +160,7 @@ class ManagerTest extends TestCase {
}
}
- private function clearMounts() {
+ private function clearMounts(): void {
$this->mountManager->clear();
$this->mountManager->addMount(new MountPoint(Temporary::class, '', []));
}
@@ -223,13 +203,10 @@ class ManagerTest extends TestCase {
$this->manager->expects($this->never())->method('tryOCMEndPoint');
} else {
$this->manager->method('tryOCMEndPoint')
- ->withConsecutive(
- ['http://localhost', 'token1', '2342', 'accept'],
- ['http://localhost', 'token3', '2342', 'decline'],
- )->willReturnOnConsecutiveCalls(
- false,
- false,
- );
+ ->willReturnMap([
+ ['http://localhost', 'token1', '2342', 'accept', false],
+ ['http://localhost', 'token3', '2342', 'decline', false],
+ ]);
}
// Add a share for "user"
diff --git a/apps/files_sharing/tests/External/ScannerTest.php b/apps/files_sharing/tests/External/ScannerTest.php
index 6241174fb28..b57f26b442d 100644
--- a/apps/files_sharing/tests/External/ScannerTest.php
+++ b/apps/files_sharing/tests/External/ScannerTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2018-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -9,6 +11,7 @@ namespace OCA\Files_Sharing\Tests\External;
use OC\Files\Cache\Cache;
use OCA\Files_Sharing\External\Scanner;
use OCA\Files_Sharing\External\Storage;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
/**
@@ -16,20 +19,14 @@ use Test\TestCase;
*/
class ScannerTest extends TestCase {
protected Scanner $scanner;
- /** @var Storage|\PHPUnit\Framework\MockObject\MockObject */
- protected $storage;
- /** @var Cache|\PHPUnit\Framework\MockObject\MockObject */
- protected $cache;
+ protected Storage&MockObject $storage;
+ protected Cache&MockObject $cache;
protected function setUp(): void {
parent::setUp();
- $this->storage = $this->getMockBuilder('\OCA\Files_Sharing\External\Storage')
- ->disableOriginalConstructor()
- ->getMock();
- $this->cache = $this->getMockBuilder('\OC\Files\Cache\Cache')
- ->disableOriginalConstructor()
- ->getMock();
+ $this->storage = $this->createMock(Storage::class);
+ $this->cache = $this->createMock(Cache::class);
$this->storage->expects($this->any())
->method('getCache')
->willReturn($this->cache);
diff --git a/apps/files_sharing/tests/Middleware/OCSShareAPIMiddlewareTest.php b/apps/files_sharing/tests/Middleware/OCSShareAPIMiddlewareTest.php
index 30bae45f520..55d110b6c29 100644
--- a/apps/files_sharing/tests/Middleware/OCSShareAPIMiddlewareTest.php
+++ b/apps/files_sharing/tests/Middleware/OCSShareAPIMiddlewareTest.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
@@ -8,22 +10,20 @@ namespace OCA\Files_Sharing\Tests\Middleware;
use OCA\Files_Sharing\Controller\ShareAPIController;
use OCA\Files_Sharing\Middleware\OCSShareAPIMiddleware;
use OCP\AppFramework\Controller;
+use OCP\AppFramework\Http\Response;
use OCP\AppFramework\OCS\OCSNotFoundException;
use OCP\AppFramework\OCSController;
use OCP\IL10N;
use OCP\Share\IManager;
+use PHPUnit\Framework\MockObject\MockObject;
/**
* @package OCA\Files_Sharing\Middleware\SharingCheckMiddleware
*/
class OCSShareAPIMiddlewareTest extends \Test\TestCase {
-
- /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
- private $shareManager;
- /** @var IL10N */
- private $l;
- /** @var OCSShareAPIMiddleware */
- private $middleware;
+ private IManager&MockObject $shareManager;
+ private IL10N&MockObject $l;
+ private OCSShareAPIMiddleware $middleware;
protected function setUp(): void {
parent::setUp();
@@ -36,35 +36,35 @@ class OCSShareAPIMiddlewareTest extends \Test\TestCase {
$this->middleware = new OCSShareAPIMiddleware($this->shareManager, $this->l);
}
- public function dataBeforeController() {
+ public static function dataBeforeController(): array {
return [
[
- $this->createMock(Controller::class),
+ Controller::class,
false,
false
],
[
- $this->createMock(Controller::class),
+ Controller::class,
true,
false
],
[
- $this->createMock(OCSController::class),
+ OCSController::class,
false,
false
],
[
- $this->createMock(OCSController::class),
+ OCSController::class,
true,
false
],
[
- $this->createMock(ShareAPIController::class),
+ ShareAPIController::class,
false,
true
],
[
- $this->createMock(ShareAPIController::class),
+ ShareAPIController::class,
true,
false
],
@@ -73,13 +73,10 @@ class OCSShareAPIMiddlewareTest extends \Test\TestCase {
/**
* @dataProvider dataBeforeController
- *
- * @param Controller $controller
- * @param bool $enabled
- * @param bool $exception
*/
- public function testBeforeController(Controller $controller, $enabled, $exception): void {
+ public function testBeforeController(string $controllerClass, bool $enabled, bool $exception): void {
$this->shareManager->method('shareApiEnabled')->willReturn($enabled);
+ $controller = $this->createMock($controllerClass);
try {
$this->middleware->beforeController($controller, 'foo');
@@ -89,34 +86,24 @@ class OCSShareAPIMiddlewareTest extends \Test\TestCase {
}
}
- public function dataAfterController() {
+ public static function dataAfterController(): array {
return [
- [
- $this->createMock(Controller::class),
- ],
- [
- $this->createMock(OCSController::class),
- ],
- [
- $this->createMock(ShareAPIController::class),
- ],
+ [Controller::class],
+ [OCSController::class],
+ [ShareAPIController::class],
];
}
/**
* @dataProvider dataAfterController
- *
- * @param Controller $controller
- * @param bool $called
*/
- public function testAfterController(Controller $controller): void {
+ public function testAfterController(string $controllerClass): void {
+ $controller = $this->createMock($controllerClass);
if ($controller instanceof ShareAPIController) {
$controller->expects($this->once())->method('cleanup');
}
- $response = $this->getMockBuilder('OCP\AppFramework\Http\Response')
- ->disableOriginalConstructor()
- ->getMock();
+ $response = $this->createMock(Response::class);
$this->middleware->afterController($controller, 'foo', $response);
$this->addToAssertionCount(1);
}
diff --git a/apps/files_sharing/tests/Middleware/ShareInfoMiddlewareTest.php b/apps/files_sharing/tests/Middleware/ShareInfoMiddlewareTest.php
index 44ef3bebdc8..27d96608417 100644
--- a/apps/files_sharing/tests/Middleware/ShareInfoMiddlewareTest.php
+++ b/apps/files_sharing/tests/Middleware/ShareInfoMiddlewareTest.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
@@ -13,15 +15,12 @@ use OCP\AppFramework\Http;
use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Http\Response;
use OCP\Share\IManager as ShareManager;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class ShareInfoMiddlewareTest extends TestCase {
-
- /** @var ShareManager|\PHPUnit\Framework\MockObject\MockObject */
- private $shareManager;
-
- /** @var ShareInfoMiddleware */
- private $middleware;
+ private ShareManager&MockObject $shareManager;
+ private ShareInfoMiddleware $middleware;
protected function setUp(): void {
parent::setUp();
diff --git a/apps/files_sharing/tests/Middleware/SharingCheckMiddlewareTest.php b/apps/files_sharing/tests/Middleware/SharingCheckMiddlewareTest.php
index 5b4f4de33d7..26b634cf20c 100644
--- a/apps/files_sharing/tests/Middleware/SharingCheckMiddlewareTest.php
+++ b/apps/files_sharing/tests/Middleware/SharingCheckMiddlewareTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -19,26 +21,19 @@ use OCP\IConfig;
use OCP\IRequest;
use OCP\Share\IManager;
use OCP\Share\IShare;
+use PHPUnit\Framework\MockObject\MockObject;
/**
* @package OCA\Files_Sharing\Middleware\SharingCheckMiddleware
*/
class SharingCheckMiddlewareTest extends \Test\TestCase {
-
- /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
- private $config;
- /** @var IAppManager|\PHPUnit\Framework\MockObject\MockObject */
- private $appManager;
- /** @var SharingCheckMiddleware */
- private $sharingCheckMiddleware;
- /** @var Controller|\PHPUnit\Framework\MockObject\MockObject */
- private $controllerMock;
- /** @var IControllerMethodReflector|\PHPUnit\Framework\MockObject\MockObject */
- private $reflector;
- /** @var IManager | \PHPUnit\Framework\MockObject\MockObject */
- private $shareManager;
- /** @var IRequest | \PHPUnit\Framework\MockObject\MockObject */
- private $request;
+ private IConfig&MockObject $config;
+ private IAppManager&MockObject $appManager;
+ private SharingCheckMiddleware $sharingCheckMiddleware;
+ private Controller&MockObject $controllerMock;
+ private IControllerMethodReflector&MockObject $reflector;
+ private IManager&MockObject $shareManager;
+ private IRequest&MockObject $request;
protected function setUp(): void {
parent::setUp();
@@ -79,7 +74,7 @@ class SharingCheckMiddlewareTest extends \Test\TestCase {
$this->assertFalse(self::invokePrivate($this->sharingCheckMiddleware, 'isSharingEnabled'));
}
- public function externalSharesChecksDataProvider() {
+ public static function externalSharesChecksDataProvider(): array {
$data = [];
foreach ([false, true] as $annIn) {
@@ -117,7 +112,7 @@ class SharingCheckMiddlewareTest extends \Test\TestCase {
/**
* @dataProvider externalSharesChecksDataProvider
*/
- public function testExternalSharesChecks($annotations, $config, $expectedResult): void {
+ public function testExternalSharesChecks(array $annotations, array $config, bool $expectedResult): void {
$this->reflector
->expects($this->atLeastOnce())
->method('hasAnnotation')
@@ -133,7 +128,7 @@ class SharingCheckMiddlewareTest extends \Test\TestCase {
/**
* @dataProvider externalSharesChecksDataProvider
*/
- public function testBeforeControllerWithExternalShareControllerWithSharingEnabled($annotations, $config, $noException): void {
+ public function testBeforeControllerWithExternalShareControllerWithSharingEnabled(array $annotations, array $config, bool $noException): void {
$this->appManager
->expects($this->once())
->method('isEnabledForUser')
@@ -163,8 +158,6 @@ class SharingCheckMiddlewareTest extends \Test\TestCase {
}
public function testBeforeControllerWithShareControllerWithSharingEnabled(): void {
- $share = $this->createMock(IShare::class);
-
$this->appManager
->expects($this->once())
->method('isEnabledForUser')
diff --git a/apps/files_sharing/tests/Migration/SetPasswordColumnTest.php b/apps/files_sharing/tests/Migration/SetPasswordColumnTest.php
index 9dccfd80025..e4e4fc560ce 100644
--- a/apps/files_sharing/tests/Migration/SetPasswordColumnTest.php
+++ b/apps/files_sharing/tests/Migration/SetPasswordColumnTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2017 ownCloud, Inc.
@@ -13,6 +15,7 @@ use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Server;
use OCP\Share\IShare;
+use PHPUnit\Framework\MockObject\MockObject;
/**
* Class SetPasswordColumnTest
@@ -20,15 +23,9 @@ use OCP\Share\IShare;
* @group DB
*/
class SetPasswordColumnTest extends TestCase {
-
- /** @var IDBConnection */
- private $connection;
-
- /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
- private $config;
-
- /** @var SetPasswordColumn */
- private $migration;
+ private IDBConnection $connection;
+ private IConfig&MockObject $config;
+ private SetPasswordColumn $migration;
private $table = 'share';
@@ -43,13 +40,13 @@ class SetPasswordColumnTest extends TestCase {
}
protected function tearDown(): void {
- parent::tearDown();
$this->cleanDB();
+ parent::tearDown();
}
- private function cleanDB() {
+ private function cleanDB(): void {
$query = $this->connection->getQueryBuilder();
- $query->delete($this->table)->execute();
+ $query->delete($this->table)->executeStatement();
}
public function testAddPasswordColumn(): void {
diff --git a/apps/files_sharing/tests/TestCase.php b/apps/files_sharing/tests/TestCase.php
index 34e2d71fb02..c2c1b4d2600 100644
--- a/apps/files_sharing/tests/TestCase.php
+++ b/apps/files_sharing/tests/TestCase.php
@@ -22,7 +22,9 @@ use OCP\IGroupManager;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\Server;
+use OCP\Share\IManager;
use OCP\Share\IShare;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\Traits\MountProviderTrait;
/**
@@ -55,8 +57,7 @@ abstract class TestCase extends \Test\TestCase {
public $folder;
public $subfolder;
- /** @var \OCP\Share\IManager */
- protected $shareManager;
+ protected IManager $shareManager;
/** @var IRootFolder */
protected $rootFolder;