aboutsummaryrefslogtreecommitdiffstats
path: root/apps/settings/tests/Controller/AuthSettingsControllerTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/settings/tests/Controller/AuthSettingsControllerTest.php')
-rw-r--r--apps/settings/tests/Controller/AuthSettingsControllerTest.php70
1 files changed, 26 insertions, 44 deletions
diff --git a/apps/settings/tests/Controller/AuthSettingsControllerTest.php b/apps/settings/tests/Controller/AuthSettingsControllerTest.php
index 4cc8be641c2..d195dbf83d3 100644
--- a/apps/settings/tests/Controller/AuthSettingsControllerTest.php
+++ b/apps/settings/tests/Controller/AuthSettingsControllerTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -28,24 +29,15 @@ use Psr\Log\LoggerInterface;
use Test\TestCase;
class AuthSettingsControllerTest extends TestCase {
-
- /** @var AuthSettingsController */
- private $controller;
- /** @var IRequest|MockObject */
- private $request;
- /** @var IProvider|MockObject */
- private $tokenProvider;
- /** @var ISession|MockObject */
- private $session;
- /**@var IUserSession|MockObject */
- private $userSession;
- /** @var ISecureRandom|MockObject */
- private $secureRandom;
- /** @var IManager|MockObject */
- private $activityManager;
- /** @var RemoteWipe|MockObject */
- private $remoteWipe;
- private $uid = 'jane';
+ private IRequest&MockObject $request;
+ private IProvider&MockObject $tokenProvider;
+ private ISession&MockObject $session;
+ private IUserSession&MockObject $userSession;
+ private ISecureRandom&MockObject $secureRandom;
+ private IManager&MockObject $activityManager;
+ private RemoteWipe&MockObject $remoteWipe;
+ private string $uid = 'jane';
+ private AuthSettingsController $controller;
protected function setUp(): void {
parent::setUp();
@@ -57,7 +49,7 @@ class AuthSettingsControllerTest extends TestCase {
$this->secureRandom = $this->createMock(ISecureRandom::class);
$this->activityManager = $this->createMock(IManager::class);
$this->remoteWipe = $this->createMock(RemoteWipe::class);
- /** @var LoggerInterface|MockObject $logger */
+ /** @var LoggerInterface&MockObject $logger */
$logger = $this->createMock(LoggerInterface::class);
$this->controller = new AuthSettingsController(
@@ -74,7 +66,7 @@ class AuthSettingsControllerTest extends TestCase {
);
}
- public function testCreate() {
+ public function testCreate(): void {
$name = 'Nexus 4';
$sessionToken = $this->createMock(IToken::class);
$deviceToken = $this->createMock(IToken::class);
@@ -123,12 +115,12 @@ class AuthSettingsControllerTest extends TestCase {
$this->assertEquals($expected, $response->getData());
}
- public function testCreateSessionNotAvailable() {
+ public function testCreateSessionNotAvailable(): void {
$name = 'personal phone';
$this->session->expects($this->once())
->method('getId')
- ->will($this->throwException(new SessionNotAvailableException()));
+ ->willThrowException(new SessionNotAvailableException());
$expected = new JSONResponse();
$expected->setStatus(Http::STATUS_SERVICE_UNAVAILABLE);
@@ -136,7 +128,7 @@ class AuthSettingsControllerTest extends TestCase {
$this->assertEquals($expected, $this->controller->create($name));
}
- public function testCreateInvalidToken() {
+ public function testCreateInvalidToken(): void {
$name = 'Company IPhone';
$this->session->expects($this->once())
@@ -145,7 +137,7 @@ class AuthSettingsControllerTest extends TestCase {
$this->tokenProvider->expects($this->once())
->method('getToken')
->with('sessionid')
- ->will($this->throwException(new InvalidTokenException()));
+ ->willThrowException(new InvalidTokenException());
$expected = new JSONResponse();
$expected->setStatus(Http::STATUS_SERVICE_UNAVAILABLE);
@@ -153,7 +145,7 @@ class AuthSettingsControllerTest extends TestCase {
$this->assertEquals($expected, $this->controller->create($name));
}
- public function testDestroy() {
+ public function testDestroy(): void {
$tokenId = 124;
$token = $this->createMock(PublicKeyToken::class);
@@ -175,7 +167,7 @@ class AuthSettingsControllerTest extends TestCase {
$this->assertEquals([], $this->controller->destroy($tokenId));
}
- public function testDestroyExpired() {
+ public function testDestroyExpired(): void {
$tokenId = 124;
$token = $this->createMock(PublicKeyToken::class);
@@ -199,7 +191,7 @@ class AuthSettingsControllerTest extends TestCase {
$this->assertSame([], $this->controller->destroy($tokenId));
}
- public function testDestroyWrongUser() {
+ public function testDestroyWrongUser(): void {
$tokenId = 124;
$token = $this->createMock(PublicKeyToken::class);
@@ -214,19 +206,14 @@ class AuthSettingsControllerTest extends TestCase {
$this->assertSame(\OCP\AppFramework\Http::STATUS_NOT_FOUND, $response->getStatus());
}
- public function dataRenameToken(): array {
+ public static function dataRenameToken(): array {
return [
'App password => Other token name' => ['App password', 'Other token name'],
'Other token name => App password' => ['Other token name', 'App password'],
];
}
- /**
- * @dataProvider dataRenameToken
- *
- * @param string $name
- * @param string $newName
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataRenameToken')]
public function testUpdateRename(string $name, string $newName): void {
$tokenId = 42;
$token = $this->createMock(PublicKeyToken::class);
@@ -257,19 +244,14 @@ class AuthSettingsControllerTest extends TestCase {
$this->assertSame([], $this->controller->update($tokenId, [IToken::SCOPE_FILESYSTEM => true], $newName));
}
- public function dataUpdateFilesystemScope(): array {
+ public static function dataUpdateFilesystemScope(): array {
return [
'Grant filesystem access' => [false, true],
'Revoke filesystem access' => [true, false],
];
}
- /**
- * @dataProvider dataUpdateFilesystemScope
- *
- * @param bool $filesystem
- * @param bool $newFilesystem
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataUpdateFilesystemScope')]
public function testUpdateFilesystemScope(bool $filesystem, bool $newFilesystem): void {
$tokenId = 42;
$token = $this->createMock(PublicKeyToken::class);
@@ -331,7 +313,7 @@ class AuthSettingsControllerTest extends TestCase {
$this->assertSame([], $this->controller->update($tokenId, [IToken::SCOPE_FILESYSTEM => true], 'App password'));
}
- public function testUpdateExpired() {
+ public function testUpdateExpired(): void {
$tokenId = 42;
$token = $this->createMock(PublicKeyToken::class);
@@ -351,7 +333,7 @@ class AuthSettingsControllerTest extends TestCase {
$this->assertSame([], $this->controller->update($tokenId, [IToken::SCOPE_FILESYSTEM => true], 'App password'));
}
- public function testUpdateTokenWrongUser() {
+ public function testUpdateTokenWrongUser(): void {
$tokenId = 42;
$token = $this->createMock(PublicKeyToken::class);
@@ -371,7 +353,7 @@ class AuthSettingsControllerTest extends TestCase {
$this->assertSame(\OCP\AppFramework\Http::STATUS_NOT_FOUND, $response->getStatus());
}
- public function testUpdateTokenNonExisting() {
+ public function testUpdateTokenNonExisting(): void {
$this->tokenProvider->expects($this->once())
->method('getTokenById')
->with($this->equalTo(42))