Skip to content

Commit

Permalink
Adjust unit testing
Browse files Browse the repository at this point in the history
  • Loading branch information
DeepDiver1975 committed Oct 16, 2017
1 parent 58004d5 commit 81f2684
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
4 changes: 3 additions & 1 deletion lib/private/Encryption/DecryptAll.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class DecryptAll {
* @param Manager $encryptionManager
* @param IUserManager $userManager
* @param View $rootView
* @param ILogger $logger
*/
public function __construct(
Manager $encryptionManager,
Expand Down Expand Up @@ -147,6 +148,7 @@ protected function prepareEncryptionModules($user) {
* iterate over all user and encrypt their files
*
* @param string $user which users files should be decrypted, default = all users
* @return bool
*/
protected function decryptAllUsersFiles($user = '') {

Expand Down Expand Up @@ -204,7 +206,7 @@ protected function decryptAllUsersFiles($user = '') {
$progress->finish();

$this->output->writeln("\n\n");

return true;
}

/**
Expand Down
40 changes: 27 additions & 13 deletions tests/lib/Encryption/DecryptAllTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
use Symfony\Component\Console\Formatter\OutputFormatterInterface;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Console\Output\OutputInterface;
use Test\TestCase;

Expand Down Expand Up @@ -257,10 +258,18 @@ public function dataTestDecryptAllUsersFiles() {
];
}

public function testDecryptUsersFiles() {
$storage = $this->getMockBuilder(SharedStorage::class)
->disableOriginalConstructor()
->getMock();
public function providesData() {
return[
[true],
[false]
];
}
/**
* @param $throwsExceptionInDecrypt
* @dataProvider providesData
*/
public function testDecryptUsersFiles($throwsExceptionInDecrypt) {
$storage = $this->createMock(SharedStorage::class);

/** @var DecryptAll | \PHPUnit_Framework_MockObject_MockObject $instance */
$instance = $this->getMockBuilder(DecryptAll::class)
Expand Down Expand Up @@ -300,18 +309,23 @@ function($path) {
}
);

$instance->expects($this->at(0))
->method('decryptFile')
->with('/user1/files/bar');
$instance->expects($this->at(1))
->method('decryptFile')
->with('/user1/files/foo/subfile');
if ($throwsExceptionInDecrypt) {
$instance->expects($this->at(0))
->method('decryptFile')
->with('/user1/files/bar')
->willThrowException(new \Exception());
} else {
$instance->expects($this->at(0))
->method('decryptFile')
->with('/user1/files/bar');
$instance->expects($this->at(1))
->method('decryptFile')
->with('/user1/files/foo/subfile');
}

$progressBar = $this->getMockBuilder(ProgressBar::class)
->disableOriginalConstructor()->getMock();
$progressBar = new ProgressBar(new NullOutput());

$this->invokePrivate($instance, 'decryptUsersFiles', ['user1', $progressBar, '']);

}

public function testDecryptFile() {
Expand Down

0 comments on commit 81f2684

Please sign in to comment.