Skip to content

Commit

Permalink
Remove at() matcher use from encryption tests
Browse files Browse the repository at this point in the history
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
  • Loading branch information
come-nc committed May 24, 2022
1 parent 45a75c6 commit deac17b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 33 deletions.
17 changes: 9 additions & 8 deletions apps/encryption/tests/Controller/SettingsControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,16 @@ public function testUpdatePrivateKeyPassword() {
->method('get')->with('loginname')->willReturn('testUser');

$this->userManagerMock
->expects($this->at(0))
->method('checkPassword')
->with('testUserUid', 'new')
->willReturn(false);
$this->userManagerMock
->expects($this->at(1))
->expects($this->exactly(2))
->method('checkPassword')
->with('testUser', 'new')
->willReturn(true);
->withConsecutive(
['testUserUid', 'new'],
['testUser', 'new'],
)
->willReturnOnConsecutiveCalls(
false,
true,
);



Expand Down
35 changes: 20 additions & 15 deletions apps/encryption/tests/Crypto/EncryptAllTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ public function testEncryptAll() {
->getMock();

$this->util->expects($this->any())->method('isMasterKeyEnabled')->willReturn(false);
$encryptAll->expects($this->at(0))->method('createKeyPairs')->with();
$encryptAll->expects($this->at(1))->method('outputPasswords')->with();
$encryptAll->expects($this->at(2))->method('encryptAllUsersFiles')->with();
$encryptAll->expects($this->once())->method('createKeyPairs')->with();
$encryptAll->expects($this->once())->method('outputPasswords')->with();
$encryptAll->expects($this->once())->method('encryptAllUsersFiles')->with();

$encryptAll->encryptAll($this->inputInterface, $this->outputInterface);
}
Expand Down Expand Up @@ -196,7 +196,7 @@ public function testEncryptAllWithMasterKey() {
$this->util->expects($this->any())->method('isMasterKeyEnabled')->willReturn(true);
$encryptAll->expects($this->never())->method('createKeyPairs');
$this->keyManager->expects($this->once())->method('validateMasterKey');
$encryptAll->expects($this->at(0))->method('encryptAllUsersFiles')->with();
$encryptAll->expects($this->once())->method('encryptAllUsersFiles')->with();
$encryptAll->expects($this->never())->method('outputPasswords');

$encryptAll->encryptAll($this->inputInterface, $this->outputInterface);
Expand Down Expand Up @@ -277,8 +277,11 @@ public function testEncryptAllUsersFiles() {
$this->invokePrivate($encryptAll, 'output', [$this->outputInterface]);
$this->invokePrivate($encryptAll, 'userPasswords', [['user1' => 'pwd1', 'user2' => 'pwd2']]);

$encryptAll->expects($this->at(0))->method('encryptUsersFiles')->with('user1');
$encryptAll->expects($this->at(1))->method('encryptUsersFiles')->with('user2');
$encryptAll->expects($this->exactly(2))->method('encryptUsersFiles')
->withConsecutive(
['user1'],
['user2'],
);

$this->invokePrivate($encryptAll, 'encryptAllUsersFiles');
}
Expand All @@ -305,16 +308,15 @@ public function testEncryptUsersFiles() {

$this->util->expects($this->any())->method('isMasterKeyEnabled')->willReturn(false);

$this->view->expects($this->at(0))->method('getDirectoryContent')
->with('/user1/files')->willReturn(
$this->view->expects($this->exactly(2))->method('getDirectoryContent')
->withConsecutive(
['/user1/files'],
['/user1/files/foo'],
)->willReturnOnConsecutiveCalls(
[
['name' => 'foo', 'type' => 'dir'],
['name' => 'bar', 'type' => 'file'],
]
);

$this->view->expects($this->at(3))->method('getDirectoryContent')
->with('/user1/files/foo')->willReturn(
],
[
['name' => 'subfile', 'type' => 'file']
]
Expand All @@ -330,8 +332,11 @@ function ($path) {
}
);

$encryptAll->expects($this->at(1))->method('encryptFile')->with('/user1/files/bar');
$encryptAll->expects($this->at(2))->method('encryptFile')->with('/user1/files/foo/subfile');
$encryptAll->expects($this->exactly(2))->method('encryptFile')
->withConsecutive(
['/user1/files/bar'],
['/user1/files/foo/subfile'],
);

$this->outputInterface->expects($this->any())
->method('getFormatter')
Expand Down
24 changes: 14 additions & 10 deletions apps/encryption/tests/KeyManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,11 @@ public function testInit($useMasterKey) {
$this->utilMock->expects($this->once())->method('isMasterKeyEnabled')
->willReturn($useMasterKey);

$this->sessionMock->expects($this->at(0))->method('setStatus')
->with(Session::INIT_EXECUTED);
$this->sessionMock->expects($this->exactly(2))->method('setStatus')
->withConsecutive(
[Session::INIT_EXECUTED],
[Session::INIT_SUCCESSFUL],
);

$instance->expects($this->any())->method('getMasterKeyId')->willReturn('masterKeyId');
$instance->expects($this->any())->method('getMasterKeyPassword')->willReturn('masterKeyPassword');
Expand Down Expand Up @@ -404,15 +407,16 @@ public function testGetFileKey($uid, $isMasterKeyEnabled, $privateKey, $expected

$this->invokePrivate($this->instance, 'masterKeyId', ['masterKeyId']);

$this->keyStorageMock->expects($this->at(0))
->method('getFileKey')
->with($path, 'fileKey', 'OC_DEFAULT_MODULE')
->willReturn(true);

$this->keyStorageMock->expects($this->at(1))
$this->keyStorageMock->expects($this->exactly(2))
->method('getFileKey')
->with($path, $expectedUid . '.shareKey', 'OC_DEFAULT_MODULE')
->willReturn(true);
->withConsecutive(
[$path, 'fileKey', 'OC_DEFAULT_MODULE'],
[$path, $expectedUid . '.shareKey', 'OC_DEFAULT_MODULE'],
)
->willReturnOnConsecutiveCalls(
true,
true,
);

$this->utilMock->expects($this->any())->method('isMasterKeyEnabled')
->willReturn($isMasterKeyEnabled);
Expand Down

0 comments on commit deac17b

Please sign in to comment.