aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/tests/External
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_sharing/tests/External')
-rw-r--r--apps/files_sharing/tests/External/CacheTest.php5
-rw-r--r--apps/files_sharing/tests/External/ManagerTest.php113
-rw-r--r--apps/files_sharing/tests/External/ScannerTest.php1
3 files changed, 48 insertions, 71 deletions
diff --git a/apps/files_sharing/tests/External/CacheTest.php b/apps/files_sharing/tests/External/CacheTest.php
index 5a862d8ddc0..39e2057a24c 100644
--- a/apps/files_sharing/tests/External/CacheTest.php
+++ b/apps/files_sharing/tests/External/CacheTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -53,11 +54,11 @@ class CacheTest extends TestCase {
$this->contactsManager = $this->createMock(IManager::class);
$this->cloudIdManager = new CloudIdManager(
+ $this->createMock(ICacheFactory::class),
+ $this->createMock(IEventDispatcher::class),
$this->contactsManager,
$this->createMock(IURLGenerator::class),
$this->createMock(IUserManager::class),
- $this->createMock(ICacheFactory::class),
- $this->createMock(IEventDispatcher::class)
);
$this->remoteUser = $this->getUniqueID('remoteuser');
diff --git a/apps/files_sharing/tests/External/ManagerTest.php b/apps/files_sharing/tests/External/ManagerTest.php
index c8566098707..14c6afec4d8 100644
--- a/apps/files_sharing/tests/External/ManagerTest.php
+++ b/apps/files_sharing/tests/External/ManagerTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -19,6 +20,7 @@ use OCP\EventDispatcher\IEventDispatcher;
use OCP\Federation\ICloudFederationFactory;
use OCP\Federation\ICloudFederationProviderManager;
use OCP\Files\NotFoundException;
+use OCP\Http\Client\IClient;
use OCP\Http\Client\IClientService;
use OCP\Http\Client\IResponse;
use OCP\ICacheFactory;
@@ -32,6 +34,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;
@@ -45,42 +48,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;
- private $testMountProvider;
- /** @var IEventDispatcher|\PHPUnit\Framework\MockObject\MockObject */
- private $eventDispatcher;
+ protected string $uid;
+ protected IUser $user;
+ protected MountProvider $testMountProvider;
+ protected IEventDispatcher&MockObject $eventDispatcher;
+ protected LoggerInterface&MockObject $logger;
+ protected \OC\Files\Mount\Manager $mountManager;
+ protected IManager&MockObject $contactsManager;
+ protected Manager&MockObject $manager;
+ protected IClientService&MockObject $clientService;
+ protected ICloudFederationProviderManager&MockObject $cloudFederationProviderManager;
+ protected ICloudFederationFactory&MockObject $cloudFederationFactory;
+ protected IGroupManager&MockObject $groupManager;
+ protected IUserManager&MockObject $userManager;
protected function setUp(): void {
parent::setUp();
@@ -110,11 +90,11 @@ class ManagerTest extends TestCase {
$this->testMountProvider = new MountProvider(Server::get(IDBConnection::class), function () {
return $this->manager;
}, new CloudIdManager(
+ $this->createMock(ICacheFactory::class),
+ $this->createMock(IEventDispatcher::class),
$this->contactsManager,
$this->createMock(IURLGenerator::class),
$this->userManager,
- $this->createMock(ICacheFactory::class),
- $this->createMock(IEventDispatcher::class)
));
$group1 = $this->createMock(IGroup::class);
@@ -128,10 +108,10 @@ 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 {
@@ -168,7 +148,7 @@ class ManagerTest extends TestCase {
$this->eventDispatcher,
$this->logger,
]
- )->setMethods(['tryOCMEndPoint'])->getMock();
+ )->onlyMethods(['tryOCMEndPoint'])->getMock();
}
private function setupMounts() {
@@ -221,14 +201,12 @@ class ManagerTest extends TestCase {
if ($isGroup) {
$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,
- );
+ $this->manager->expects(self::atLeast(2))
+ ->method('tryOCMEndPoint')
+ ->willReturnMap([
+ ['http://localhost', 'token1', '2342', 'accept', false],
+ ['http://localhost', 'token3', '2342', 'decline', false],
+ ]);
}
// Add a share for "user"
@@ -254,12 +232,18 @@ class ManagerTest extends TestCase {
$this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}');
$this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}-1');
+ $newClientCalls = [];
+ $this->clientService
+ ->method('newClient')
+ ->willReturnCallback(function () use (&$newClientCalls): IClient {
+ if (!empty($newClientCalls)) {
+ return array_shift($newClientCalls);
+ }
+ return $this->createMock(IClient::class);
+ });
if (!$isGroup) {
- $client = $this->getMockBuilder('OCP\Http\Client\IClient')
- ->disableOriginalConstructor()->getMock();
- $this->clientService->expects($this->at(0))
- ->method('newClient')
- ->willReturn($client);
+ $client = $this->createMock(IClient::class);
+ $newClientCalls[] = $client;
$response = $this->createMock(IResponse::class);
$response->method('getBody')
->willReturn(json_encode([
@@ -311,11 +295,8 @@ class ManagerTest extends TestCase {
$this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}-1');
if (!$isGroup) {
- $client = $this->getMockBuilder('OCP\Http\Client\IClient')
- ->disableOriginalConstructor()->getMock();
- $this->clientService->expects($this->at(0))
- ->method('newClient')
- ->willReturn($client);
+ $client = $this->createMock(IClient::class);
+ $newClientCalls[] = $client;
$response = $this->createMock(IResponse::class);
$response->method('getBody')
->willReturn(json_encode([
@@ -367,16 +348,10 @@ class ManagerTest extends TestCase {
// no http requests here
$this->manager->removeGroupShares('group1');
} else {
- $client1 = $this->getMockBuilder('OCP\Http\Client\IClient')
- ->disableOriginalConstructor()->getMock();
- $client2 = $this->getMockBuilder('OCP\Http\Client\IClient')
- ->disableOriginalConstructor()->getMock();
- $this->clientService->expects($this->exactly(2))
- ->method('newClient')
- ->willReturnOnConsecutiveCalls(
- $client1,
- $client2,
- );
+ $client1 = $this->createMock(IClient::class);
+ $client2 = $this->createMock(IClient::class);
+ $newClientCalls[] = $client1;
+ $newClientCalls[] = $client2;
$response = $this->createMock(IResponse::class);
$response->method('getBody')
->willReturn(json_encode([
diff --git a/apps/files_sharing/tests/External/ScannerTest.php b/apps/files_sharing/tests/External/ScannerTest.php
index 6241174fb28..8b44d47f2b1 100644
--- a/apps/files_sharing/tests/External/ScannerTest.php
+++ b/apps/files_sharing/tests/External/ScannerTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2018-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.