aboutsummaryrefslogtreecommitdiffstats
path: root/apps/federation/tests/Controller/SettingsControllerTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/federation/tests/Controller/SettingsControllerTest.php')
-rw-r--r--apps/federation/tests/Controller/SettingsControllerTest.php65
1 files changed, 34 insertions, 31 deletions
diff --git a/apps/federation/tests/Controller/SettingsControllerTest.php b/apps/federation/tests/Controller/SettingsControllerTest.php
index 0eb15e40d8f..b0a7a5e30c9 100644
--- a/apps/federation/tests/Controller/SettingsControllerTest.php
+++ b/apps/federation/tests/Controller/SettingsControllerTest.php
@@ -1,5 +1,6 @@
<?php
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -10,35 +11,36 @@ namespace OCA\Federation\Tests\Controller;
use OCA\Federation\Controller\SettingsController;
use OCA\Federation\TrustedServers;
use OCP\AppFramework\Http\DataResponse;
+use OCP\AppFramework\OCS\OCSException;
+use OCP\AppFramework\OCS\OCSNotFoundException;
use OCP\IL10N;
use OCP\IRequest;
+use PHPUnit\Framework\MockObject\MockObject;
+use Psr\Log\LoggerInterface;
use Test\TestCase;
class SettingsControllerTest extends TestCase {
private SettingsController $controller;
- /** @var \PHPUnit\Framework\MockObject\MockObject | \OCP\IRequest */
- private $request;
-
- /** @var \PHPUnit\Framework\MockObject\MockObject | \OCP\IL10N */
- private $l10n;
-
- /** @var \PHPUnit\Framework\MockObject\MockObject | \OCA\Federation\TrustedServers */
- private $trustedServers;
+ 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->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',
$this->request,
$this->l10n,
- $this->trustedServers
+ $this->trustedServers,
+ $this->logger,
);
}
@@ -55,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());
@@ -63,12 +65,8 @@ class SettingsControllerTest extends TestCase {
$this->assertArrayHasKey('id', $data);
}
- /**
- * @dataProvider checkServerFails
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('checkServerFails')]
public function testAddServerFail(bool $isTrustedServer, bool $isNextcloud): void {
- $this->expectException(\OCP\HintException::class);
-
$this->trustedServers
->expects($this->any())
->method('isTrustedServer')
@@ -80,6 +78,12 @@ class SettingsControllerTest extends TestCase {
->with('url')
->willReturn($isNextcloud);
+ if ($isTrustedServer) {
+ $this->expectException(OCSException::class);
+ } else {
+ $this->expectException(OCSNotFoundException::class);
+ }
+
$this->controller->addServer('url');
}
@@ -104,17 +108,13 @@ class SettingsControllerTest extends TestCase {
->with('url')
->willReturn(true);
- $this->assertTrue(
- $this->invokePrivate($this->controller, 'checkServer', ['url'])
+ $this->assertNull(
+ self::invokePrivate($this->controller, 'checkServer', ['url'])
);
}
- /**
- * @dataProvider checkServerFails
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('checkServerFails')]
public function testCheckServerFail(bool $isTrustedServer, bool $isNextcloud): void {
- $this->expectException(\OCP\HintException::class);
-
$this->trustedServers
->expects($this->any())
->method('isTrustedServer')
@@ -126,15 +126,18 @@ class SettingsControllerTest extends TestCase {
->with('url')
->willReturn($isNextcloud);
+ if ($isTrustedServer) {
+ $this->expectException(OCSException::class);
+ } else {
+ $this->expectException(OCSNotFoundException::class);
+ }
+
$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]