aboutsummaryrefslogtreecommitdiffstats
path: root/apps/encryption/tests/SessionTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/encryption/tests/SessionTest.php')
-rw-r--r--apps/encryption/tests/SessionTest.php57
1 files changed, 29 insertions, 28 deletions
diff --git a/apps/encryption/tests/SessionTest.php b/apps/encryption/tests/SessionTest.php
index 098120e2b03..986502749c8 100644
--- a/apps/encryption/tests/SessionTest.php
+++ b/apps/encryption/tests/SessionTest.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -7,22 +9,20 @@
*/
namespace OCA\Encryption\Tests;
+use OCA\Encryption\Exceptions\PrivateKeyMissingException;
use OCA\Encryption\Session;
use OCP\ISession;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class SessionTest extends TestCase {
private static $tempStorage = [];
- /**
- * @var Session
- */
- private $instance;
- /** @var \OCP\ISession|\PHPUnit\Framework\MockObject\MockObject */
- private $sessionMock;
+ protected Session $instance;
+ protected ISession&MockObject $sessionMock;
- public function testThatGetPrivateKeyThrowsExceptionWhenNotSet() {
- $this->expectException(\OCA\Encryption\Exceptions\PrivateKeyMissingException::class);
+ public function testThatGetPrivateKeyThrowsExceptionWhenNotSet(): void {
+ $this->expectException(PrivateKeyMissingException::class);
$this->expectExceptionMessage('Private Key missing for user: please try to log-out and log-in again');
$this->instance->getPrivateKey();
@@ -31,7 +31,7 @@ class SessionTest extends TestCase {
/**
* @depends testThatGetPrivateKeyThrowsExceptionWhenNotSet
*/
- public function testSetAndGetPrivateKey() {
+ public function testSetAndGetPrivateKey(): void {
$this->instance->setPrivateKey('dummyPrivateKey');
$this->assertEquals('dummyPrivateKey', $this->instance->getPrivateKey());
}
@@ -39,7 +39,7 @@ class SessionTest extends TestCase {
/**
* @depends testSetAndGetPrivateKey
*/
- public function testIsPrivateKeySet() {
+ public function testIsPrivateKeySet(): void {
$this->instance->setPrivateKey('dummyPrivateKey');
$this->assertTrue($this->instance->isPrivateKeySet());
@@ -50,21 +50,21 @@ class SessionTest extends TestCase {
self::$tempStorage['privateKey'] = 'dummyPrivateKey';
}
- public function testDecryptAllModeActivated() {
+ public function testDecryptAllModeActivated(): void {
$this->instance->prepareDecryptAll('user1', 'usersKey');
$this->assertTrue($this->instance->decryptAllModeActivated());
$this->assertSame('user1', $this->instance->getDecryptAllUid());
$this->assertSame('usersKey', $this->instance->getDecryptAllKey());
}
- public function testDecryptAllModeDeactivated() {
+ public function testDecryptAllModeDeactivated(): void {
$this->assertFalse($this->instance->decryptAllModeActivated());
}
/**
* @expectExceptionMessage 'Please activate decrypt all mode first'
*/
- public function testGetDecryptAllUidException() {
+ public function testGetDecryptAllUidException(): void {
$this->expectException(\Exception::class);
$this->instance->getDecryptAllUid();
@@ -73,7 +73,7 @@ class SessionTest extends TestCase {
/**
* @expectExceptionMessage 'No uid found while in decrypt all mode'
*/
- public function testGetDecryptAllUidException2() {
+ public function testGetDecryptAllUidException2(): void {
$this->expectException(\Exception::class);
$this->instance->prepareDecryptAll(null, 'key');
@@ -83,8 +83,8 @@ class SessionTest extends TestCase {
/**
* @expectExceptionMessage 'Please activate decrypt all mode first'
*/
- public function testGetDecryptAllKeyException() {
- $this->expectException(\OCA\Encryption\Exceptions\PrivateKeyMissingException::class);
+ public function testGetDecryptAllKeyException(): void {
+ $this->expectException(PrivateKeyMissingException::class);
$this->instance->getDecryptAllKey();
}
@@ -92,15 +92,15 @@ class SessionTest extends TestCase {
/**
* @expectExceptionMessage 'No key found while in decrypt all mode'
*/
- public function testGetDecryptAllKeyException2() {
- $this->expectException(\OCA\Encryption\Exceptions\PrivateKeyMissingException::class);
+ public function testGetDecryptAllKeyException2(): void {
+ $this->expectException(PrivateKeyMissingException::class);
$this->instance->prepareDecryptAll('user', null);
$this->instance->getDecryptAllKey();
}
- public function testSetAndGetStatusWillSetAndReturn() {
+ public function testSetAndGetStatusWillSetAndReturn(): void {
// Check if get status will return 0 if it has not been set before
$this->assertEquals(0, $this->instance->getStatus());
@@ -115,16 +115,17 @@ class SessionTest extends TestCase {
}
/**
- * @dataProvider dataTestIsReady
*
* @param int $status
* @param bool $expected
*/
- public function testIsReady($status, $expected) {
- /** @var Session | \PHPUnit\Framework\MockObject\MockObject $instance */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestIsReady')]
+ public function testIsReady($status, $expected): void {
+ /** @var Session&MockObject $instance */
$instance = $this->getMockBuilder(Session::class)
->setConstructorArgs([$this->sessionMock])
- ->setMethods(['getStatus'])->getMock();
+ ->onlyMethods(['getStatus'])
+ ->getMock();
$instance->expects($this->once())->method('getStatus')
->willReturn($status);
@@ -132,7 +133,7 @@ class SessionTest extends TestCase {
$this->assertSame($expected, $instance->isReady());
}
- public function dataTestIsReady() {
+ public static function dataTestIsReady(): array {
return [
[Session::INIT_SUCCESSFUL, true],
[Session::INIT_EXECUTED, false],
@@ -167,7 +168,7 @@ class SessionTest extends TestCase {
}
- public function testClearWillRemoveValues() {
+ public function testClearWillRemoveValues(): void {
$this->instance->setPrivateKey('privateKey');
$this->instance->setStatus('initStatus');
$this->instance->prepareDecryptAll('user', 'key');
@@ -183,15 +184,15 @@ class SessionTest extends TestCase {
$this->sessionMock->expects($this->any())
->method('set')
- ->willReturnCallback([$this, "setValueTester"]);
+ ->willReturnCallback([$this, 'setValueTester']);
$this->sessionMock->expects($this->any())
->method('get')
- ->willReturnCallback([$this, "getValueTester"]);
+ ->willReturnCallback([$this, 'getValueTester']);
$this->sessionMock->expects($this->any())
->method('remove')
- ->willReturnCallback([$this, "removeValueTester"]);
+ ->willReturnCallback([$this, 'removeValueTester']);
$this->instance = new Session($this->sessionMock);