Skip to content

Commit 2fe7ea2

Browse files
come-ncbackportbot[bot]
authored andcommitted
chore(encryption): Adapt tests to code changes
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com> [skip ci]
1 parent c744543 commit 2fe7ea2

File tree

3 files changed

+19
-22
lines changed

3 files changed

+19
-22
lines changed

apps/encryption/lib/Crypto/EncryptAll.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ protected function encryptUsersFiles($uid, ProgressBar $progress, $userCount) {
203203
while ($root = array_pop($directories)) {
204204
$content = $this->rootView->getDirectoryContent($root);
205205
foreach ($content as $file) {
206-
$path = $root . '/' . $file['name'];
206+
$path = $root . '/' . $file->getName();
207207
if ($file->isShared()) {
208208
$progress->setMessage("Skip shared file/folder $path");
209209
$progress->advance();

apps/encryption/tests/Crypto/EncryptAllTest.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ protected function setUp(): void {
8080

8181
/**
8282
* We need format method to return a string
83-
* @var OutputFormatterInterface|\PHPUnit\Framework\MockObject\MockObject
83+
* @var OutputFormatterInterface&MockObject
8484
*/
8585
$outputFormatter = $this->createMock(OutputFormatterInterface::class);
8686
$outputFormatter->method('isDecorated')->willReturn(false);
@@ -112,6 +112,13 @@ protected function setUp(): void {
112112
);
113113
}
114114

115+
protected function createFileInfoMock($type, string $name): FileInfo&MockObject {
116+
$fileInfo = $this->createMock(FileInfo::class);
117+
$fileInfo->method('getType')->willReturn($type);
118+
$fileInfo->method('getName')->willReturn($name);
119+
return $fileInfo;
120+
}
121+
115122
public function testEncryptAll(): void {
116123
/** @var EncryptAll&MockObject $encryptAll */
117124
$encryptAll = $this->getMockBuilder(EncryptAll::class)
@@ -343,8 +350,7 @@ public function testEncryptFile($isEncrypted): void {
343350
$fileInfo = $this->createMock(FileInfo::class);
344351
$fileInfo->expects($this->any())->method('isEncrypted')
345352
->willReturn($isEncrypted);
346-
$this->view->expects($this->any())->method('getFileInfo')
347-
->willReturn($fileInfo);
353+
$this->view->expects($this->never())->method('getFileInfo');
348354

349355

350356
if ($isEncrypted) {
@@ -356,7 +362,7 @@ public function testEncryptFile($isEncrypted): void {
356362
}
357363

358364
$this->assertTrue(
359-
$this->invokePrivate($this->encryptAll, 'encryptFile', ['foo.txt'])
365+
$this->invokePrivate($this->encryptAll, 'encryptFile', [$fileInfo, 'foo.txt'])
360366
);
361367
}
362368

tests/Core/Command/Encryption/EncryptAllTest.php

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use OCP\Encryption\IEncryptionModule;
1313
use OCP\Encryption\IManager;
1414
use OCP\IConfig;
15+
use PHPUnit\Framework\MockObject\MockObject;
1516
use Symfony\Component\Console\Helper\QuestionHelper;
1617
use Symfony\Component\Console\Input\InputInterface;
1718
use Symfony\Component\Console\Output\OutputInterface;
@@ -45,26 +46,16 @@ class EncryptAllTest extends TestCase {
4546
protected function setUp(): void {
4647
parent::setUp();
4748

48-
$this->config = $this->getMockBuilder(IConfig::class)
49-
->disableOriginalConstructor()
50-
->getMock();
51-
$this->encryptionManager = $this->getMockBuilder(IManager::class)
52-
->disableOriginalConstructor()
53-
->getMock();
54-
$this->appManager = $this->getMockBuilder(IAppManager::class)
55-
->disableOriginalConstructor()
56-
->getMock();
57-
$this->encryptionModule = $this->getMockBuilder(IEncryptionModule::class)
58-
->disableOriginalConstructor()
59-
->getMock();
60-
$this->questionHelper = $this->getMockBuilder(QuestionHelper::class)
61-
->disableOriginalConstructor()
62-
->getMock();
63-
$this->consoleInput = $this->getMockBuilder(InputInterface::class)->getMock();
49+
$this->config = $this->createMock(IConfig::class);
50+
$this->encryptionManager = $this->createMock(IManager::class);
51+
$this->appManager = $this->createMock(IAppManager::class);
52+
$this->encryptionModule = $this->createMock(IEncryptionModule::class);
53+
$this->questionHelper = $this->createMock(QuestionHelper::class);
54+
$this->consoleInput = $this->createMock(InputInterface::class);
6455
$this->consoleInput->expects($this->any())
6556
->method('isInteractive')
6657
->willReturn(true);
67-
$this->consoleOutput = $this->getMockBuilder(OutputInterface::class)->getMock();
58+
$this->consoleOutput = $this->createMock(OutputInterface::class);
6859
}
6960

7061
public function testEncryptAll(): void {

0 commit comments

Comments
 (0)