|
|
|
@ -82,7 +82,7 @@ class EncryptAllTest extends TestCase {
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* We need format method to return a string
|
|
|
|
* We need format method to return a string
|
|
|
|
* @var OutputFormatterInterface|\PHPUnit\Framework\MockObject\MockObject
|
|
|
|
* @var OutputFormatterInterface&MockObject
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
$outputFormatter = $this->createMock(OutputFormatterInterface::class);
|
|
|
|
$outputFormatter = $this->createMock(OutputFormatterInterface::class);
|
|
|
|
$outputFormatter->method('isDecorated')->willReturn(false);
|
|
|
|
$outputFormatter->method('isDecorated')->willReturn(false);
|
|
|
|
@ -114,6 +114,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 {
|
|
|
|
public function testEncryptAll(): void {
|
|
|
|
/** @var EncryptAll&MockObject $encryptAll */
|
|
|
|
/** @var EncryptAll&MockObject $encryptAll */
|
|
|
|
$encryptAll = $this->getMockBuilder(EncryptAll::class)
|
|
|
|
$encryptAll = $this->getMockBuilder(EncryptAll::class)
|
|
|
|
@ -299,8 +306,8 @@ class EncryptAllTest extends TestCase {
|
|
|
|
'',
|
|
|
|
'',
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
[
|
|
|
|
[
|
|
|
|
['name' => 'foo', 'type' => 'dir'],
|
|
|
|
$this->createFileInfoMock(FileInfo::TYPE_FOLDER, 'foo'),
|
|
|
|
['name' => 'bar', 'type' => 'file'],
|
|
|
|
$this->createFileInfoMock(FileInfo::TYPE_FILE, 'bar'),
|
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
[
|
|
|
|
[
|
|
|
|
@ -308,26 +315,17 @@ class EncryptAllTest extends TestCase {
|
|
|
|
'',
|
|
|
|
'',
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
[
|
|
|
|
[
|
|
|
|
['name' => 'subfile', 'type' => 'file']
|
|
|
|
$this->createFileInfoMock(FileInfo::TYPE_FILE, 'subfile'),
|
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
$this->view->expects($this->any())->method('is_dir')
|
|
|
|
|
|
|
|
->willReturnCallback(
|
|
|
|
|
|
|
|
function ($path) {
|
|
|
|
|
|
|
|
if ($path === '/user1/files/foo') {
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$encryptAllCalls = [];
|
|
|
|
$encryptAllCalls = [];
|
|
|
|
$encryptAll->expects($this->exactly(2))
|
|
|
|
$encryptAll->expects($this->exactly(2))
|
|
|
|
->method('encryptFile')
|
|
|
|
->method('encryptFile')
|
|
|
|
->willReturnCallback(function (string $path) use (&$encryptAllCalls): void {
|
|
|
|
->willReturnCallback(function (FileInfo $file, string $path) use (&$encryptAllCalls): bool {
|
|
|
|
$encryptAllCalls[] = $path;
|
|
|
|
$encryptAllCalls[] = $path;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
$outputFormatter = $this->createMock(OutputFormatterInterface::class);
|
|
|
|
$outputFormatter = $this->createMock(OutputFormatterInterface::class);
|
|
|
|
@ -362,8 +360,7 @@ class EncryptAllTest extends TestCase {
|
|
|
|
$fileInfo = $this->createMock(FileInfo::class);
|
|
|
|
$fileInfo = $this->createMock(FileInfo::class);
|
|
|
|
$fileInfo->expects($this->any())->method('isEncrypted')
|
|
|
|
$fileInfo->expects($this->any())->method('isEncrypted')
|
|
|
|
->willReturn($isEncrypted);
|
|
|
|
->willReturn($isEncrypted);
|
|
|
|
$this->view->expects($this->any())->method('getFileInfo')
|
|
|
|
$this->view->expects($this->never())->method('getFileInfo');
|
|
|
|
->willReturn($fileInfo);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($isEncrypted) {
|
|
|
|
if ($isEncrypted) {
|
|
|
|
@ -375,7 +372,7 @@ class EncryptAllTest extends TestCase {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$this->assertTrue(
|
|
|
|
$this->assertTrue(
|
|
|
|
$this->invokePrivate($this->encryptAll, 'encryptFile', ['foo.txt'])
|
|
|
|
$this->invokePrivate($this->encryptAll, 'encryptFile', [$fileInfo, 'foo.txt'])
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|