aboutsummaryrefslogtreecommitdiffstats
path: root/apps/federation/tests
diff options
context:
space:
mode:
Diffstat (limited to 'apps/federation/tests')
-rw-r--r--apps/federation/tests/BackgroundJob/GetSharedSecretTest.php64
-rw-r--r--apps/federation/tests/BackgroundJob/RequestSharedSecretTest.php122
-rw-r--r--apps/federation/tests/Controller/OCSAuthAPIControllerTest.php57
-rw-r--r--apps/federation/tests/Controller/SettingsControllerTest.php38
-rw-r--r--apps/federation/tests/DAV/FedAuthTest.php20
-rw-r--r--apps/federation/tests/DbHandlerTest.php100
-rw-r--r--apps/federation/tests/Settings/AdminTest.php11
-rw-r--r--apps/federation/tests/SyncFederationAddressbooksTest.php84
-rw-r--r--apps/federation/tests/TrustedServersTest.php130
9 files changed, 247 insertions, 379 deletions
diff --git a/apps/federation/tests/BackgroundJob/GetSharedSecretTest.php b/apps/federation/tests/BackgroundJob/GetSharedSecretTest.php
index 3da2e2e15e4..943bdf352de 100644
--- a/apps/federation/tests/BackgroundJob/GetSharedSecretTest.php
+++ b/apps/federation/tests/BackgroundJob/GetSharedSecretTest.php
@@ -1,5 +1,6 @@
<?php
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -75,14 +76,9 @@ class GetSharedSecretTest extends TestCase {
);
}
- /**
- * @dataProvider dataTestExecute
- *
- * @param bool $isTrustedServer
- * @param bool $retainBackgroundJob
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestExecute')]
public function testExecute(bool $isTrustedServer, bool $retainBackgroundJob): void {
- /** @var GetSharedSecret |\PHPUnit\Framework\MockObject\MockObject $getSharedSecret */
+ /** @var GetSharedSecret&MockObject $getSharedSecret */
$getSharedSecret = $this->getMockBuilder(GetSharedSecret::class)
->setConstructorArgs(
[
@@ -95,8 +91,10 @@ class GetSharedSecretTest extends TestCase {
$this->timeFactory,
$this->config,
]
- )->setMethods(['parentStart'])->getMock();
- $this->invokePrivate($getSharedSecret, 'argument', [['url' => 'url', 'token' => 'token']]);
+ )
+ ->onlyMethods(['parentStart'])
+ ->getMock();
+ self::invokePrivate($getSharedSecret, 'argument', [['url' => 'url', 'token' => 'token']]);
$this->trustedServers->expects($this->once())->method('isTrustedServer')
->with('url')->willReturn($isTrustedServer);
@@ -105,7 +103,7 @@ class GetSharedSecretTest extends TestCase {
} else {
$getSharedSecret->expects($this->never())->method('parentStart');
}
- $this->invokePrivate($getSharedSecret, 'retainJob', [$retainBackgroundJob]);
+ self::invokePrivate($getSharedSecret, 'retainJob', [$retainBackgroundJob]);
$this->jobList->expects($this->once())->method('remove');
$this->timeFactory->method('getTime')->willReturn(42);
@@ -128,7 +126,7 @@ class GetSharedSecretTest extends TestCase {
$getSharedSecret->start($this->jobList);
}
- public function dataTestExecute() {
+ public static function dataTestExecute(): array {
return [
[true, true],
[true, false],
@@ -136,12 +134,8 @@ class GetSharedSecretTest extends TestCase {
];
}
- /**
- * @dataProvider dataTestRun
- *
- * @param int $statusCode
- */
- public function testRun($statusCode): void {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestRun')]
+ public function testRun(int $statusCode): void {
$target = 'targetURL';
$source = 'sourceURL';
$token = 'token';
@@ -157,12 +151,11 @@ class GetSharedSecretTest extends TestCase {
->with(
$target . '/ocs/v2.php/apps/federation/api/v1/shared-secret',
[
- 'query' =>
- [
- 'url' => $source,
- 'token' => $token,
- 'format' => 'json',
- ],
+ 'query' => [
+ 'url' => $source,
+ 'token' => $token,
+ 'format' => 'json',
+ ],
'timeout' => 3,
'connect_timeout' => 3,
'verify' => true,
@@ -181,18 +174,18 @@ class GetSharedSecretTest extends TestCase {
$this->trustedServers->expects($this->never())->method('addSharedSecret');
}
- $this->invokePrivate($this->getSharedSecret, 'run', [$argument]);
+ self::invokePrivate($this->getSharedSecret, 'run', [$argument]);
if (
$statusCode !== Http::STATUS_OK
&& $statusCode !== Http::STATUS_FORBIDDEN
) {
- $this->assertTrue($this->invokePrivate($this->getSharedSecret, 'retainJob'));
+ $this->assertTrue(self::invokePrivate($this->getSharedSecret, 'retainJob'));
} else {
- $this->assertFalse($this->invokePrivate($this->getSharedSecret, 'retainJob'));
+ $this->assertFalse(self::invokePrivate($this->getSharedSecret, 'retainJob'));
}
}
- public function dataTestRun() {
+ public static function dataTestRun(): array {
return [
[Http::STATUS_OK],
[Http::STATUS_FORBIDDEN],
@@ -227,7 +220,7 @@ class GetSharedSecretTest extends TestCase {
TrustedServers::STATUS_FAILURE
);
- $this->invokePrivate($this->getSharedSecret, 'run', [$argument]);
+ self::invokePrivate($this->getSharedSecret, 'run', [$argument]);
}
public function testRunConnectionError(): void {
@@ -249,12 +242,11 @@ class GetSharedSecretTest extends TestCase {
->with(
$target . '/ocs/v2.php/apps/federation/api/v1/shared-secret',
[
- 'query' =>
- [
- 'url' => $source,
- 'token' => $token,
- 'format' => 'json',
- ],
+ 'query' => [
+ 'url' => $source,
+ 'token' => $token,
+ 'format' => 'json',
+ ],
'timeout' => 3,
'connect_timeout' => 3,
'verify' => true,
@@ -263,8 +255,8 @@ class GetSharedSecretTest extends TestCase {
$this->trustedServers->expects($this->never())->method('addSharedSecret');
- $this->invokePrivate($this->getSharedSecret, 'run', [$argument]);
+ self::invokePrivate($this->getSharedSecret, 'run', [$argument]);
- $this->assertTrue($this->invokePrivate($this->getSharedSecret, 'retainJob'));
+ $this->assertTrue(self::invokePrivate($this->getSharedSecret, 'retainJob'));
}
}
diff --git a/apps/federation/tests/BackgroundJob/RequestSharedSecretTest.php b/apps/federation/tests/BackgroundJob/RequestSharedSecretTest.php
index 68f8cc070c8..6ef579c7483 100644
--- a/apps/federation/tests/BackgroundJob/RequestSharedSecretTest.php
+++ b/apps/federation/tests/BackgroundJob/RequestSharedSecretTest.php
@@ -1,5 +1,6 @@
<?php
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -24,50 +25,28 @@ use Psr\Log\LoggerInterface;
use Test\TestCase;
class RequestSharedSecretTest extends TestCase {
- /** @var MockObject|IClientService */
- private $httpClientService;
-
- /** @var MockObject|IClient */
- private $httpClient;
-
- /** @var MockObject|IJobList */
- private $jobList;
-
- /** @var MockObject|IURLGenerator */
- private $urlGenerator;
-
- /** @var MockObject|TrustedServers */
- private $trustedServers;
-
- /** @var MockObject|IResponse */
- private $response;
-
- /** @var MockObject|IDiscoveryService */
- private $discoveryService;
-
- /** @var MockObject|LoggerInterface */
- private $logger;
-
- /** @var MockObject|ITimeFactory */
- private $timeFactory;
-
- /** @var MockObject|IConfig */
- private $config;
-
- /** @var RequestSharedSecret */
- private $requestSharedSecret;
+ private IClientService&MockObject $httpClientService;
+ private IClient&MockObject $httpClient;
+ private IJobList&MockObject $jobList;
+ private IURLGenerator&MockObject $urlGenerator;
+ private TrustedServers&MockObject $trustedServers;
+ private IResponse&MockObject $response;
+ private IDiscoveryService&MockObject $discoveryService;
+ private LoggerInterface&MockObject $logger;
+ private ITimeFactory&MockObject $timeFactory;
+ private IConfig&MockObject $config;
+ private RequestSharedSecret $requestSharedSecret;
protected function setUp(): void {
parent::setUp();
$this->httpClientService = $this->createMock(IClientService::class);
- $this->httpClient = $this->getMockBuilder(IClient::class)->getMock();
- $this->jobList = $this->getMockBuilder(IJobList::class)->getMock();
- $this->urlGenerator = $this->getMockBuilder(IURLGenerator::class)->getMock();
- $this->trustedServers = $this->getMockBuilder(TrustedServers::class)
- ->disableOriginalConstructor()->getMock();
- $this->response = $this->getMockBuilder(IResponse::class)->getMock();
- $this->discoveryService = $this->getMockBuilder(IDiscoveryService::class)->getMock();
+ $this->httpClient = $this->createMock(IClient::class);
+ $this->jobList = $this->createMock(IJobList::class);
+ $this->urlGenerator = $this->createMock(IURLGenerator::class);
+ $this->trustedServers = $this->createMock(TrustedServers::class);
+ $this->response = $this->createMock(IResponse::class);
+ $this->discoveryService = $this->createMock(IDiscoveryService::class);
$this->logger = $this->createMock(LoggerInterface::class);
$this->timeFactory = $this->createMock(ITimeFactory::class);
$this->config = $this->createMock(IConfig::class);
@@ -87,15 +66,10 @@ class RequestSharedSecretTest extends TestCase {
);
}
- /**
- * @dataProvider dataTestStart
- *
- * @param bool $isTrustedServer
- * @param bool $retainBackgroundJob
- */
- public function testStart($isTrustedServer, $retainBackgroundJob): void {
- /** @var RequestSharedSecret |MockObject $requestSharedSecret */
- $requestSharedSecret = $this->getMockBuilder('OCA\Federation\BackgroundJob\RequestSharedSecret')
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestStart')]
+ public function testStart(bool $isTrustedServer, bool $retainBackgroundJob): void {
+ /** @var RequestSharedSecret&MockObject $requestSharedSecret */
+ $requestSharedSecret = $this->getMockBuilder(RequestSharedSecret::class)
->setConstructorArgs(
[
$this->httpClientService,
@@ -107,8 +81,10 @@ class RequestSharedSecretTest extends TestCase {
$this->timeFactory,
$this->config,
]
- )->setMethods(['parentStart'])->getMock();
- $this->invokePrivate($requestSharedSecret, 'argument', [['url' => 'url', 'token' => 'token']]);
+ )
+ ->onlyMethods(['parentStart'])
+ ->getMock();
+ self::invokePrivate($requestSharedSecret, 'argument', [['url' => 'url', 'token' => 'token']]);
$this->trustedServers->expects($this->once())->method('isTrustedServer')
->with('url')->willReturn($isTrustedServer);
@@ -117,7 +93,7 @@ class RequestSharedSecretTest extends TestCase {
} else {
$requestSharedSecret->expects($this->never())->method('parentStart');
}
- $this->invokePrivate($requestSharedSecret, 'retainJob', [$retainBackgroundJob]);
+ self::invokePrivate($requestSharedSecret, 'retainJob', [$retainBackgroundJob]);
$this->jobList->expects($this->once())->method('remove');
$this->timeFactory->method('getTime')->willReturn(42);
@@ -141,7 +117,7 @@ class RequestSharedSecretTest extends TestCase {
$requestSharedSecret->start($this->jobList);
}
- public function dataTestStart() {
+ public static function dataTestStart(): array {
return [
[true, true],
[true, false],
@@ -149,11 +125,7 @@ class RequestSharedSecretTest extends TestCase {
];
}
- /**
- * @dataProvider dataTestRun
- *
- * @param int $statusCode
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestRun')]
public function testRun(int $statusCode, int $attempt = 0): void {
$target = 'targetURL';
$source = 'sourceURL';
@@ -169,12 +141,11 @@ class RequestSharedSecretTest extends TestCase {
->with(
$target . '/ocs/v2.php/apps/federation/api/v1/request-shared-secret',
[
- 'body' =>
- [
- 'url' => $source,
- 'token' => $token,
- 'format' => 'json',
- ],
+ 'body' => [
+ 'url' => $source,
+ 'token' => $token,
+ 'format' => 'json',
+ ],
'timeout' => 3,
'connect_timeout' => 3,
'verify' => true,
@@ -184,18 +155,18 @@ class RequestSharedSecretTest extends TestCase {
$this->response->expects($this->once())->method('getStatusCode')
->willReturn($statusCode);
- $this->invokePrivate($this->requestSharedSecret, 'run', [$argument]);
+ self::invokePrivate($this->requestSharedSecret, 'run', [$argument]);
if (
$statusCode !== Http::STATUS_OK
&& ($statusCode !== Http::STATUS_FORBIDDEN || $attempt < 5)
) {
- $this->assertTrue($this->invokePrivate($this->requestSharedSecret, 'retainJob'));
+ $this->assertTrue(self::invokePrivate($this->requestSharedSecret, 'retainJob'));
} else {
- $this->assertFalse($this->invokePrivate($this->requestSharedSecret, 'retainJob'));
+ $this->assertFalse(self::invokePrivate($this->requestSharedSecret, 'retainJob'));
}
}
- public function dataTestRun() {
+ public static function dataTestRun(): array {
return [
[Http::STATUS_OK],
[Http::STATUS_FORBIDDEN, 5],
@@ -231,7 +202,7 @@ class RequestSharedSecretTest extends TestCase {
TrustedServers::STATUS_FAILURE
);
- $this->invokePrivate($this->requestSharedSecret, 'run', [$argument]);
+ self::invokePrivate($this->requestSharedSecret, 'run', [$argument]);
}
public function testRunConnectionError(): void {
@@ -255,19 +226,18 @@ class RequestSharedSecretTest extends TestCase {
->with(
$target . '/ocs/v2.php/apps/federation/api/v1/request-shared-secret',
[
- 'body' =>
- [
- 'url' => $source,
- 'token' => $token,
- 'format' => 'json',
- ],
+ 'body' => [
+ 'url' => $source,
+ 'token' => $token,
+ 'format' => 'json',
+ ],
'timeout' => 3,
'connect_timeout' => 3,
'verify' => true,
]
)->willThrowException($this->createMock(ConnectException::class));
- $this->invokePrivate($this->requestSharedSecret, 'run', [$argument]);
- $this->assertTrue($this->invokePrivate($this->requestSharedSecret, 'retainJob'));
+ self::invokePrivate($this->requestSharedSecret, 'run', [$argument]);
+ $this->assertTrue(self::invokePrivate($this->requestSharedSecret, 'retainJob'));
}
}
diff --git a/apps/federation/tests/Controller/OCSAuthAPIControllerTest.php b/apps/federation/tests/Controller/OCSAuthAPIControllerTest.php
index 9f2d41a1072..a054277c5cd 100644
--- a/apps/federation/tests/Controller/OCSAuthAPIControllerTest.php
+++ b/apps/federation/tests/Controller/OCSAuthAPIControllerTest.php
@@ -1,5 +1,6 @@
<?php
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -8,6 +9,7 @@
namespace OCA\Federation\Tests\Controller;
use OC\BackgroundJob\JobList;
+use OCA\Federation\BackgroundJob\GetSharedSecret;
use OCA\Federation\Controller\OCSAuthAPIController;
use OCA\Federation\DbHandler;
use OCA\Federation\TrustedServers;
@@ -16,34 +18,19 @@ use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IRequest;
use OCP\Security\Bruteforce\IThrottler;
use OCP\Security\ISecureRandom;
+use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use Test\TestCase;
class OCSAuthAPIControllerTest extends TestCase {
- /** @var \PHPUnit\Framework\MockObject\MockObject|IRequest */
- private $request;
-
- /** @var \PHPUnit\Framework\MockObject\MockObject|ISecureRandom */
- private $secureRandom;
-
- /** @var \PHPUnit\Framework\MockObject\MockObject|JobList */
- private $jobList;
-
- /** @var \PHPUnit\Framework\MockObject\MockObject|TrustedServers */
- private $trustedServers;
-
- /** @var \PHPUnit\Framework\MockObject\MockObject|DbHandler */
- private $dbHandler;
-
- /** @var \PHPUnit\Framework\MockObject\MockObject|LoggerInterface */
- private $logger;
-
- /** @var \PHPUnit\Framework\MockObject\MockObject|ITimeFactory */
- private $timeFactory;
-
- /** @var \PHPUnit\Framework\MockObject\MockObject|IThrottler */
- private $throttler;
-
+ private IRequest&MockObject $request;
+ private ISecureRandom&MockObject $secureRandom;
+ private JobList&MockObject $jobList;
+ private TrustedServers&MockObject $trustedServers;
+ private DbHandler&MockObject $dbHandler;
+ private LoggerInterface&MockObject $logger;
+ private ITimeFactory&MockObject $timeFactory;
+ private IThrottler&MockObject $throttler;
private OCSAuthAPIController $ocsAuthApi;
/** @var int simulated timestamp */
@@ -77,9 +64,7 @@ class OCSAuthAPIControllerTest extends TestCase {
->willReturn($this->currentTime);
}
- /**
- * @dataProvider dataTestRequestSharedSecret
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestRequestSharedSecret')]
public function testRequestSharedSecret(string $token, string $localToken, bool $isTrustedServer, bool $ok): void {
$url = 'url';
@@ -91,7 +76,7 @@ class OCSAuthAPIControllerTest extends TestCase {
if ($ok) {
$this->jobList->expects($this->once())->method('add')
- ->with('OCA\Federation\BackgroundJob\GetSharedSecret', ['url' => $url, 'token' => $token, 'created' => $this->currentTime]);
+ ->with(GetSharedSecret::class, ['url' => $url, 'token' => $token, 'created' => $this->currentTime]);
} else {
$this->jobList->expects($this->never())->method('add');
$this->jobList->expects($this->never())->method('remove');
@@ -111,7 +96,7 @@ class OCSAuthAPIControllerTest extends TestCase {
}
}
- public function dataTestRequestSharedSecret() {
+ public static function dataTestRequestSharedSecret(): array {
return [
['token2', 'token1', true, true],
['token1', 'token2', false, false],
@@ -119,15 +104,13 @@ class OCSAuthAPIControllerTest extends TestCase {
];
}
- /**
- * @dataProvider dataTestGetSharedSecret
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestGetSharedSecret')]
public function testGetSharedSecret(bool $isTrustedServer, bool $isValidToken, bool $ok): void {
$url = 'url';
$token = 'token';
- /** @var OCSAuthAPIController | \PHPUnit\Framework\MockObject\MockObject $ocsAuthApi */
- $ocsAuthApi = $this->getMockBuilder('OCA\Federation\Controller\OCSAuthAPIController')
+ /** @var OCSAuthAPIController&MockObject $ocsAuthApi */
+ $ocsAuthApi = $this->getMockBuilder(OCSAuthAPIController::class)
->setConstructorArgs(
[
'federation',
@@ -140,7 +123,9 @@ class OCSAuthAPIControllerTest extends TestCase {
$this->timeFactory,
$this->throttler
]
- )->setMethods(['isValidToken'])->getMock();
+ )
+ ->onlyMethods(['isValidToken'])
+ ->getMock();
$this->trustedServers
->expects($this->any())
@@ -171,7 +156,7 @@ class OCSAuthAPIControllerTest extends TestCase {
}
}
- public function dataTestGetSharedSecret() {
+ public static function dataTestGetSharedSecret(): array {
return [
[true, true, true],
[false, true, false],
diff --git a/apps/federation/tests/Controller/SettingsControllerTest.php b/apps/federation/tests/Controller/SettingsControllerTest.php
index c3e83945e9a..b0a7a5e30c9 100644
--- a/apps/federation/tests/Controller/SettingsControllerTest.php
+++ b/apps/federation/tests/Controller/SettingsControllerTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -20,19 +22,18 @@ use Test\TestCase;
class SettingsControllerTest extends TestCase {
private SettingsController $controller;
- private MockObject&IRequest $request;
- private MockObject&IL10N $l10n;
- private MockObject&TrustedServers $trustedServers;
- private MockObject&LoggerInterface $logger;
+ private IRequest&MockObject $request;
+ private IL10N&MockObject $l10n;
+ private TrustedServers&MockObject $trustedServers;
+ private LoggerInterface&MockObject $logger;
protected function setUp(): void {
parent::setUp();
- $this->request = $this->getMockBuilder(IRequest::class)->getMock();
- $this->l10n = $this->getMockBuilder(IL10N::class)->getMock();
- $this->trustedServers = $this->getMockBuilder(TrustedServers::class)
- ->disableOriginalConstructor()->getMock();
- $this->logger = $this->getMockBuilder(LoggerInterface::class)->getMock();
+ $this->request = $this->createMock(IRequest::class);
+ $this->l10n = $this->createMock(IL10N::class);
+ $this->trustedServers = $this->createMock(TrustedServers::class);
+ $this->logger = $this->createMock(LoggerInterface::class);
$this->controller = new SettingsController(
'SettingsControllerTest',
@@ -56,7 +57,7 @@ class SettingsControllerTest extends TestCase {
->willReturn(true);
$result = $this->controller->addServer('url');
- $this->assertTrue($result instanceof DataResponse);
+ $this->assertInstanceOf(DataResponse::class, $result);
$data = $result->getData();
$this->assertSame(200, $result->getStatus());
@@ -64,9 +65,7 @@ class SettingsControllerTest extends TestCase {
$this->assertArrayHasKey('id', $data);
}
- /**
- * @dataProvider checkServerFails
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('checkServerFails')]
public function testAddServerFail(bool $isTrustedServer, bool $isNextcloud): void {
$this->trustedServers
->expects($this->any())
@@ -110,13 +109,11 @@ class SettingsControllerTest extends TestCase {
->willReturn(true);
$this->assertNull(
- $this->invokePrivate($this->controller, 'checkServer', ['url'])
+ self::invokePrivate($this->controller, 'checkServer', ['url'])
);
}
- /**
- * @dataProvider checkServerFails
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('checkServerFails')]
public function testCheckServerFail(bool $isTrustedServer, bool $isNextcloud): void {
$this->trustedServers
->expects($this->any())
@@ -136,14 +133,11 @@ class SettingsControllerTest extends TestCase {
}
$this->assertTrue(
- $this->invokePrivate($this->controller, 'checkServer', ['url'])
+ self::invokePrivate($this->controller, 'checkServer', ['url'])
);
}
- /**
- * Data to simulate checkServer fails
- */
- public function checkServerFails(): array {
+ public static function checkServerFails(): array {
return [
[true, true],
[false, false]
diff --git a/apps/federation/tests/DAV/FedAuthTest.php b/apps/federation/tests/DAV/FedAuthTest.php
index d059fff0481..c95d3852b48 100644
--- a/apps/federation/tests/DAV/FedAuthTest.php
+++ b/apps/federation/tests/DAV/FedAuthTest.php
@@ -1,5 +1,6 @@
<?php
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -9,27 +10,22 @@ namespace OCA\Federation\Tests\DAV;
use OCA\Federation\DAV\FedAuth;
use OCA\Federation\DbHandler;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class FedAuthTest extends TestCase {
- /**
- * @dataProvider providesUser
- *
- * @param array $expected
- * @param string $user
- * @param string $password
- */
- public function testFedAuth($expected, $user, $password): void {
- /** @var DbHandler | \PHPUnit\Framework\MockObject\MockObject $db */
- $db = $this->getMockBuilder('OCA\Federation\DbHandler')->disableOriginalConstructor()->getMock();
+ #[\PHPUnit\Framework\Attributes\DataProvider('providesUser')]
+ public function testFedAuth(bool $expected, string $user, string $password): void {
+ /** @var DbHandler&MockObject $db */
+ $db = $this->createMock(DbHandler::class);
$db->method('auth')->willReturn(true);
$auth = new FedAuth($db);
- $result = $this->invokePrivate($auth, 'validateUserPass', [$user, $password]);
+ $result = self::invokePrivate($auth, 'validateUserPass', [$user, $password]);
$this->assertEquals($expected, $result);
}
- public function providesUser() {
+ public static function providesUser(): array {
return [
[true, 'system', '123456']
];
diff --git a/apps/federation/tests/DbHandlerTest.php b/apps/federation/tests/DbHandlerTest.php
index 1db9f7f2315..5452a48fc4a 100644
--- a/apps/federation/tests/DbHandlerTest.php
+++ b/apps/federation/tests/DbHandlerTest.php
@@ -1,5 +1,6 @@
<?php
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -12,30 +13,23 @@ use OCA\Federation\TrustedServers;
use OCP\IDBConnection;
use OCP\IL10N;
use OCP\Server;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
/**
* @group DB
*/
class DbHandlerTest extends TestCase {
-
- /** @var DbHandler */
- private $dbHandler;
-
- /** @var IL10N | \PHPUnit\Framework\MockObject\MockObject */
- private $il10n;
-
- /** @var IDBConnection */
- private $connection;
-
- /** @var string */
- private $dbTable = 'trusted_servers';
+ private DbHandler $dbHandler;
+ private IL10N&MockObject $il10n;
+ private IDBConnection $connection;
+ private string $dbTable = 'trusted_servers';
protected function setUp(): void {
parent::setUp();
$this->connection = Server::get(IDBConnection::class);
- $this->il10n = $this->getMockBuilder(IL10N::class)->getMock();
+ $this->il10n = $this->createMock(IL10N::class);
$this->dbHandler = new DbHandler(
$this->connection,
@@ -44,26 +38,27 @@ class DbHandlerTest extends TestCase {
$query = $this->connection->getQueryBuilder()->select('*')->from($this->dbTable);
- $qResult = $query->execute();
+ $qResult = $query->executeQuery();
$result = $qResult->fetchAll();
$qResult->closeCursor();
$this->assertEmpty($result, 'we need to start with a empty trusted_servers table');
}
protected function tearDown(): void {
- parent::tearDown();
$query = $this->connection->getQueryBuilder()->delete($this->dbTable);
- $query->execute();
+ $query->executeStatement()
+ ;
+ parent::tearDown();
}
/**
- * @dataProvider dataTestAddServer
*
* @param string $url passed to the method
* @param string $expectedUrl the url we expect to be written to the db
* @param string $expectedHash the hash value we expect to be written to the db
*/
- public function testAddServer($url, $expectedUrl, $expectedHash): void {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestAddServer')]
+ public function testAddServer(string $url, string $expectedUrl, string $expectedHash): void {
$id = $this->dbHandler->addServer($url);
$query = $this->connection->getQueryBuilder()->select('*')->from($this->dbTable);
@@ -71,14 +66,14 @@ class DbHandlerTest extends TestCase {
$qResult = $query->execute();
$result = $qResult->fetchAll();
$qResult->closeCursor();
- $this->assertSame(1, count($result));
+ $this->assertCount(1, $result);
$this->assertSame($expectedUrl, $result[0]['url']);
$this->assertSame($id, (int)$result[0]['id']);
$this->assertSame($expectedHash, $result[0]['url_hash']);
$this->assertSame(TrustedServers::STATUS_PENDING, (int)$result[0]['status']);
}
- public function dataTestAddServer() {
+ public static function dataTestAddServer(): array {
return [
['http://owncloud.org', 'http://owncloud.org', sha1('owncloud.org')],
['https://owncloud.org', 'https://owncloud.org', sha1('owncloud.org')],
@@ -95,7 +90,7 @@ class DbHandlerTest extends TestCase {
$qResult = $query->execute();
$result = $qResult->fetchAll();
$qResult->closeCursor();
- $this->assertSame(2, count($result));
+ $this->assertCount(2, $result);
$this->assertSame('server1', $result[0]['url']);
$this->assertSame('server2', $result[1]['url']);
$this->assertSame($id1, (int)$result[0]['id']);
@@ -107,7 +102,7 @@ class DbHandlerTest extends TestCase {
$qResult = $query->execute();
$result = $qResult->fetchAll();
$qResult->closeCursor();
- $this->assertSame(1, count($result));
+ $this->assertCount(1, $result);
$this->assertSame('server1', $result[0]['url']);
$this->assertSame($id1, (int)$result[0]['id']);
}
@@ -133,21 +128,15 @@ class DbHandlerTest extends TestCase {
$this->assertSame($id2, (int)$result[1]['id']);
}
- /**
- * @dataProvider dataTestServerExists
- *
- * @param string $serverInTable
- * @param string $checkForServer
- * @param bool $expected
- */
- public function testServerExists($serverInTable, $checkForServer, $expected): void {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestServerExists')]
+ public function testServerExists(string $serverInTable, string $checkForServer, bool $expected): void {
$this->dbHandler->addServer($serverInTable);
$this->assertSame($expected,
$this->dbHandler->serverExists($checkForServer)
);
}
- public function dataTestServerExists() {
+ public static function dataTestServerExists(): array {
return [
['server1', 'server1', true],
['server1', 'http://server1', true],
@@ -159,18 +148,18 @@ class DbHandlerTest extends TestCase {
$this->dbHandler->addServer('server1');
$query = $this->connection->getQueryBuilder()->select('*')->from($this->dbTable);
- $qResult = $query->execute();
+ $qResult = $query->executeQuery();
$result = $qResult->fetchAll();
$qResult->closeCursor();
- $this->assertSame(1, count($result));
+ $this->assertCount(1, $result);
$this->assertSame(null, $result[0]['token']);
$this->dbHandler->addToken('http://server1', 'token');
$query = $this->connection->getQueryBuilder()->select('*')->from($this->dbTable);
- $qResult = $query->execute();
+ $qResult = $query->executeQuery();
$result = $qResult->fetchAll();
$qResult->closeCursor();
- $this->assertSame(1, count($result));
+ $this->assertCount(1, $result);
$this->assertSame('token', $result[0]['token']);
}
@@ -189,7 +178,7 @@ class DbHandlerTest extends TestCase {
$qResult = $query->execute();
$result = $qResult->fetchAll();
$qResult->closeCursor();
- $this->assertSame(1, count($result));
+ $this->assertCount(1, $result);
$this->assertSame(null, $result[0]['shared_secret']);
$this->dbHandler->addSharedSecret('http://server1', 'secret');
$query = $this->connection->getQueryBuilder()->select('*')->from($this->dbTable);
@@ -197,7 +186,7 @@ class DbHandlerTest extends TestCase {
$qResult = $query->execute();
$result = $qResult->fetchAll();
$qResult->closeCursor();
- $this->assertSame(1, count($result));
+ $this->assertCount(1, $result);
$this->assertSame('secret', $result[0]['shared_secret']);
}
@@ -213,18 +202,18 @@ class DbHandlerTest extends TestCase {
$this->dbHandler->addServer('server1');
$query = $this->connection->getQueryBuilder()->select('*')->from($this->dbTable);
- $qResult = $query->execute();
+ $qResult = $query->executeQuery();
$result = $qResult->fetchAll();
$qResult->closeCursor();
- $this->assertSame(1, count($result));
+ $this->assertCount(1, $result);
$this->assertSame(TrustedServers::STATUS_PENDING, (int)$result[0]['status']);
$this->dbHandler->setServerStatus('http://server1', TrustedServers::STATUS_OK);
$query = $this->connection->getQueryBuilder()->select('*')->from($this->dbTable);
- $qResult = $query->execute();
+ $qResult = $query->executeQuery();
$result = $qResult->fetchAll();
$qResult->closeCursor();
- $this->assertSame(1, count($result));
+ $this->assertCount(1, $result);
$this->assertSame(TrustedServers::STATUS_OK, (int)$result[0]['status']);
}
@@ -243,19 +232,15 @@ class DbHandlerTest extends TestCase {
/**
* hash should always be computed with the normalized URL
- *
- * @dataProvider dataTestHash
- *
- * @param string $url
- * @param string $expected
*/
- public function testHash($url, $expected): void {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestHash')]
+ public function testHash(string $url, string $expected): void {
$this->assertSame($expected,
$this->invokePrivate($this->dbHandler, 'hash', [$url])
);
}
- public function dataTestHash() {
+ public static function dataTestHash(): array {
return [
['server1', sha1('server1')],
['http://server1', sha1('server1')],
@@ -264,19 +249,14 @@ class DbHandlerTest extends TestCase {
];
}
- /**
- * @dataProvider dataTestNormalizeUrl
- *
- * @param string $url
- * @param string $expected
- */
- public function testNormalizeUrl($url, $expected): void {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestNormalizeUrl')]
+ public function testNormalizeUrl(string $url, string $expected): void {
$this->assertSame($expected,
$this->invokePrivate($this->dbHandler, 'normalizeUrl', [$url])
);
}
- public function dataTestNormalizeUrl() {
+ public static function dataTestNormalizeUrl(): array {
return [
['owncloud.org', 'owncloud.org'],
['http://owncloud.org', 'owncloud.org'],
@@ -286,10 +266,8 @@ class DbHandlerTest extends TestCase {
];
}
- /**
- * @dataProvider providesAuth
- */
- public function testAuth($expectedResult, $user, $password): void {
+ #[\PHPUnit\Framework\Attributes\DataProvider('providesAuth')]
+ public function testAuth(bool $expectedResult, string $user, string $password): void {
if ($expectedResult) {
$this->dbHandler->addServer('url1');
$this->dbHandler->addSharedSecret('url1', $password);
@@ -298,7 +276,7 @@ class DbHandlerTest extends TestCase {
$this->assertEquals($expectedResult, $result);
}
- public function providesAuth() {
+ public static function providesAuth(): array {
return [
[false, 'foo', ''],
[true, 'system', '123456789'],
diff --git a/apps/federation/tests/Settings/AdminTest.php b/apps/federation/tests/Settings/AdminTest.php
index 3d58fae2d7b..b879547a8cd 100644
--- a/apps/federation/tests/Settings/AdminTest.php
+++ b/apps/federation/tests/Settings/AdminTest.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
@@ -9,17 +11,16 @@ use OCA\Federation\Settings\Admin;
use OCA\Federation\TrustedServers;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IL10N;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class AdminTest extends TestCase {
- /** @var Admin */
- private $admin;
- /** @var TrustedServers */
- private $trustedServers;
+ private TrustedServers&MockObject $trustedServers;
+ private Admin $admin;
protected function setUp(): void {
parent::setUp();
- $this->trustedServers = $this->getMockBuilder('\OCA\Federation\TrustedServers')->disableOriginalConstructor()->getMock();
+ $this->trustedServers = $this->createMock(TrustedServers::class);
$this->admin = new Admin(
$this->trustedServers,
$this->createMock(IL10N::class)
diff --git a/apps/federation/tests/SyncFederationAddressbooksTest.php b/apps/federation/tests/SyncFederationAddressbooksTest.php
index 39274a11ade..8b075204859 100644
--- a/apps/federation/tests/SyncFederationAddressbooksTest.php
+++ b/apps/federation/tests/SyncFederationAddressbooksTest.php
@@ -1,5 +1,6 @@
<?php
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -16,44 +17,33 @@ use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
class SyncFederationAddressbooksTest extends \Test\TestCase {
-
- /** @var array */
- private $callBacks = [];
-
- /** @var MockObject | DiscoveryService */
- private $discoveryService;
-
- /** @var MockObject|LoggerInterface */
- private $logger;
+ private array $callBacks = [];
+ private DiscoveryService&MockObject $discoveryService;
+ private LoggerInterface&MockObject $logger;
protected function setUp(): void {
parent::setUp();
- $this->discoveryService = $this->getMockBuilder(DiscoveryService::class)
- ->disableOriginalConstructor()->getMock();
+ $this->discoveryService = $this->createMock(DiscoveryService::class);
$this->discoveryService->expects($this->any())->method('discover')->willReturn([]);
$this->logger = $this->createMock(LoggerInterface::class);
}
public function testSync(): void {
- /** @var DbHandler | MockObject $dbHandler */
- $dbHandler = $this->getMockBuilder('OCA\Federation\DbHandler')
- ->disableOriginalConstructor()
- ->getMock();
+ /** @var DbHandler&MockObject $dbHandler */
+ $dbHandler = $this->createMock(DbHandler::class);
$dbHandler->method('getAllServer')
->willReturn([
[
- 'url' => 'https://cloud.drop.box',
+ 'url' => 'https://cloud.example.org',
'url_hash' => 'sha1',
- 'shared_secret' => 'iloveowncloud',
+ 'shared_secret' => 'ilovenextcloud',
'sync_token' => '0'
]
]);
- $dbHandler->expects($this->once())->method('setServerStatus')->
- with('https://cloud.drop.box', 1, '1');
- $syncService = $this->getMockBuilder('OCA\DAV\CardDAV\SyncService')
- ->disableOriginalConstructor()
- ->getMock();
+ $dbHandler->expects($this->once())->method('setServerStatus')
+ ->with('https://cloud.example.org', 1, '1');
+ $syncService = $this->createMock(SyncService::class);
$syncService->expects($this->once())->method('syncRemoteAddressBook')
->willReturn('1');
@@ -62,26 +52,22 @@ class SyncFederationAddressbooksTest extends \Test\TestCase {
$s->syncThemAll(function ($url, $ex): void {
$this->callBacks[] = [$url, $ex];
});
- $this->assertEquals('1', count($this->callBacks));
+ $this->assertCount(1, $this->callBacks);
}
public function testException(): void {
- /** @var DbHandler | MockObject $dbHandler */
- $dbHandler = $this->getMockBuilder('OCA\Federation\DbHandler')->
- disableOriginalConstructor()->
- getMock();
- $dbHandler->method('getAllServer')->
- willReturn([
- [
- 'url' => 'https://cloud.drop.box',
- 'url_hash' => 'sha1',
- 'shared_secret' => 'iloveowncloud',
- 'sync_token' => '0'
- ]
- ]);
- $syncService = $this->getMockBuilder('OCA\DAV\CardDAV\SyncService')
- ->disableOriginalConstructor()
- ->getMock();
+ /** @var DbHandler&MockObject $dbHandler */
+ $dbHandler = $this->createMock(DbHandler::class);
+ $dbHandler->method('getAllServer')
+ ->willReturn([
+ [
+ 'url' => 'https://cloud.example.org',
+ 'url_hash' => 'sha1',
+ 'shared_secret' => 'ilovenextcloud',
+ 'sync_token' => '0'
+ ]
+ ]);
+ $syncService = $this->createMock(SyncService::class);
$syncService->expects($this->once())->method('syncRemoteAddressBook')
->willThrowException(new \Exception('something did not work out'));
@@ -90,29 +76,25 @@ class SyncFederationAddressbooksTest extends \Test\TestCase {
$s->syncThemAll(function ($url, $ex): void {
$this->callBacks[] = [$url, $ex];
});
- $this->assertEquals(2, count($this->callBacks));
+ $this->assertCount(2, $this->callBacks);
}
public function testSuccessfulSyncWithoutChangesAfterFailure(): void {
- /** @var DbHandler | MockObject $dbHandler */
- $dbHandler = $this->getMockBuilder('OCA\Federation\DbHandler')
- ->disableOriginalConstructor()
- ->getMock();
+ /** @var DbHandler&MockObject $dbHandler */
+ $dbHandler = $this->createMock(DbHandler::class);
$dbHandler->method('getAllServer')
->willReturn([
[
- 'url' => 'https://cloud.drop.box',
+ 'url' => 'https://cloud.example.org',
'url_hash' => 'sha1',
'shared_secret' => 'ilovenextcloud',
'sync_token' => '0'
]
]);
$dbHandler->method('getServerStatus')->willReturn(TrustedServers::STATUS_FAILURE);
- $dbHandler->expects($this->once())->method('setServerStatus')->
- with('https://cloud.drop.box', 1);
- $syncService = $this->getMockBuilder('OCA\DAV\CardDAV\SyncService')
- ->disableOriginalConstructor()
- ->getMock();
+ $dbHandler->expects($this->once())->method('setServerStatus')
+ ->with('https://cloud.example.org', 1);
+ $syncService = $this->createMock(SyncService::class);
$syncService->expects($this->once())->method('syncRemoteAddressBook')
->willReturn('0');
@@ -121,6 +103,6 @@ class SyncFederationAddressbooksTest extends \Test\TestCase {
$s->syncThemAll(function ($url, $ex): void {
$this->callBacks[] = [$url, $ex];
});
- $this->assertEquals('1', count($this->callBacks));
+ $this->assertCount(1, $this->callBacks);
}
}
diff --git a/apps/federation/tests/TrustedServersTest.php b/apps/federation/tests/TrustedServersTest.php
index c3f0368858b..c8477f637cb 100644
--- a/apps/federation/tests/TrustedServersTest.php
+++ b/apps/federation/tests/TrustedServersTest.php
@@ -1,5 +1,6 @@
<?php
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -7,6 +8,7 @@
*/
namespace OCA\Federation\Tests;
+use OCA\Federation\BackgroundJob\RequestSharedSecret;
use OCA\Federation\DbHandler;
use OCA\Federation\TrustedServers;
use OCP\AppFramework\Utility\ITimeFactory;
@@ -19,57 +21,35 @@ use OCP\Http\Client\IClientService;
use OCP\Http\Client\IResponse;
use OCP\IConfig;
use OCP\Security\ISecureRandom;
+use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use Test\TestCase;
class TrustedServersTest extends TestCase {
- /** @var \PHPUnit\Framework\MockObject\MockObject | TrustedServers */
- private $trustedServers;
-
- /** @var \PHPUnit\Framework\MockObject\MockObject | DbHandler */
- private $dbHandler;
-
- /** @var \PHPUnit\Framework\MockObject\MockObject | IClientService */
- private $httpClientService;
-
- /** @var \PHPUnit\Framework\MockObject\MockObject | IClient */
- private $httpClient;
-
- /** @var \PHPUnit\Framework\MockObject\MockObject | IResponse */
- private $response;
-
- /** @var \PHPUnit\Framework\MockObject\MockObject | LoggerInterface */
- private $logger;
-
- /** @var \PHPUnit\Framework\MockObject\MockObject | IJobList */
- private $jobList;
-
- /** @var \PHPUnit\Framework\MockObject\MockObject | ISecureRandom */
- private $secureRandom;
-
- /** @var \PHPUnit\Framework\MockObject\MockObject | IConfig */
- private $config;
-
- /** @var \PHPUnit\Framework\MockObject\MockObject | IEventDispatcher */
- private $dispatcher;
-
- /** @var \PHPUnit\Framework\MockObject\MockObject|ITimeFactory */
- private $timeFactory;
+ private TrustedServers $trustedServers;
+ private DbHandler&MockObject $dbHandler;
+ private IClientService&MockObject $httpClientService;
+ private IClient&MockObject $httpClient;
+ private IResponse&MockObject $response;
+ private LoggerInterface&MockObject $logger;
+ private IJobList&MockObject $jobList;
+ private ISecureRandom&MockObject $secureRandom;
+ private IConfig&MockObject $config;
+ private IEventDispatcher&MockObject $dispatcher;
+ private ITimeFactory&MockObject $timeFactory;
protected function setUp(): void {
parent::setUp();
- $this->dbHandler = $this->getMockBuilder(DbHandler::class)
- ->disableOriginalConstructor()->getMock();
- $this->dispatcher = $this->getMockBuilder(IEventDispatcher::class)
- ->disableOriginalConstructor()->getMock();
- $this->httpClientService = $this->getMockBuilder(IClientService::class)->getMock();
- $this->httpClient = $this->getMockBuilder(IClient::class)->getMock();
- $this->response = $this->getMockBuilder(IResponse::class)->getMock();
- $this->logger = $this->getMockBuilder(LoggerInterface::class)->getMock();
- $this->jobList = $this->getMockBuilder(IJobList::class)->getMock();
- $this->secureRandom = $this->getMockBuilder(ISecureRandom::class)->getMock();
- $this->config = $this->getMockBuilder(IConfig::class)->getMock();
+ $this->dbHandler = $this->createMock(DbHandler::class);
+ $this->dispatcher = $this->createMock(IEventDispatcher::class);
+ $this->httpClientService = $this->createMock(IClientService::class);
+ $this->httpClient = $this->createMock(IClient::class);
+ $this->response = $this->createMock(IResponse::class);
+ $this->logger = $this->createMock(LoggerInterface::class);
+ $this->jobList = $this->createMock(IJobList::class);
+ $this->secureRandom = $this->createMock(ISecureRandom::class);
+ $this->config = $this->createMock(IConfig::class);
$this->timeFactory = $this->createMock(ITimeFactory::class);
$this->trustedServers = new TrustedServers(
@@ -85,8 +65,8 @@ class TrustedServersTest extends TestCase {
}
public function testAddServer(): void {
- /** @var \PHPUnit\Framework\MockObject\MockObject|TrustedServers $trustedServers */
- $trustedServers = $this->getMockBuilder('OCA\Federation\TrustedServers')
+ /** @var TrustedServers&MockObject $trustedServers */
+ $trustedServers = $this->getMockBuilder(TrustedServers::class)
->setConstructorArgs(
[
$this->dbHandler,
@@ -99,7 +79,7 @@ class TrustedServersTest extends TestCase {
$this->timeFactory
]
)
- ->setMethods(['normalizeUrl', 'updateProtocol'])
+ ->onlyMethods(['updateProtocol'])
->getMock();
$trustedServers->expects($this->once())->method('updateProtocol')
->with('url')->willReturn('https://url');
@@ -112,12 +92,12 @@ class TrustedServersTest extends TestCase {
->willReturn('token');
$this->dbHandler->expects($this->once())->method('addToken')->with('https://url', 'token');
$this->jobList->expects($this->once())->method('add')
- ->with('OCA\Federation\BackgroundJob\RequestSharedSecret',
+ ->with(RequestSharedSecret::class,
['url' => 'https://url', 'token' => 'token', 'created' => 1234567]);
$this->assertSame(
- $trustedServers->addServer('url'),
- 1
+ 1,
+ $trustedServers->addServer('url')
);
}
@@ -190,14 +170,12 @@ class TrustedServersTest extends TestCase {
);
}
- /**
- * @dataProvider dataTestIsNextcloudServer
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestIsNextcloudServer')]
public function testIsNextcloudServer(int $statusCode, bool $isValidNextcloudVersion, bool $expected): void {
$server = 'server1';
- /** @var \PHPUnit\Framework\MockObject\MockObject | TrustedServers $trustedServers */
- $trustedServers = $this->getMockBuilder('OCA\Federation\TrustedServers')
+ /** @var TrustedServers&MockObject $trustedServers */
+ $trustedServers = $this->getMockBuilder(TrustedServers::class)
->setConstructorArgs(
[
$this->dbHandler,
@@ -210,7 +188,7 @@ class TrustedServersTest extends TestCase {
$this->timeFactory
]
)
- ->setMethods(['checkNextcloudVersion'])
+ ->onlyMethods(['checkNextcloudVersion'])
->getMock();
$this->httpClientService->expects($this->once())->method('newClient')
@@ -236,7 +214,7 @@ class TrustedServersTest extends TestCase {
);
}
- public function dataTestIsNextcloudServer(): array {
+ public static function dataTestIsNextcloudServer(): array {
return [
[200, true, true],
[200, false, false],
@@ -244,63 +222,55 @@ class TrustedServersTest extends TestCase {
];
}
- /**
- * @expectedExceptionMessage simulated exception
- */
public function testIsNextcloudServerFail(): void {
$server = 'server1';
- $this->httpClientService->expects($this->once())->method('newClient')
+ $this->httpClientService->expects($this->once())
+ ->method('newClient')
->willReturn($this->httpClient);
- $this->httpClient->expects($this->once())->method('get')->with($server . '/status.php')
- ->willReturnCallback(function (): void {
- throw new \Exception('simulated exception');
- });
+ $this->httpClient->expects($this->once())
+ ->method('get')
+ ->with($server . '/status.php')
+ ->willThrowException(new \Exception('simulated exception'));
$this->assertFalse($this->trustedServers->isNextcloudServer($server));
}
- /**
- * @dataProvider dataTestCheckNextcloudVersion
- */
- public function testCheckNextcloudVersion($status): void {
- $this->assertTrue($this->invokePrivate($this->trustedServers, 'checkNextcloudVersion', [$status]));
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestCheckNextcloudVersion')]
+ public function testCheckNextcloudVersion(string $status): void {
+ $this->assertTrue(self::invokePrivate($this->trustedServers, 'checkNextcloudVersion', [$status]));
}
- public function dataTestCheckNextcloudVersion(): array {
+ public static function dataTestCheckNextcloudVersion(): array {
return [
['{"version":"9.0.0"}'],
['{"version":"9.1.0"}']
];
}
- /**
- * @dataProvider dataTestCheckNextcloudVersionTooLow
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestCheckNextcloudVersionTooLow')]
public function testCheckNextcloudVersionTooLow(string $status): void {
$this->expectException(HintException::class);
$this->expectExceptionMessage('Remote server version is too low. 9.0 is required.');
- $this->invokePrivate($this->trustedServers, 'checkNextcloudVersion', [$status]);
+ self::invokePrivate($this->trustedServers, 'checkNextcloudVersion', [$status]);
}
- public function dataTestCheckNextcloudVersionTooLow(): array {
+ public static function dataTestCheckNextcloudVersionTooLow(): array {
return [
['{"version":"8.2.3"}'],
];
}
- /**
- * @dataProvider dataTestUpdateProtocol
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestUpdateProtocol')]
public function testUpdateProtocol(string $url, string $expected): void {
$this->assertSame($expected,
- $this->invokePrivate($this->trustedServers, 'updateProtocol', [$url])
+ self::invokePrivate($this->trustedServers, 'updateProtocol', [$url])
);
}
- public function dataTestUpdateProtocol(): array {
+ public static function dataTestUpdateProtocol(): array {
return [
['http://owncloud.org', 'http://owncloud.org'],
['https://owncloud.org', 'https://owncloud.org'],