diff options
Diffstat (limited to 'tests/lib/Encryption')
-rw-r--r-- | tests/lib/Encryption/DecryptAllTest.php | 21 | ||||
-rw-r--r-- | tests/lib/Encryption/EncryptionWrapperTest.php | 7 | ||||
-rw-r--r-- | tests/lib/Encryption/Keys/StorageTest.php | 16 | ||||
-rw-r--r-- | tests/lib/Encryption/ManagerTest.php | 9 | ||||
-rw-r--r-- | tests/lib/Encryption/UpdateTest.php | 4 | ||||
-rw-r--r-- | tests/lib/Encryption/UtilTest.php | 28 |
6 files changed, 36 insertions, 49 deletions
diff --git a/tests/lib/Encryption/DecryptAllTest.php b/tests/lib/Encryption/DecryptAllTest.php index 7385ff03785..979e12e03b3 100644 --- a/tests/lib/Encryption/DecryptAllTest.php +++ b/tests/lib/Encryption/DecryptAllTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -44,7 +45,7 @@ class DecryptAllTest extends TestCase { /** @var \PHPUnit\Framework\MockObject\MockObject | \Symfony\Component\Console\Output\OutputInterface */ protected $outputInterface; - /** @var \PHPUnit\Framework\MockObject\MockObject | \OCP\UserInterface */ + /** @var \PHPUnit\Framework\MockObject\MockObject|UserInterface */ protected $userInterface; /** @var DecryptAll */ @@ -93,11 +94,11 @@ class DecryptAllTest extends TestCase { } /** - * @dataProvider dataDecryptAll * @param bool $prepareResult * @param string $user * @param bool $userExistsChecked */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataDecryptAll')] public function testDecryptAll($prepareResult, $user, $userExistsChecked): void { if ($userExistsChecked) { $this->userManager->expects($this->once())->method('userExists')->willReturn(true); @@ -153,9 +154,9 @@ class DecryptAllTest extends TestCase { } /** - * @dataProvider dataTrueFalse * @param bool $success */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataTrueFalse')] public function testPrepareEncryptionModules($success): void { $user = 'user1'; @@ -185,9 +186,7 @@ class DecryptAllTest extends TestCase { ); } - /** - * @dataProvider dataTestDecryptAllUsersFiles - */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestDecryptAllUsersFiles')] public function testDecryptAllUsersFiles($user): void { /** @var DecryptAll | \PHPUnit\Framework\MockObject\MockObject | $instance */ $instance = $this->getMockBuilder('OC\Encryption\DecryptAll') @@ -217,7 +216,7 @@ class DecryptAllTest extends TestCase { ]; $instance->expects($this->exactly(2)) ->method('decryptUsersFiles') - ->willReturnCallback(function ($user) use (&$calls) { + ->willReturnCallback(function ($user) use (&$calls): void { $expected = array_shift($calls); $this->assertEquals($expected, $user); }); @@ -297,7 +296,7 @@ class DecryptAllTest extends TestCase { ]; $instance->expects($this->exactly(2)) ->method('decryptFile') - ->willReturnCallback(function ($path) use (&$calls) { + ->willReturnCallback(function ($path) use (&$calls): void { $expected = array_shift($calls); $this->assertEquals($expected, $path); }); @@ -317,9 +316,7 @@ class DecryptAllTest extends TestCase { $this->invokePrivate($instance, 'decryptUsersFiles', ['user1', $progressBar, '']); } - /** - * @dataProvider dataTrueFalse - */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataTrueFalse')] public function testDecryptFile($isEncrypted): void { $path = 'test.txt'; @@ -387,7 +384,7 @@ class DecryptAllTest extends TestCase { $this->view->expects($this->once()) ->method('copy') ->with($path, $path . '.decrypted.42') - ->willReturnCallback(function () { + ->willReturnCallback(function (): void { throw new DecryptionFailedException(); }); diff --git a/tests/lib/Encryption/EncryptionWrapperTest.php b/tests/lib/Encryption/EncryptionWrapperTest.php index 342a7214e44..58bf5aff005 100644 --- a/tests/lib/Encryption/EncryptionWrapperTest.php +++ b/tests/lib/Encryption/EncryptionWrapperTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -28,7 +29,7 @@ class EncryptionWrapperTest extends TestCase { /** @var \PHPUnit\Framework\MockObject\MockObject | \OC\Encryption\Manager */ private $manager; - /** @var \PHPUnit\Framework\MockObject\MockObject | \OC\Memcache\ArrayCache */ + /** @var \PHPUnit\Framework\MockObject\MockObject|ArrayCache */ private $arrayCache; protected function setUp(): void { @@ -42,9 +43,7 @@ class EncryptionWrapperTest extends TestCase { } - /** - * @dataProvider provideWrapStorage - */ + #[\PHPUnit\Framework\Attributes\DataProvider('provideWrapStorage')] public function testWrapStorage($expectedWrapped, $wrappedStorages): void { $storage = $this->getMockBuilder(IStorage::class) ->disableOriginalConstructor() diff --git a/tests/lib/Encryption/Keys/StorageTest.php b/tests/lib/Encryption/Keys/StorageTest.php index bc79c5771ca..333d8d8ce21 100644 --- a/tests/lib/Encryption/Keys/StorageTest.php +++ b/tests/lib/Encryption/Keys/StorageTest.php @@ -124,13 +124,13 @@ class StorageTest extends TestCase { } /** - * @dataProvider dataTestGetFileKey * * @param string $path * @param string $strippedPartialName * @param bool $originalKeyExists * @param string $expectedKeyContent */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestGetFileKey')] public function testGetFileKey($path, $strippedPartialName, $originalKeyExists, $expectedKeyContent): void { $this->config->method('getSystemValueString') ->with('version') @@ -408,9 +408,7 @@ class StorageTest extends TestCase { ); } - /** - * @dataProvider dataProviderCopyRename - */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataProviderCopyRename')] public function testRenameKeys($source, $target, $systemWideMountSource, $systemWideMountTarget, $expectedSource, $expectedTarget): void { $this->view->expects($this->any()) ->method('file_exists') @@ -439,9 +437,7 @@ class StorageTest extends TestCase { $this->storage->renameKeys($source, $target); } - /** - * @dataProvider dataProviderCopyRename - */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataProviderCopyRename')] public function testCopyKeys($source, $target, $systemWideMountSource, $systemWideMountTarget, $expectedSource, $expectedTarget): void { $this->view->expects($this->any()) ->method('file_exists') @@ -510,13 +506,13 @@ class StorageTest extends TestCase { } /** - * @dataProvider dataTestGetPathToKeys * * @param string $path * @param boolean $systemWideMountPoint * @param string $storageRoot * @param string $expected */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestGetPathToKeys')] public function testGetPathToKeys($path, $systemWideMountPoint, $storageRoot, $expected): void { $this->invokePrivate($this->storage, 'root_dir', [$storageRoot]); @@ -569,9 +565,9 @@ class StorageTest extends TestCase { /** - * @dataProvider dataTestBackupUserKeys * @param bool $createBackupDir */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestBackupUserKeys')] public function testBackupUserKeys($createBackupDir): void { $storage = $this->getMockBuilder('OC\Encryption\Keys\Storage') ->setConstructorArgs([$this->view, $this->util, $this->crypto, $this->config]) @@ -589,7 +585,7 @@ class StorageTest extends TestCase { 'user1/files_encryption/backup/test.encryptionModule.1234567', ]; $this->view->expects($this->exactly(2))->method('mkdir') - ->willReturnCallback(function ($path) use (&$calls) { + ->willReturnCallback(function ($path) use (&$calls): void { $expected = array_shift($calls); $this->assertEquals($expected, $path); }); diff --git a/tests/lib/Encryption/ManagerTest.php b/tests/lib/Encryption/ManagerTest.php index 8dd602349b6..e9b6ddae8a0 100644 --- a/tests/lib/Encryption/ManagerTest.php +++ b/tests/lib/Encryption/ManagerTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -6,6 +7,8 @@ */ namespace Test\Encryption; +use OC\Encryption\Exceptions\ModuleAlreadyExistsException; +use OC\Encryption\Exceptions\ModuleDoesNotExistsException; use OC\Encryption\Manager; use OC\Encryption\Util; use OC\Files\View; @@ -88,7 +91,7 @@ class ManagerTest extends TestCase { * @depends testModuleRegistration */ public function testModuleReRegistration($manager): void { - $this->expectException(\OC\Encryption\Exceptions\ModuleAlreadyExistsException::class); + $this->expectException(ModuleAlreadyExistsException::class); $this->expectExceptionMessage('Id "ID0" already used by encryption module "TestDummyModule0"'); $this->addNewEncryptionModule($manager, 0); @@ -105,7 +108,7 @@ class ManagerTest extends TestCase { public function testGetEncryptionModuleUnknown(): void { - $this->expectException(\OC\Encryption\Exceptions\ModuleDoesNotExistsException::class); + $this->expectException(ModuleDoesNotExistsException::class); $this->expectExceptionMessage('Module with ID: unknown does not exist.'); $this->config->expects($this->any())->method('getAppValue')->willReturn(true); @@ -263,7 +266,7 @@ class ManagerTest extends TestCase { $encryptionModule->expects($this->any()) ->method('getDisplayName') ->willReturn('TestDummyModule' . $id); - /** @var \OCP\Encryption\IEncryptionModule $encryptionModule */ + /** @var IEncryptionModule $encryptionModule */ $manager->registerEncryptionModule('ID' . $id, 'TestDummyModule' . $id, function () use ($encryptionModule) { return $encryptionModule; }); diff --git a/tests/lib/Encryption/UpdateTest.php b/tests/lib/Encryption/UpdateTest.php index 4f3de2b495d..04ca224c0a1 100644 --- a/tests/lib/Encryption/UpdateTest.php +++ b/tests/lib/Encryption/UpdateTest.php @@ -77,13 +77,13 @@ class UpdateTest extends TestCase { } /** - * @dataProvider dataTestUpdate * * @param string $path * @param boolean $isDir * @param array $allFiles * @param integer $numberOfFiles */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestUpdate')] public function testUpdate($path, $isDir, $allFiles, $numberOfFiles): void { $updateMock = $this->getUpdateMock(['getOwnerPath']); $updateMock->expects($this->once())->method('getOwnerPath') @@ -121,11 +121,11 @@ class UpdateTest extends TestCase { } /** - * @dataProvider dataTestPostRename * * @param string $source * @param string $target */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestPostRename')] public function testPostRename($source, $target): void { $updateMock = $this->getUpdateMock(['update','getOwnerPath']); diff --git a/tests/lib/Encryption/UtilTest.php b/tests/lib/Encryption/UtilTest.php index 68989c55fb0..d1fefee872a 100644 --- a/tests/lib/Encryption/UtilTest.php +++ b/tests/lib/Encryption/UtilTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -6,6 +7,7 @@ */ namespace Test\Encryption; +use OC\Encryption\Exceptions\EncryptionHeaderKeyExistsException; use OC\Encryption\Util; use OC\Files\View; use OCP\Encryption\IEncryptionModule; @@ -53,9 +55,7 @@ class UtilTest extends TestCase { ); } - /** - * @dataProvider providesHeadersForEncryptionModule - */ + #[\PHPUnit\Framework\Attributes\DataProvider('providesHeadersForEncryptionModule')] public function testGetEncryptionModuleId($expected, $header): void { $id = $this->util->getEncryptionModuleId($header); $this->assertEquals($expected, $id); @@ -69,9 +69,7 @@ class UtilTest extends TestCase { ]; } - /** - * @dataProvider providesHeaders - */ + #[\PHPUnit\Framework\Attributes\DataProvider('providesHeaders')] public function testCreateHeader($expected, $header, $moduleId): void { $em = $this->createMock(IEncryptionModule::class); $em->expects($this->any())->method('getId')->willReturn($moduleId); @@ -91,7 +89,7 @@ class UtilTest extends TestCase { public function testCreateHeaderFailed(): void { - $this->expectException(\OC\Encryption\Exceptions\EncryptionHeaderKeyExistsException::class); + $this->expectException(EncryptionHeaderKeyExistsException::class); $header = ['header1' => 1, 'header2' => 2, 'oc_encryption_module' => 'foo']; @@ -102,9 +100,7 @@ class UtilTest extends TestCase { $this->util->createHeader($header, $em); } - /** - * @dataProvider providePathsForTestIsExcluded - */ + #[\PHPUnit\Framework\Attributes\DataProvider('providePathsForTestIsExcluded')] public function testIsExcluded($path, $keyStorageRoot, $expected): void { $this->config->expects($this->once()) ->method('getAppValue') @@ -143,9 +139,7 @@ class UtilTest extends TestCase { return false; } - /** - * @dataProvider dataTestIsFile - */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestIsFile')] public function testIsFile($path, $expected): void { $this->assertSame($expected, $this->util->isFile($path) @@ -165,11 +159,11 @@ class UtilTest extends TestCase { } /** - * @dataProvider dataTestStripPartialFileExtension * * @param string $path * @param string $expected */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestStripPartialFileExtension')] public function testStripPartialFileExtension($path, $expected): void { $this->assertSame($expected, $this->util->stripPartialFileExtension($path)); @@ -184,9 +178,7 @@ class UtilTest extends TestCase { ]; } - /** - * @dataProvider dataTestParseRawHeader - */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestParseRawHeader')] public function testParseRawHeader($rawHeader, $expected): void { $result = $this->util->parseRawHeader($rawHeader); $this->assertSameSize($expected, $result); @@ -212,12 +204,12 @@ class UtilTest extends TestCase { } /** - * @dataProvider dataTestGetFileKeyDir * * @param bool $isSystemWideMountPoint * @param string $storageRoot * @param string $expected */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestGetFileKeyDir')] public function testGetFileKeyDir($isSystemWideMountPoint, $storageRoot, $expected): void { $path = '/user1/files/foo/bar.txt'; $owner = 'user1'; |