diff options
author | Côme Chilliet <come.chilliet@nextcloud.com> | 2025-08-04 11:53:19 +0200 |
---|---|---|
committer | backportbot[bot] <backportbot[bot]@users.noreply.github.com> | 2025-08-05 15:13:46 +0000 |
commit | a9a8c32ff853037971bbfed0e73a1fa94580d05c (patch) | |
tree | 40c424f7bf15cfd97b39657bb7106da9cb33351f | |
parent | b442810717e01048793a0907409982a8f81ad04f (diff) | |
download | nextcloud-server-backport/54233/stable30.tar.gz nextcloud-server-backport/54233/stable30.zip |
chore(encryption): Adapt tests to code changesbackport/54233/stable30
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
[skip ci]
-rw-r--r-- | apps/encryption/lib/Crypto/EncryptAll.php | 2 | ||||
-rw-r--r-- | apps/encryption/tests/Crypto/EncryptAllTest.php | 14 | ||||
-rw-r--r-- | tests/Core/Command/Encryption/EncryptAllTest.php | 25 |
3 files changed, 19 insertions, 22 deletions
diff --git a/apps/encryption/lib/Crypto/EncryptAll.php b/apps/encryption/lib/Crypto/EncryptAll.php index c88f6c2b6ed..61c0a2af393 100644 --- a/apps/encryption/lib/Crypto/EncryptAll.php +++ b/apps/encryption/lib/Crypto/EncryptAll.php @@ -247,7 +247,7 @@ class EncryptAll { while ($root = array_pop($directories)) { $content = $this->rootView->getDirectoryContent($root); foreach ($content as $file) { - $path = $root . '/' . $file['name']; + $path = $root . '/' . $file->getName(); if ($file->isShared()) { $progress->setMessage("Skip shared file/folder $path"); $progress->advance(); diff --git a/apps/encryption/tests/Crypto/EncryptAllTest.php b/apps/encryption/tests/Crypto/EncryptAllTest.php index 5ec0c1baf86..b621dd66815 100644 --- a/apps/encryption/tests/Crypto/EncryptAllTest.php +++ b/apps/encryption/tests/Crypto/EncryptAllTest.php @@ -109,7 +109,7 @@ class EncryptAllTest extends TestCase { /** * We need format method to return a string - * @var OutputFormatterInterface|\PHPUnit\Framework\MockObject\MockObject + * @var OutputFormatterInterface&MockObject */ $outputFormatter = $this->createMock(OutputFormatterInterface::class); $outputFormatter->method('isDecorated')->willReturn(false); @@ -141,6 +141,13 @@ class EncryptAllTest extends TestCase { ); } + protected function createFileInfoMock($type, string $name): FileInfo&MockObject { + $fileInfo = $this->createMock(FileInfo::class); + $fileInfo->method('getType')->willReturn($type); + $fileInfo->method('getName')->willReturn($name); + return $fileInfo; + } + public function testEncryptAll(): void { /** @var EncryptAll&MockObject $encryptAll */ $encryptAll = $this->getMockBuilder(EncryptAll::class) @@ -372,8 +379,7 @@ class EncryptAllTest extends TestCase { $fileInfo = $this->createMock(FileInfo::class); $fileInfo->expects($this->any())->method('isEncrypted') ->willReturn($isEncrypted); - $this->view->expects($this->any())->method('getFileInfo') - ->willReturn($fileInfo); + $this->view->expects($this->never())->method('getFileInfo'); if ($isEncrypted) { @@ -385,7 +391,7 @@ class EncryptAllTest extends TestCase { } $this->assertTrue( - $this->invokePrivate($this->encryptAll, 'encryptFile', ['foo.txt']) + $this->invokePrivate($this->encryptAll, 'encryptFile', [$fileInfo, 'foo.txt']) ); } diff --git a/tests/Core/Command/Encryption/EncryptAllTest.php b/tests/Core/Command/Encryption/EncryptAllTest.php index 4c8af1bd98b..58d736019ed 100644 --- a/tests/Core/Command/Encryption/EncryptAllTest.php +++ b/tests/Core/Command/Encryption/EncryptAllTest.php @@ -13,6 +13,7 @@ use OCP\App\IAppManager; use OCP\Encryption\IEncryptionModule; use OCP\Encryption\IManager; use OCP\IConfig; +use PHPUnit\Framework\MockObject\MockObject; use Symfony\Component\Console\Helper\QuestionHelper; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -46,26 +47,16 @@ class EncryptAllTest extends TestCase { protected function setUp(): void { parent::setUp(); - $this->config = $this->getMockBuilder(IConfig::class) - ->disableOriginalConstructor() - ->getMock(); - $this->encryptionManager = $this->getMockBuilder(IManager::class) - ->disableOriginalConstructor() - ->getMock(); - $this->appManager = $this->getMockBuilder(IAppManager::class) - ->disableOriginalConstructor() - ->getMock(); - $this->encryptionModule = $this->getMockBuilder(IEncryptionModule::class) - ->disableOriginalConstructor() - ->getMock(); - $this->questionHelper = $this->getMockBuilder(QuestionHelper::class) - ->disableOriginalConstructor() - ->getMock(); - $this->consoleInput = $this->getMockBuilder(InputInterface::class)->getMock(); + $this->config = $this->createMock(IConfig::class); + $this->encryptionManager = $this->createMock(IManager::class); + $this->appManager = $this->createMock(IAppManager::class); + $this->encryptionModule = $this->createMock(IEncryptionModule::class); + $this->questionHelper = $this->createMock(QuestionHelper::class); + $this->consoleInput = $this->createMock(InputInterface::class); $this->consoleInput->expects($this->any()) ->method('isInteractive') ->willReturn(true); - $this->consoleOutput = $this->getMockBuilder(OutputInterface::class)->getMock(); + $this->consoleOutput = $this->createMock(OutputInterface::class); } public function testEncryptAll() { |