test: Finish migrating tests/Core/ to PHPUnit 10 compatible code

Signed-off-by: Joas Schilling <coding@schilljs.com>
pull/52588/head
Joas Schilling 2025-05-02 14:00:10 +07:00
parent 9a16e4fd14
commit c24f5fb256
No known key found for this signature in database
GPG Key ID: F72FA5B49FFA96B0
46 changed files with 864 additions and 880 deletions

@ -50,7 +50,7 @@ class AppsDisableTest extends TestCase {
$this->assertSame($statusCode, $this->commandTester->getStatusCode());
}
public function dataCommandInput(): array {
public static function dataCommandInput(): array {
return [
[['admin_audit'], 0, 'admin_audit ([\d\.]*) disabled'],
[['comments'], 0, 'comments ([\d\.]*) disabled'],

@ -57,7 +57,7 @@ class AppsEnableTest extends TestCase {
$this->assertSame($statusCode, $this->commandTester->getStatusCode());
}
public function dataCommandInput(): array {
public static function dataCommandInput(): array {
return [
[['admin_audit'], null, 0, 'admin_audit ([\d\.]*) enabled'],
[['comments'], null, 0, 'comments ([\d\.]*) enabled'],

@ -38,7 +38,7 @@ class ImportTest extends TestCase {
$this->command = new Import($config);
}
public function validateAppsArrayData() {
public static function validateAppsArrayData(): array {
return [
[0],
[1],
@ -58,7 +58,7 @@ class ImportTest extends TestCase {
$this->assertTrue(true, 'Asserting that no exception is thrown');
}
public function validateAppsArrayThrowsData() {
public static function validateAppsArrayThrowsData(): array {
return [
[false],
[true],
@ -81,7 +81,7 @@ class ImportTest extends TestCase {
}
}
public function checkTypeRecursivelyData() {
public static function checkTypeRecursivelyData(): array {
return [
[0],
[1],
@ -107,7 +107,7 @@ class ImportTest extends TestCase {
$this->assertTrue(true, 'Asserting that no exception is thrown');
}
public function checkTypeRecursivelyThrowsData() {
public static function checkTypeRecursivelyThrowsData(): array {
return [
[new \Exception()],
[[new \Exception()]],
@ -130,7 +130,7 @@ class ImportTest extends TestCase {
}
}
public function validateArrayData() {
public static function validateArrayData(): array {
return [
[['system' => []]],
[['apps' => []]],
@ -148,7 +148,7 @@ class ImportTest extends TestCase {
$this->assertTrue(true, 'Asserting that no exception is thrown');
}
public function validateArrayThrowsData() {
public static function validateArrayThrowsData(): array {
return [
[[], 'At least one key of the following is expected:'],
[[0 => []], 'Found invalid entries in root'],

@ -46,7 +46,7 @@ class ListConfigsTest extends TestCase {
$this->command = new ListConfigs($systemConfig, $appConfig);
}
public function listData() {
public static function listData(): array {
return [
[
'all',

@ -38,7 +38,7 @@ class DeleteConfigTest extends TestCase {
$this->command = new DeleteConfig($systemConfig);
}
public function deleteData() {
public static function deleteData(): array {
return [
[
'name1',
@ -105,7 +105,7 @@ class DeleteConfigTest extends TestCase {
$this->assertSame($expectedReturn, $this->invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]));
}
public function deleteArrayData() {
public static function deleteArrayData(): array {
return [
[
['name', 'sub'],

@ -39,7 +39,7 @@ class GetConfigTest extends TestCase {
}
public function getData() {
public static function getData(): array {
return [
// String output as json
['name', 'newvalue', true, null, false, 'json', 0, json_encode('newvalue')],

@ -76,7 +76,7 @@ class SetConfigTest extends TestCase {
$this->invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]);
}
public function setUpdateOnlyProvider() {
public static function setUpdateOnlyProvider(): array {
return [
[['name'], null],
[['a', 'b', 'c'], null],
@ -113,7 +113,7 @@ class SetConfigTest extends TestCase {
$this->invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]);
}
public function castValueProvider() {
public static function castValueProvider(): array {
return [
[null, 'string', ['value' => '', 'readable-value' => 'empty string']],
@ -141,7 +141,7 @@ class SetConfigTest extends TestCase {
);
}
public function castValueInvalidProvider() {
public static function castValueInvalidProvider(): array {
return [
['123', 'foobar'],

@ -89,7 +89,7 @@ class ChangeKeyStorageRootTest extends TestCase {
$this->util,
$this->questionHelper
]
)->setMethods(['moveAllKeys'])->getMock();
)->onlyMethods(['moveAllKeys'])->getMock();
$this->util->expects($this->once())->method('getKeyStorageRoot')
->willReturn('');
@ -122,7 +122,7 @@ class ChangeKeyStorageRootTest extends TestCase {
);
}
public function dataTestExecute() {
public static function dataTestExecute(): array {
return [
[null, true, true],
[null, true, false],
@ -143,7 +143,7 @@ class ChangeKeyStorageRootTest extends TestCase {
$this->util,
$this->questionHelper
]
)->setMethods(['prepareNewRoot', 'moveSystemKeys', 'moveUserKeys'])->getMock();
)->onlyMethods(['prepareNewRoot', 'moveSystemKeys', 'moveUserKeys'])->getMock();
$changeKeyStorageRoot->expects($this->once())->method('prepareNewRoot')->with('newRoot');
$changeKeyStorageRoot->expects($this->once())->method('moveSystemKeys')->with('oldRoot', 'newRoot');
@ -179,7 +179,7 @@ class ChangeKeyStorageRootTest extends TestCase {
$this->invokePrivate($this->changeKeyStorageRoot, 'prepareNewRoot', ['newRoot']);
}
public function dataTestPrepareNewRootException() {
public static function dataTestPrepareNewRootException(): array {
return [
[true, false],
[true, null],
@ -204,7 +204,7 @@ class ChangeKeyStorageRootTest extends TestCase {
$this->util,
$this->questionHelper
]
)->setMethods(['targetExists'])->getMock();
)->onlyMethods(['targetExists'])->getMock();
$this->view->expects($this->once())->method('is_dir')
->with('oldRoot/files_encryption')->willReturn($dirExists);
@ -221,7 +221,7 @@ class ChangeKeyStorageRootTest extends TestCase {
$this->invokePrivate($changeKeyStorageRoot, 'moveSystemKeys', ['oldRoot', 'newRoot']);
}
public function dataTestMoveSystemKeys() {
public static function dataTestMoveSystemKeys(): array {
return [
[true, false, true],
[false, true, false],
@ -241,7 +241,7 @@ class ChangeKeyStorageRootTest extends TestCase {
$this->util,
$this->questionHelper
]
)->setMethods(['setupUserFS', 'moveUserEncryptionFolder'])->getMock();
)->onlyMethods(['setupUserFS', 'moveUserEncryptionFolder'])->getMock();
$this->userManager->expects($this->once())->method('getBackends')
->willReturn([$this->userInterface]);
@ -271,7 +271,7 @@ class ChangeKeyStorageRootTest extends TestCase {
$this->util,
$this->questionHelper
]
)->setMethods(['targetExists', 'prepareParentFolder'])->getMock();
)->onlyMethods(['targetExists', 'prepareParentFolder'])->getMock();
$this->userManager->expects($this->once())->method('userExists')
->willReturn($userExists);
@ -293,7 +293,7 @@ class ChangeKeyStorageRootTest extends TestCase {
$this->invokePrivate($changeKeyStorageRoot, 'moveUserEncryptionFolder', ['user1', 'oldRoot', 'newRoot']);
}
public function dataTestMoveUserEncryptionFolder() {
public static function dataTestMoveUserEncryptionFolder(): array {
return [
[true, true, false, true],
[true, false, true, false],
@ -334,7 +334,7 @@ class ChangeKeyStorageRootTest extends TestCase {
);
}
public function dataTestPrepareParentFolder() {
public static function dataTestPrepareParentFolder(): array {
return [
['/user/folder/sub_folder/keystorage', true],
['/user/folder/sub_folder/keystorage', false]

@ -73,12 +73,16 @@ class DecryptAllTest extends TestCase {
public function testMaintenanceAndTrashbin(): void {
// on construct we enable single-user-mode and disable the trash bin
// on destruct we disable single-user-mode again and enable the trash bin
$calls = [
['maintenance', true],
['maintenance', false],
];
$this->config->expects($this->exactly(2))
->method('setSystemValue')
->withConsecutive(
['maintenance', true],
['maintenance', false],
);
->willReturnCallback(function () use (&$calls) {
$expected = array_shift($calls);
$this->assertEquals($expected, func_get_args());
});
$this->appManager->expects($this->once())
->method('disableApp')
->with('files_trashbin');
@ -127,12 +131,16 @@ class DecryptAllTest extends TestCase {
->willReturn('user1');
if ($encryptionEnabled) {
$calls = [
['core', 'encryption_enabled', 'no'],
['core', 'encryption_enabled', 'yes'],
];
$this->config->expects($this->exactly(2))
->method('setAppValue')
->withConsecutive(
['core', 'encryption_enabled', 'no'],
['core', 'encryption_enabled', 'yes'],
);
->willReturnCallback(function () use (&$calls) {
$expected = array_shift($calls);
$this->assertEquals($expected, func_get_args());
});
$this->questionHelper->expects($this->once())
->method('ask')
->willReturn($continue);
@ -152,7 +160,7 @@ class DecryptAllTest extends TestCase {
$this->invokePrivate($instance, 'execute', [$this->consoleInput, $this->consoleOutput]);
}
public function dataTestExecute() {
public static function dataTestExecute(): array {
return [
[true, true],
[true, false],
@ -174,13 +182,16 @@ class DecryptAllTest extends TestCase {
);
// make sure that we enable encryption again after a exception was thrown
$calls = [
['core', 'encryption_enabled', 'no'],
['core', 'encryption_enabled', 'yes'],
];
$this->config->expects($this->exactly(2))
->method('setAppValue')
->withConsecutive(
['core', 'encryption_enabled', 'no'],
['core', 'encryption_enabled', 'yes'],
);
->willReturnCallback(function () use (&$calls) {
$expected = array_shift($calls);
$this->assertEquals($expected, func_get_args());
});
$this->encryptionManager->expects($this->once())
->method('isEnabled')
->willReturn(true);

@ -38,7 +38,7 @@ class DisableTest extends TestCase {
}
public function dataDisable() {
public static function dataDisable(): array {
return [
['yes', true, 'Encryption disabled'],
['no', false, 'Encryption is already disabled'],

@ -99,7 +99,7 @@ class EncryptAllTest extends TestCase {
$this->invokePrivate($command, 'execute', [$this->consoleInput, $this->consoleOutput]);
}
public function dataTestExecute() {
public static function dataTestExecute(): array {
return [
['y', true], ['Y', true], ['n', false], ['N', false], ['', false]
];

@ -43,7 +43,7 @@ class SetDefaultModuleTest extends TestCase {
}
public function dataSetDefaultModule() {
public static function dataSetDefaultModule(): array {
return [
['ID0', 'ID0', null, null, 'already'],
['ID0', 'ID1', 'ID1', true, 'info'],
@ -113,12 +113,16 @@ class SetDefaultModuleTest extends TestCase {
->with('maintenance', false)
->willReturn(true);
$calls = [
'Maintenance mode must be disabled when setting default module,',
'in order to load the relevant encryption modules correctly.',
];
$this->consoleOutput->expects($this->exactly(2))
->method('writeln')
->withConsecutive(
[$this->stringContains('Maintenance mode must be disabled when setting default module,')],
[$this->stringContains('in order to load the relevant encryption modules correctly.')],
);
->willReturnCallback(function ($message) use (&$calls) {
$expected = array_shift($calls);
$this->assertStringContainsString($expected, $message);
});
self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]);
}

@ -32,7 +32,7 @@ class InfoTest extends TestCase {
$this->groupManager = $this->createMock(IGroupManager::class);
$this->command = $this->getMockBuilder(Info::class)
->setConstructorArgs([$this->groupManager])
->setMethods(['writeArrayInOutputFormat'])
->onlyMethods(['writeArrayInOutputFormat'])
->getMock();
$this->input = $this->createMock(InputInterface::class);

@ -33,7 +33,7 @@ class ListCommandTest extends TestCase {
$this->groupManager = $this->createMock(IGroupManager::class);
$this->command = $this->getMockBuilder(ListCommand::class)
->setConstructorArgs([$this->groupManager])
->setMethods(['writeArrayInOutputFormat'])
->onlyMethods(['writeArrayInOutputFormat'])
->getMock();
$this->input = $this->createMock(InputInterface::class);

@ -33,15 +33,10 @@ class UpdateDBTest extends TestCase {
protected function setUp(): void {
parent::setUp();
$this->detector = $this->getMockBuilder(Detection::class)
->disableOriginalConstructor()
->getMock();
$this->loader = $this->getMockBuilder(Loader::class)
->disableOriginalConstructor()
->getMock();
$this->consoleInput = $this->getMockBuilder(InputInterface::class)->getMock();
$this->consoleOutput = $this->getMockBuilder(OutputInterface::class)->getMock();
$this->detector = $this->createMock(Detection::class);
$this->loader = $this->createMock(Loader::class);
$this->consoleInput = $this->createMock(InputInterface::class);
$this->consoleOutput = $this->createMock(OutputInterface::class);
$this->command = new UpdateDB($this->detector, $this->loader);
}
@ -64,12 +59,16 @@ class UpdateDBTest extends TestCase {
$this->loader->expects($this->never())
->method('updateFilecache');
$calls = [
'Added 0 new mimetypes',
'Updated 0 filecache rows',
];
$this->consoleOutput->expects($this->exactly(2))
->method('writeln')
->withConsecutive(
['Added 0 new mimetypes'],
['Updated 0 filecache rows'],
);
->willReturnCallback(function ($message) use (&$calls) {
$expected = array_shift($calls);
$this->assertStringContainsString($expected, $message);
});
self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]);
}
@ -103,14 +102,18 @@ class UpdateDBTest extends TestCase {
->with('new', 2)
->willReturn(3);
$calls = [
'Added mimetype "testing/newmimetype" to database',
'Updated 3 filecache rows for mimetype "testing/newmimetype"',
'Added 1 new mimetypes',
'Updated 3 filecache rows',
];
$this->consoleOutput->expects($this->exactly(4))
->method('writeln')
->withConsecutive(
['Added mimetype "testing/newmimetype" to database'],
['Updated 3 filecache rows for mimetype "testing/newmimetype"'],
['Added 1 new mimetypes'],
['Updated 3 filecache rows'],
);
->willReturnCallback(function ($message) use (&$calls) {
$expected = array_shift($calls);
$this->assertStringContainsString($expected, $message);
});
self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]);
}
@ -153,13 +156,17 @@ class UpdateDBTest extends TestCase {
->with('ext', 1)
->willReturn(3);
$calls = [
'Updated 3 filecache rows for mimetype "testing/existingmimetype"',
'Added 0 new mimetypes',
'Updated 3 filecache rows',
];
$this->consoleOutput->expects($this->exactly(3))
->method('writeln')
->withConsecutive(
['Updated 3 filecache rows for mimetype "testing/existingmimetype"'],
['Added 0 new mimetypes'],
['Updated 3 filecache rows'],
);
->willReturnCallback(function ($message) use (&$calls) {
$expected = array_shift($calls);
$this->assertStringContainsString($expected, $message);
});
self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]);
}

@ -67,7 +67,7 @@ class ModeTest extends TestCase {
*
* @return array
*/
public function getExecuteTestData(): array {
public static function getExecuteTestData(): array {
return [
'off -> on' => [
'on', // command option

@ -16,6 +16,7 @@ use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Formatter\OutputFormatterInterface;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Output\OutputInterface;
use Test\TestCase;
@ -54,8 +55,7 @@ class RepairTest extends TestCase {
$this->iniGetWrapper,
$this->createMock(ILockingProvider::class)
);
$this->input = $this->getMockBuilder(InputInterface::class)
->getMock();
$this->input = $this->createMock(InputInterface::class);
$this->input->expects($this->any())
->method('getOption')
->willReturnCallback(function ($parameter) {
@ -64,13 +64,10 @@ class RepairTest extends TestCase {
}
return null;
});
$this->output = $this->getMockBuilder(OutputInterface::class)
->setMethods(['section', 'writeln', 'write', 'setVerbosity', 'getVerbosity', 'isQuiet', 'isVerbose', 'isVeryVerbose', 'isDebug', 'setDecorated', 'isDecorated', 'setFormatter', 'getFormatter'])
$this->output = $this->getMockBuilder(ConsoleOutput::class)
->onlyMethods(['section', 'writeln', 'getFormatter'])
->getMock();
$self = $this;
$this->output->expects($this->any())
->method('section')
->willReturn($this->output);
/* We need format method to return a string */
$outputFormatter = $this->createMock(OutputFormatterInterface::class);
@ -87,7 +84,7 @@ class RepairTest extends TestCase {
});
}
public function emptyTestDataProvider() {
public static function dataEmptyTest(): array {
/** directoryNames, expectedOutput */
return [
[
@ -114,7 +111,7 @@ class RepairTest extends TestCase {
}
/**
* @dataProvider emptyTestDataProvider
* @dataProvider dataEmptyTest
*/
public function testEmptyExecute($directoryNames, $expectedOutput): void {
$previewFolder = $this->getMockBuilder(Folder::class)

@ -33,7 +33,7 @@ class AddTest extends TestCase {
$this->systemTagManager = $this->createMock(ISystemTagManager::class);
$this->command = $this->getMockBuilder(Add::class)
->setConstructorArgs([$this->systemTagManager])
->setMethods(['writeArrayInOutputFormat'])
->onlyMethods(['writeArrayInOutputFormat'])
->getMock();
$this->input = $this->createMock(InputInterface::class);

@ -32,7 +32,7 @@ class DeleteTest extends TestCase {
$this->systemTagManager = $this->createMock(ISystemTagManager::class);
$this->command = $this->getMockBuilder(Delete::class)
->setConstructorArgs([$this->systemTagManager])
->setMethods(['writeArrayInOutputFormat'])
->onlyMethods(['writeArrayInOutputFormat'])
->getMock();
$this->input = $this->createMock(InputInterface::class);

@ -33,7 +33,7 @@ class EditTest extends TestCase {
$this->systemTagManager = $this->createMock(ISystemTagManager::class);
$this->command = $this->getMockBuilder(Edit::class)
->setConstructorArgs([$this->systemTagManager])
->setMethods(['writeArrayInOutputFormat'])
->onlyMethods(['writeArrayInOutputFormat'])
->getMock();
$this->input = $this->createMock(InputInterface::class);

@ -32,7 +32,7 @@ class ListCommandTest extends TestCase {
$this->systemTagManager = $this->createMock(ISystemTagManager::class);
$this->command = $this->getMockBuilder(ListCommand::class)
->setConstructorArgs([$this->systemTagManager])
->setMethods(['writeArrayInOutputFormat'])
->onlyMethods(['writeArrayInOutputFormat'])
->getMock();
$this->input = $this->createMock(InputInterface::class);

@ -126,7 +126,7 @@ class AddTest extends TestCase {
/**
* @return array
*/
public function addEmailDataProvider(): array {
public static function addEmailDataProvider(): array {
return [
'Valid E-Mail' => [
'info@example.com',

@ -39,7 +39,7 @@ class DeleteTest extends TestCase {
}
public function validUserLastSeen() {
public static function validUserLastSeen(): array {
return [
[true, 'The specified user was deleted'],
[false, 'The specified user could not be deleted'],

@ -38,7 +38,7 @@ class LastSeenTest extends TestCase {
$this->command = new LastSeen($userManager);
}
public function validUserLastSeen() {
public static function validUserLastSeen(): array {
return [
[0, 'never logged in'],
[time(), 'last login'],

@ -62,7 +62,7 @@ class SettingTest extends TestCase {
}
}
public function dataCheckInput() {
public static function dataCheckInput(): array {
return [
[
[['uid', 'username']],
@ -235,7 +235,7 @@ class SettingTest extends TestCase {
$this->assertEquals(1, $this->invokePrivate($command, 'execute', [$this->consoleInput, $this->consoleOutput]));
}
public function dataExecuteDelete() {
public static function dataExecuteDelete(): array {
return [
['config', false, null, 0],
['config', true, null, 0],
@ -299,7 +299,7 @@ class SettingTest extends TestCase {
$this->assertEquals($expectedReturn, $this->invokePrivate($command, 'execute', [$this->consoleInput, $this->consoleOutput]));
}
public function dataExecuteSet() {
public static function dataExecuteSet(): array {
return [
['config', false, null, 0],
['config', true, null, 0],
@ -367,7 +367,7 @@ class SettingTest extends TestCase {
$this->assertEquals($expectedReturn, $this->invokePrivate($command, 'execute', [$this->consoleInput, $this->consoleOutput]));
}
public function dataExecuteGet() {
public static function dataExecuteGet(): array {
return [
['config', null, 'config', 0],
[null, 'config', 'config', 0],

@ -42,7 +42,7 @@ class AutoCompleteControllerTest extends TestCase {
);
}
public function searchDataProvider() {
public static function searchDataProvider(): array {
return [
[ #0 regular search
// searchResults

@ -118,10 +118,6 @@ class ClientFlowLoginControllerTest extends TestCase {
public function testShowAuthPickerPageWithOcsHeader(): void {
$this->request
->method('getHeader')
->withConsecutive(
['USER_AGENT'],
['OCS-APIREQUEST']
)
->willReturnMap([
['USER_AGENT', 'Mac OS X Sync Client'],
['OCS-APIREQUEST', 'true'],
@ -181,10 +177,6 @@ class ClientFlowLoginControllerTest extends TestCase {
public function testShowAuthPickerPageWithOauth(): void {
$this->request
->method('getHeader')
->withConsecutive(
['USER_AGENT'],
['OCS-APIREQUEST']
)
->willReturnMap([
['USER_AGENT', 'Mac OS X Sync Client'],
['OCS-APIREQUEST', 'false'],
@ -404,20 +396,20 @@ class ClientFlowLoginControllerTest extends TestCase {
public function testGeneratePasswordWithPasswordForOauthClient($redirectUri, $redirectUrl): void {
$this->session
->method('get')
->withConsecutive(
['client.flow.state.token'],
['oauth.state']
)
->willReturnMap([
['client.flow.state.token', 'MyStateToken'],
['oauth.state', 'MyOauthState'],
]);
$calls = [
'client.flow.state.token',
'oauth.state',
];
$this->session
->method('remove')
->withConsecutive(
['client.flow.state.token'],
['oauth.state']
);
->willReturnCallback(function ($key) use (&$calls) {
$expected = array_shift($calls);
$this->assertEquals($expected, $key);
});
$this->session
->expects($this->once())
->method('getId')
@ -439,10 +431,6 @@ class ClientFlowLoginControllerTest extends TestCase {
->willReturn('MyPassword');
$this->random
->method('generate')
->withConsecutive(
[72],
[128]
)
->willReturnMap([
[72, ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS, 'MyGeneratedToken'],
[128, ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS, 'MyAccessCode'],
@ -561,7 +549,7 @@ class ClientFlowLoginControllerTest extends TestCase {
$this->assertEquals($expected, $this->clientFlowLoginController->generateAppPassword('MyStateToken'));
}
public function dataGeneratePasswordWithHttpsProxy() {
public static function dataGeneratePasswordWithHttpsProxy(): array {
return [
[
[

@ -255,9 +255,9 @@ class LoginControllerTest extends TestCase {
],
]
);
$this->initialState->expects($this->exactly(13))
->method('provideInitialState')
->withConsecutive([
$calls = [
[
'loginMessages',
[
'MessageArray1',
@ -265,17 +265,26 @@ class LoginControllerTest extends TestCase {
'This community release of Nextcloud is unsupported and push notifications are limited.',
],
],
[
'loginErrors',
[
'loginErrors',
[
'ErrorArray1',
'ErrorArray2',
],
'ErrorArray1',
'ErrorArray2',
],
[
'loginUsername',
'',
]);
],
[
'loginUsername',
'',
]
];
$this->initialState->expects($this->exactly(13))
->method('provideInitialState')
->willReturnCallback(function () use (&$calls) {
$expected = array_shift($calls);
if (!empty($expected)) {
$this->assertEquals($expected, func_get_args());
}
});
$expectedResponse = new TemplateResponse(
'core',
@ -294,15 +303,25 @@ class LoginControllerTest extends TestCase {
->expects($this->once())
->method('isLoggedIn')
->willReturn(false);
$this->initialState->expects($this->exactly(14))
->method('provideInitialState')
->withConsecutive([], [], [], [
$calls = [
[], [], [],
[
'loginAutocomplete',
false
], [
],
[
'loginRedirectUrl',
'login/flow'
]);
],
];
$this->initialState->expects($this->exactly(14))
->method('provideInitialState')
->willReturnCallback(function () use (&$calls) {
$expected = array_shift($calls);
if (!empty($expected)) {
$this->assertEquals($expected, func_get_args());
}
});
$expectedResponse = new TemplateResponse(
'core',
@ -319,7 +338,7 @@ class LoginControllerTest extends TestCase {
/**
* @return array
*/
public function passwordResetDataProvider(): array {
public static function passwordResetDataProvider(): array {
return [
[
true,
@ -363,15 +382,26 @@ class LoginControllerTest extends TestCase {
->method('get')
->with('LdapUser')
->willReturn($user);
$this->initialState->expects($this->exactly(13))
->method('provideInitialState')
->withConsecutive([], [], [
$calls = [
[], [],
[
'loginUsername',
'LdapUser'
], [], [], [], [
],
[], [], [],
[
'loginCanResetPassword',
$expectedResult
]);
],
];
$this->initialState->expects($this->exactly(13))
->method('provideInitialState')
->willReturnCallback(function () use (&$calls) {
$expected = array_shift($calls);
if (!empty($expected)) {
$this->assertEquals($expected, func_get_args());
}
});
$expectedResponse = new TemplateResponse(
'core',
@ -411,18 +441,30 @@ class LoginControllerTest extends TestCase {
->method('get')
->with('0')
->willReturn($user);
$this->initialState->expects($this->exactly(13))
->method('provideInitialState')
->withConsecutive([], [], [], [
$calls = [
[], [], [],
[
'loginAutocomplete',
true
], [], [
],
[],
[
'loginResetPasswordLink',
false
], [
],
[
'loginCanResetPassword',
false
]);
],
];
$this->initialState->expects($this->exactly(13))
->method('provideInitialState')
->willReturnCallback(function () use (&$calls) {
$expected = array_shift($calls);
if (!empty($expected)) {
$this->assertEquals($expected, func_get_args());
}
});
$expectedResponse = new TemplateResponse(
'core',

@ -172,13 +172,18 @@ class LostControllerTest extends TestCase {
->method('linkToRouteAbsolute')
->with('core.lost.setPassword', ['userId' => 'ValidTokenUser', 'token' => 'MySecretToken'])
->willReturn('https://example.tld/index.php/lostpassword/set/sometoken/someuser');
$calls = [
['resetPasswordUser', 'ValidTokenUser'],
['resetPasswordTarget', 'https://example.tld/index.php/lostpassword/set/sometoken/someuser'],
];
$this->initialState
->expects($this->exactly(2))
->method('provideInitialState')
->withConsecutive(
['resetPasswordUser', 'ValidTokenUser'],
['resetPasswordTarget', 'https://example.tld/index.php/lostpassword/set/sometoken/someuser']
);
->willReturnCallback(function () use (&$calls) {
$expected = array_shift($calls);
$this->assertEquals($expected, func_get_args());
});
$response = $this->lostController->resetform('MySecretToken', 'ValidTokenUser');
$expectedResponse = new TemplateResponse('core',
@ -448,12 +453,19 @@ class LostControllerTest extends TestCase {
$this->userManager->method('get')
->with('ValidTokenUser')
->willReturn($this->existingUser);
$beforePasswordResetEvent = new BeforePasswordResetEvent($this->existingUser, 'NewPassword');
$passwordResetEvent = new PasswordResetEvent($this->existingUser, 'NewPassword');
$calls = [
[new BeforePasswordResetEvent($this->existingUser, 'NewPassword')],
[new PasswordResetEvent($this->existingUser, 'NewPassword')],
];
$this->eventDispatcher
->expects($this->exactly(2))
->method('dispatchTyped')
->withConsecutive([$beforePasswordResetEvent], [$passwordResetEvent]);
->willReturnCallback(function () use (&$calls) {
$expected = array_shift($calls);
$this->assertEquals($expected, func_get_args());
});
$this->config->expects($this->once())
->method('deleteUserValue')
->with('ValidTokenUser', 'core', 'lostpassword');
@ -666,15 +678,15 @@ class LostControllerTest extends TestCase {
/**
* @return array
*/
public function dataTwoUserswithSameEmailOneDisabled(): array {
public static function dataTwoUsersWithSameEmailOneDisabled(): array {
return [
['user1' => true, 'user2' => false],
['user1' => false, 'user2' => true]
['userEnabled1' => true, 'userEnabled2' => false],
['userEnabled1' => false, 'userEnabled2' => true]
];
}
/**
* @dataProvider dataTwoUserswithSameEmailOneDisabled
* @dataProvider dataTwoUsersWithSameEmailOneDisabled
* @param bool $userEnabled1
* @param bool $userEnabled2
*/

@ -68,7 +68,7 @@ class TwoFactorChallengeControllerTest extends TestCase {
$this->urlGenerator,
$this->logger,
])
->setMethods(['getLogoutUrl'])
->onlyMethods(['getLogoutUrl'])
->getMock();
$this->controller->expects($this->any())
->method('getLogoutUrl')
@ -302,12 +302,16 @@ class TwoFactorChallengeControllerTest extends TestCase {
->method('verifyChallenge')
->with('myprovider', $user, 'token')
->will($this->throwException($exception));
$calls = [
['two_factor_auth_error_message', '2FA failed'],
['two_factor_auth_error', true],
];
$this->session->expects($this->exactly(2))
->method('set')
->withConsecutive(
['two_factor_auth_error_message', '2FA failed'],
['two_factor_auth_error', true]
);
->willReturnCallback(function () use (&$calls) {
$expected = array_shift($calls);
$this->assertEquals($expected, func_get_args());
});
$this->urlGenerator->expects($this->once())
->method('linkToRoute')
->with('core.TwoFactorChallenge.showChallenge', [

@ -33,7 +33,7 @@ class WipeControllerTest extends TestCase {
$this->remoteWipe);
}
public function dataTest() {
public static function dataTest(): array {
return [
// valid token, could perform operation, valid result
[ true, true, true],

@ -234,23 +234,29 @@ class TwoFactorMiddlewareTest extends TestCase {
$this->middleware->beforeController($twoFactorChallengeController, 'index');
}
public function dataRequires2FASetupDone() {
$provider = $this->createMock(IProvider::class);
$provider->method('getId')
->willReturn('2FAftw');
public static function dataRequires2FASetupDone(): array {
return [
[[], false, false],
[[], true, true],
[[$provider], false, true],
[[$provider], true, true],
[false, false, false],
[false, true, true],
[true, false, true],
[true, true, true],
];
}
/**
* @dataProvider dataRequires2FASetupDone
*/
public function testRequires2FASetupDone(array $providers, bool $missingProviders, bool $expectEception): void {
public function testRequires2FASetupDone(bool $hasProvider, bool $missingProviders, bool $expectEception): void {
if ($hasProvider) {
$provider = $this->createMock(IProvider::class);
$provider->method('getId')
->willReturn('2FAftw');
$providers = [$provider];
} else {
$providers = [];
}
$user = $this->createMock(IUser::class);
$this->reflector

@ -67,26 +67,13 @@ class LoginFlowV2ServiceUnitTest extends TestCase {
* Code was moved to separate function to keep setUp function small and clear.
*/
private function setupSubjectUnderTest(): void {
$this->config = $this->getMockBuilder(IConfig::class)
->disableOriginalConstructor()->getMock();
$this->crypto = $this->getMockBuilder(ICrypto::class)
->disableOriginalConstructor()->getMock();
$this->mapper = $this->getMockBuilder(LoginFlowV2Mapper::class)
->disableOriginalConstructor()->getMock();
$this->logger = $this->getMockBuilder(LoggerInterface::class)
->disableOriginalConstructor()->getMock();
$this->tokenProvider = $this->getMockBuilder(IProvider::class)
->disableOriginalConstructor()->getMock();
$this->secureRandom = $this->getMockBuilder(ISecureRandom::class)
->disableOriginalConstructor()->getMock();
$this->timeFactory = $this->getMockBuilder(ITimeFactory::class)
->disableOriginalConstructor()->getMock();
$this->config = $this->createMock(IConfig::class);
$this->crypto = $this->createMock(ICrypto::class);
$this->mapper = $this->createMock(LoginFlowV2Mapper::class);
$this->logger = $this->createMock(LoggerInterface::class);
$this->tokenProvider = $this->createMock(IProvider::class);
$this->secureRandom = $this->createMock(ISecureRandom::class);
$this->timeFactory = $this->createMock(ITimeFactory::class);
$this->subjectUnderTest = new LoginFlowV2Service(
$this->mapper,

@ -76,13 +76,10 @@ class LookupPluginTest extends TestCase {
->willReturn('yes');
$this->config->expects($this->exactly(2))
->method('getSystemValueBool')
->withConsecutive(
['gs.enabled', false],
['has_internet_connection', true],
)->willReturnOnConsecutiveCalls(
true,
true,
);
->willReturnMap([
['gs.enabled', false, true],
['has_internet_connection', true, true],
]);
$this->config->expects($this->once())
->method('getSystemValueString')
@ -105,13 +102,10 @@ class LookupPluginTest extends TestCase {
->willReturn('yes');
$this->config->expects($this->exactly(2))
->method('getSystemValueBool')
->withConsecutive(
['gs.enabled', false],
['has_internet_connection', true],
)->willReturnOnConsecutiveCalls(
false,
false,
);
->willReturnMap([
['gs.enabled', false, false],
['has_internet_connection', true, false],
]);
$this->clientService->expects($this->never())
->method('newClient');
@ -141,13 +135,10 @@ class LookupPluginTest extends TestCase {
->willReturn('yes');
$this->config->expects($this->exactly(2))
->method('getSystemValueBool')
->withConsecutive(
['gs.enabled', false],
['has_internet_connection', true],
)->willReturnOnConsecutiveCalls(
true,
true,
);
->willReturnMap([
['gs.enabled', false, true],
['has_internet_connection', true, true],
]);
$this->config->expects($this->once())
->method('getSystemValueString')
@ -206,13 +197,10 @@ class LookupPluginTest extends TestCase {
$this->config->expects($this->exactly(2))
->method('getSystemValueBool')
->withConsecutive(
['gs.enabled', false],
['has_internet_connection', true],
)->willReturnOnConsecutiveCalls(
$GSEnabled,
true,
);
->willReturnMap([
['gs.enabled', false, $GSEnabled],
['has_internet_connection', true, true],
]);
$this->config->expects($this->once())
->method('getSystemValueString')
->with('lookup_server', 'https://lookup.nextcloud.com')
@ -239,13 +227,10 @@ class LookupPluginTest extends TestCase {
$searchResult->expects($this->never())->method('addResultSet');
$this->config->expects($this->exactly(2))
->method('getSystemValueBool')
->withConsecutive(
['gs.enabled', false],
['has_internet_connection', true],
)->willReturnOnConsecutiveCalls(
$GSEnabled,
true,
);
->willReturnMap([
['gs.enabled', false, $GSEnabled],
['has_internet_connection', true, true],
]);
}
$moreResults = $this->plugin->search(
$searchParams['search'],
@ -276,7 +261,7 @@ class LookupPluginTest extends TestCase {
$this->assertFalse($this->plugin->search('irr', 10, 0, $searchResult));
}
public function dataSearchEnableDisableLookupServer() {
public static function dataSearchEnableDisableLookupServer(): array {
$fedIDs = [
'foo@enceladus.moon',
'foobar@enceladus.moon',
@ -449,7 +434,7 @@ class LookupPluginTest extends TestCase {
];
}
public function searchDataProvider() {
public static function searchDataProvider(): array {
$fedIDs = [
'foo@enceladus.moon',
'foobar@enceladus.moon',

@ -255,29 +255,27 @@ class ContactsStoreTest extends TestCase {
$user2 = $this->createMock(IUser::class);
$user3 = $this->createMock(IUser::class);
$calls = [
[[$currentUser], ['group1', 'group2', 'group3']],
[[$user1], ['group1']],
[[$user2], ['group2', 'group3']],
[[$user3], ['group8', 'group9']],
];
$this->groupManager->expects($this->exactly(4))
->method('getUserGroupIds')
->withConsecutive(
[$this->equalTo($currentUser)],
[$this->equalTo($user1)],
[$this->equalTo($user2)],
[$this->equalTo($user3)]
)
->willReturnOnConsecutiveCalls(
['group1', 'group2', 'group3'],
['group1'],
['group2', 'group3'],
['group8', 'group9']
);
->willReturnCallback(function () use (&$calls): array {
$expected = array_shift($calls);
$this->assertEquals($expected[0], func_get_args());
return $expected[1];
});
$this->userManager->expects($this->exactly(3))
->method('get')
->withConsecutive(
['user1'],
['user2'],
['user3']
)
->willReturnOnConsecutiveCalls($user1, $user2, $user3);
->willReturnMap([
['user1', $user1],
['user2', $user2],
['user3', $user3],
]);
$this->contactsManager->expects($this->once())
->method('search')
@ -330,29 +328,27 @@ class ContactsStoreTest extends TestCase {
$user2 = $this->createMock(IUser::class);
$user3 = $this->createMock(IUser::class);
$calls = [
[[$currentUser], ['group1', 'group2', 'group3']],
[[$user1], ['group1']],
[[$user2], ['group2', 'group3']],
[[$user3], ['group8', 'group9']],
];
$this->groupManager->expects($this->exactly(4))
->method('getUserGroupIds')
->withConsecutive(
[$this->equalTo($currentUser)],
[$this->equalTo($user1)],
[$this->equalTo($user2)],
[$this->equalTo($user3)]
)
->willReturnOnConsecutiveCalls(
['group1', 'group2', 'group3'],
['group1'],
['group2', 'group3'],
['group8', 'group9']
);
->willReturnCallback(function () use (&$calls): array {
$expected = array_shift($calls);
$this->assertEquals($expected[0], func_get_args());
return $expected[1];
});
$this->userManager->expects($this->exactly(3))
->method('get')
->withConsecutive(
['user1'],
['user2'],
['user3']
)
->willReturn($user1, $user2, $user3);
->willReturnMap([
['user1', $user1],
['user2', $user2],
['user3', $user3],
]);
$this->contactsManager->expects($this->once())
->method('search')
@ -463,29 +459,27 @@ class ContactsStoreTest extends TestCase {
$user2 = $this->createMock(IUser::class);
$user3 = $this->createMock(IUser::class);
$calls = [
[[$currentUser], ['group1', 'group2', 'group3']],
[[$user1], ['group1']],
[[$user2], ['group2', 'group3']],
[[$user3], ['group8', 'group9']],
];
$this->groupManager->expects($this->exactly(4))
->method('getUserGroupIds')
->withConsecutive(
[$this->equalTo($currentUser)],
[$this->equalTo($user1)],
[$this->equalTo($user2)],
[$this->equalTo($user3)]
)
->willReturnOnConsecutiveCalls(
['group1', 'group2', 'group3'],
['group1'],
['group2', 'group3'],
['group8', 'group9']
);
->willReturnCallback(function () use (&$calls): array {
$expected = array_shift($calls);
$this->assertEquals($expected[0], func_get_args());
return $expected[1];
});
$this->userManager->expects($this->exactly(3))
->method('get')
->withConsecutive(
['user1'],
['user2'],
['user3']
)
->willReturnOnConsecutiveCalls($user1, $user2, $user3);
->willReturnMap([
['user1', $user1],
['user2', $user2],
['user3', $user3],
]);
$this->knownUserService->method('isKnownToUser')
->willReturnMap([
@ -542,16 +536,17 @@ class ContactsStoreTest extends TestCase {
$user1 = $this->createMock(IUser::class);
$calls = [
[[$currentUser], ['group1', 'group2', 'group3']],
[[$user1], ['group1']],
];
$this->groupManager->expects($this->exactly(2))
->method('getUserGroupIds')
->withConsecutive(
[$this->equalTo($currentUser)],
[$this->equalTo($user1)]
)
->willReturnOnConsecutiveCalls(
['group1', 'group2', 'group3'],
['group1']
);
->willReturnCallback(function () use (&$calls): array {
$expected = array_shift($calls);
$this->assertEquals($expected[0], func_get_args());
return $expected[1];
});
$this->userManager->expects($this->once())
->method('get')
@ -617,29 +612,27 @@ class ContactsStoreTest extends TestCase {
$user2 = $this->createMock(IUser::class);
$user3 = $this->createMock(IUser::class);
$calls = [
[[$currentUser], ['group1', 'group2', 'group3']],
[[$user1], ['group1']],
[[$user2], ['group2', 'group3']],
[[$user3], ['group8', 'group9']],
];
$this->groupManager->expects($this->exactly(4))
->method('getUserGroupIds')
->withConsecutive(
[$this->equalTo($currentUser)],
[$this->equalTo($user1)],
[$this->equalTo($user2)],
[$this->equalTo($user3)]
)
->willReturnOnConsecutiveCalls(
['group1', 'group2', 'group3'],
['group1'],
['group2', 'group3'],
['group8', 'group9']
);
->willReturnCallback(function () use (&$calls): array {
$expected = array_shift($calls);
$this->assertEquals($expected[0], func_get_args());
return $expected[1];
});
$this->userManager->expects($this->exactly(3))
->method('get')
->withConsecutive(
['user1'],
['user2'],
['user3']
)
->willReturnOnConsecutiveCalls($user1, $user2, $user3);
->willReturnMap([
['user1', $user1],
['user2', $user2],
['user3', $user3],
]);
$this->knownUserService->method('isKnownToUser')
->willReturnMap([

@ -65,11 +65,10 @@ class ManagerTest extends TestCase {
$this->config->expects($this->exactly(2))
->method('getSystemValueInt')
->withConsecutive(
['sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT],
['sharing.minSearchStringLength', 0]
)
->willReturnOnConsecutiveCalls(25, 0);
->willReturnMap([
['sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT, 25],
['sharing.minSearchStringLength', 0, 0],
]);
$this->contactsStore->expects($this->once())
->method('getContacts')
->with($user, $filter)
@ -102,11 +101,10 @@ class ManagerTest extends TestCase {
$this->config->expects($this->exactly(2))
->method('getSystemValueInt')
->withConsecutive(
['sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT],
['sharing.minSearchStringLength', 0]
)
->willReturnOnConsecutiveCalls(3, 0);
->willReturnMap([
['sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT, 3],
['sharing.minSearchStringLength', 0, 0],
]);
$this->contactsStore->expects($this->once())
->method('getContacts')
->with($user, $filter)
@ -138,11 +136,10 @@ class ManagerTest extends TestCase {
$this->config->expects($this->exactly(2))
->method('getSystemValueInt')
->withConsecutive(
['sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT],
['sharing.minSearchStringLength', 0]
)
->willReturnOnConsecutiveCalls(3, 4);
->willReturnMap([
['sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT, 3],
['sharing.minSearchStringLength', 0, 4],
]);
$this->appManager->expects($this->once())
->method('isEnabledForUser')
->with($this->equalTo('contacts'), $user)

@ -173,8 +173,10 @@ class ManagerTest extends TestCase {
$folder = $this->createMock(Folder::class);
$this->userFolder
->method('nodeExists')
->withConsecutive(['/File.txt'], ['/'])
->willReturnOnConsecutiveCalls(false, true);
->willReturnMap([
['/File.txt', false],
['/', true],
]);
$this->userFolder
->method('get')
->with('/')
@ -198,8 +200,10 @@ class ManagerTest extends TestCase {
$folder = $this->createMock(Folder::class);
$this->userFolder
->method('nodeExists')
->withConsecutive(['/File.txt'], ['/'])
->willReturnOnConsecutiveCalls(false, true);
->willReturnMap([
['/File.txt', false],
['/', true],
]);
$this->userFolder
->method('get')
->with('/')
@ -226,11 +230,12 @@ class ManagerTest extends TestCase {
$this->random->expects($this->once())
->method('generate')
->willReturn($expectedToken);
$folder = $this->createMock(Folder::class);
$this->userFolder
->method('nodeExists')
->withConsecutive(['/File.txt'], ['/'])
->willReturnOnConsecutiveCalls(false, true);
->willReturnMap([
['/File.txt', false],
['/', true],
]);
$this->userFolder
->method('get')
->with('/File.txt')
@ -277,8 +282,10 @@ class ManagerTest extends TestCase {
]);
$this->userFolder
->method('nodeExists')
->withConsecutive(['/File.txt'], ['/'])
->willReturnOnConsecutiveCalls(false, true);
->willReturnMap([
['/File.txt', false],
['/', true],
]);
$this->userFolder
->method('get')
->with('/')

@ -82,7 +82,7 @@ class DecryptAllTest extends TestCase {
$this->invokePrivate($this->instance, 'output', [$this->outputInterface]);
}
public function dataDecryptAll() {
public static function dataDecryptAll(): array {
return [
[true, 'user1', true],
[false, 'user1', true],
@ -113,7 +113,7 @@ class DecryptAllTest extends TestCase {
$this->view
]
)
->setMethods(['prepareEncryptionModules', 'decryptAllUsersFiles'])
->onlyMethods(['prepareEncryptionModules', 'decryptAllUsersFiles'])
->getMock();
$instance->expects($this->once())
@ -145,7 +145,7 @@ class DecryptAllTest extends TestCase {
);
}
public function dataTrueFalse() {
public static function dataTrueFalse(): array {
return [
[true],
[false],
@ -198,7 +198,7 @@ class DecryptAllTest extends TestCase {
$this->view
]
)
->setMethods(['decryptUsersFiles'])
->onlyMethods(['decryptUsersFiles'])
->getMock();
$this->invokePrivate($instance, 'input', [$this->inputInterface]);
@ -211,12 +211,16 @@ class DecryptAllTest extends TestCase {
$this->userInterface->expects($this->any())
->method('getUsers')
->willReturn(['user1', 'user2']);
$calls = [
'user1',
'user2',
];
$instance->expects($this->exactly(2))
->method('decryptUsersFiles')
->withConsecutive(
['user1'],
['user2'],
);
->willReturnCallback(function ($user) use (&$calls) {
$expected = array_shift($calls);
$this->assertEquals($expected, $user);
});
} else {
$instance->expects($this->once())
->method('decryptUsersFiles')
@ -226,7 +230,7 @@ class DecryptAllTest extends TestCase {
$this->invokePrivate($instance, 'decryptAllUsersFiles', [$user]);
}
public function dataTestDecryptAllUsersFiles() {
public static function dataTestDecryptAllUsersFiles(): array {
return [
['user1'],
['']
@ -243,7 +247,7 @@ class DecryptAllTest extends TestCase {
$this->view
]
)
->setMethods(['decryptFile'])
->onlyMethods(['decryptFile'])
->getMock();
$storage = $this->getMockBuilder(IStorage::class)
@ -253,25 +257,29 @@ class DecryptAllTest extends TestCase {
$sharedStorage = $this->getMockBuilder(IStorage::class)
->disableOriginalConstructor()->getMock();
$sharedStorage->expects($this->once())->method('instanceOfStorage')
->with('OCA\Files_Sharing\SharedStorage')->willReturn(true);
$sharedStorage->expects($this->once())
->method('instanceOfStorage')
->with('OCA\Files_Sharing\SharedStorage')
->willReturn(true);
$this->view->expects($this->exactly(2))
->method('getDirectoryContent')
->withConsecutive(
['/user1/files'],
['/user1/files/foo']
)
->willReturnOnConsecutiveCalls(
->willReturnMap([
[
new FileInfo('path', $storage, 'intPath', ['name' => 'foo', 'type' => 'dir'], null),
new FileInfo('path', $storage, 'intPath', ['name' => 'bar', 'type' => 'file', 'encrypted' => true], null),
new FileInfo('path', $sharedStorage, 'intPath', ['name' => 'shared', 'type' => 'file', 'encrypted' => true], null),
'/user1/files', '', null,
[
new FileInfo('path', $storage, 'intPath', ['name' => 'foo', 'type' => 'dir'], null),
new FileInfo('path', $storage, 'intPath', ['name' => 'bar', 'type' => 'file', 'encrypted' => true], null),
new FileInfo('path', $sharedStorage, 'intPath', ['name' => 'shared', 'type' => 'file', 'encrypted' => true], null),
],
],
[
new FileInfo('path', $storage, 'intPath', ['name' => 'subfile', 'type' => 'file', 'encrypted' => true], null)
]
);
'/user1/files/foo', '', null,
[
new FileInfo('path', $storage, 'intPath', ['name' => 'subfile', 'type' => 'file', 'encrypted' => true], null)
],
],
]);
$this->view->expects($this->any())->method('is_dir')
->willReturnCallback(
@ -283,12 +291,16 @@ class DecryptAllTest extends TestCase {
}
);
$calls = [
'/user1/files/bar',
'/user1/files/foo/subfile',
];
$instance->expects($this->exactly(2))
->method('decryptFile')
->withConsecutive(
['/user1/files/bar'],
['/user1/files/foo/subfile'],
);
->willReturnCallback(function ($path) use (&$calls) {
$expected = array_shift($calls);
$this->assertEquals($expected, $path);
});
/* We need format method to return a string */
@ -320,7 +332,7 @@ class DecryptAllTest extends TestCase {
$this->view
]
)
->setMethods(['getTimestamp'])
->onlyMethods(['getTimestamp'])
->getMock();
$fileInfo = $this->createMock(FileInfo::class);
@ -360,7 +372,7 @@ class DecryptAllTest extends TestCase {
$this->view
]
)
->setMethods(['getTimestamp'])
->onlyMethods(['getTimestamp'])
->getMock();

@ -9,6 +9,7 @@
namespace Test\Encryption\Keys;
use OC\Encryption\Keys\Storage;
use OC\Encryption\Util;
use OC\Files\View;
use OCP\IConfig;
use OCP\Security\ICrypto;
@ -36,9 +37,9 @@ class StorageTest extends TestCase {
protected function setUp(): void {
parent::setUp();
$this->util = $this->getMockBuilder('OC\Encryption\Util')
$this->util = $this->getMockBuilder(Util::class)
->disableOriginalConstructor()
->setMethodsExcept(['getFileKeyDir'])
->onlyMethods(array_diff(get_class_methods(Util::class), ['getFileKeyDir']))
->getMock();
$this->view = $this->getMockBuilder(View::class)
@ -114,7 +115,7 @@ class StorageTest extends TestCase {
);
}
public function dataTestGetFileKey() {
public static function dataTestGetFileKey() {
return [
['/files/foo.txt', '/files/foo.txt', true, 'key'],
['/files/foo.txt.ocTransferId2111130212.part', '/files/foo.txt', true, 'key'],
@ -157,13 +158,10 @@ class StorageTest extends TestCase {
if (!$originalKeyExists) {
$this->view->expects($this->exactly(2))
->method('file_exists')
->withConsecutive(
[$this->equalTo('/user1/files_encryption/keys' . $strippedPartialName . '/encModule/fileKey')],
[$this->equalTo('/user1/files_encryption/keys' . $path . '/encModule/fileKey')],
)->willReturnOnConsecutiveCalls(
$originalKeyExists,
true,
);
->willReturnMap([
['/user1/files_encryption/keys' . $strippedPartialName . '/encModule/fileKey', $originalKeyExists],
['/user1/files_encryption/keys' . $path . '/encModule/fileKey', true],
]);
$this->view->expects($this->once())
->method('file_get_contents')
@ -481,7 +479,7 @@ class StorageTest extends TestCase {
return [$parts[1], '/' . implode('/', array_slice($parts, 2))];
}
public function dataProviderCopyRename() {
public static function dataProviderCopyRename() {
return [
['/user1/files/source.txt', '/user1/files/target.txt', false, false,
'/user1/files_encryption/keys/files/source.txt/', '/user1/files_encryption/keys/files/target.txt/'],
@ -534,7 +532,7 @@ class StorageTest extends TestCase {
);
}
public function dataTestGetPathToKeys() {
public static function dataTestGetPathToKeys() {
return [
['/user1/files/source.txt', false, '', '/user1/files_encryption/keys/files/source.txt/'],
['/user1/files/source.txt', true, '', '/files_encryption/keys/files/source.txt/'],
@ -577,7 +575,7 @@ class StorageTest extends TestCase {
public function testBackupUserKeys($createBackupDir): void {
$storage = $this->getMockBuilder('OC\Encryption\Keys\Storage')
->setConstructorArgs([$this->view, $this->util, $this->crypto, $this->config])
->setMethods(['getTimestamp'])
->onlyMethods(['getTimestamp'])
->getMock();
$storage->expects($this->any())->method('getTimestamp')->willReturn('1234567');
@ -586,11 +584,15 @@ class StorageTest extends TestCase {
->with('user1/files_encryption/backup')->willReturn(!$createBackupDir);
if ($createBackupDir) {
$calls = [
'user1/files_encryption/backup',
'user1/files_encryption/backup/test.encryptionModule.1234567',
];
$this->view->expects($this->exactly(2))->method('mkdir')
->withConsecutive(
['user1/files_encryption/backup'],
['user1/files_encryption/backup/test.encryptionModule.1234567'],
);
->willReturnCallback(function ($path) use (&$calls) {
$expected = array_shift($calls);
$this->assertEquals($expected, $path);
});
} else {
$this->view->expects($this->once())->method('mkdir')
->with('user1/files_encryption/backup/test.encryptionModule.1234567');
@ -605,7 +607,7 @@ class StorageTest extends TestCase {
$this->assertTrue($storage->backupUserKeys('encryptionModule', 'test', 'user1'));
}
public function dataTestBackupUserKeys() {
public static function dataTestBackupUserKeys() {
return [
[true], [false]
];

@ -205,16 +205,12 @@ class ObjectHomeMountProviderTest extends \Test\TestCase {
public function testMultiBucketConfigFirstFallBackSingle(): void {
$this->config->expects($this->exactly(2))
->method('getSystemValue')
->withConsecutive(
[$this->equalTo('objectstore_multibucket')],
[$this->equalTo('objectstore')],
)->willReturnOnConsecutiveCalls(
'',
[
->method('getSystemValue')->willReturnMap([
['objectstore_multibucket', '', ''],
['objectstore', '', [
'class' => 'Test\Files\Mount\FakeObjectStore',
],
);
]],
]);
$this->user->method('getUID')
->willReturn('uid');

@ -76,12 +76,16 @@ class AvailabilityTest extends \Test\TestCase {
$this->storage->expects($this->once())
->method('test')
->willReturn(true);
$calls = [
false, // prevents concurrent rechecks
true, // sets correct availability
];
$this->storage->expects($this->exactly(2))
->method('setAvailability')
->withConsecutive(
[$this->equalTo(false)], // prevents concurrent rechecks
[$this->equalTo(true)] // sets correct availability
);
->willReturnCallback(function ($value) use (&$calls) {
$expected = array_shift($calls);
$this->assertEquals($expected, $value);
});
$this->storage->expects($this->once())
->method('mkdir');

@ -25,7 +25,7 @@ class DetectionTest extends \Test\TestCase {
);
}
public function dataDetectPath(): array {
public static function dataDetectPath(): array {
return [
['foo.txt', 'text/plain'],
['foo.png', 'image/png'],
@ -54,7 +54,7 @@ class DetectionTest extends \Test\TestCase {
$this->assertEquals($expected, $this->detection->detectPath($path));
}
public function dataDetectContent(): array {
public static function dataDetectContent(): array {
return [
['/', 'httpd/unix-directory'],
['/data.tar.gz', 'application/gzip'],
@ -74,7 +74,7 @@ class DetectionTest extends \Test\TestCase {
$this->assertEquals($expected, $this->detection->detectContent(\OC::$SERVERROOT . '/tests/data' . $path));
}
public function dataDetect(): array {
public static function dataDetect(): array {
return [
['/', 'httpd/unix-directory'],
['/data.tar.gz', 'application/gzip'],
@ -100,7 +100,7 @@ class DetectionTest extends \Test\TestCase {
$this->assertEquals($expected, $result);
}
public function dataMimeTypeCustom(): array {
public static function dataMimeTypeCustom(): array {
return [
['123', 'foobar/123'],
['a123', 'foobar/123'],
@ -135,7 +135,7 @@ class DetectionTest extends \Test\TestCase {
$this->assertEquals($mime, $detection->detectPath('foo.' . $ext));
}
public function dataGetSecureMimeType(): array {
public static function dataGetSecureMimeType(): array {
return [
['image/svg+xml', 'text/plain'],
['image/png', 'image/png'],
@ -255,14 +255,16 @@ class DetectionTest extends \Test\TestCase {
->getMock();
//Only call the url generator once
$calls = [
['core', 'filetypes/my-type.png'],
['core', 'filetypes/my.png'],
];
$urlGenerator->expects($this->exactly(2))
->method('imagePath')
->withConsecutive(
[$this->equalTo('core'), $this->equalTo('filetypes/my-type.png')],
[$this->equalTo('core'), $this->equalTo('filetypes/my.png')]
)
->willReturnCallback(
function ($appName, $file) {
function ($appName, $file) use (&$calls) {
$expected = array_shift($calls);
$this->assertEquals($expected, [$appName, $file]);
if ($file === 'filetypes/my.png') {
return 'my.svg';
}
@ -285,15 +287,17 @@ class DetectionTest extends \Test\TestCase {
->getMock();
//Only call the url generator once
$calls = [
['core', 'filetypes/foo-bar.png'],
['core', 'filetypes/foo.png'],
['core', 'filetypes/file.png'],
];
$urlGenerator->expects($this->exactly(3))
->method('imagePath')
->withConsecutive(
[$this->equalTo('core'), $this->equalTo('filetypes/foo-bar.png')],
[$this->equalTo('core'), $this->equalTo('filetypes/foo.png')],
[$this->equalTo('core'), $this->equalTo('filetypes/file.png')]
)
->willReturnCallback(
function ($appName, $file) {
function ($appName, $file) use (&$calls) {
$expected = array_shift($calls);
$this->assertEquals($expected, [$appName, $file]);
if ($file === 'filetypes/file.png') {
return 'file.svg';
}

@ -64,6 +64,17 @@ class TemporaryNoLocal extends Temporary {
}
}
class TestEventHandler {
public function umount() {
}
public function post_umount() {
}
public function preCallback() {
}
public function postCallback() {
}
}
/**
* Class ViewTest
*
@ -291,7 +302,7 @@ class ViewTest extends \Test\TestCase {
$this->assertCount(4, $folderContent);
}
public function sharingDisabledPermissionProvider() {
public static function sharingDisabledPermissionProvider(): array {
return [
['no', '', true],
['yes', 'group1', false],
@ -543,7 +554,7 @@ class ViewTest extends \Test\TestCase {
$this->assertFalse($rootView->file_exists('substorage/bar.txt'));
}
public function rmdirOrUnlinkDataProvider() {
public static function rmdirOrUnlinkDataProvider(): array {
return [['rmdir'], ['unlink']];
}
@ -775,7 +786,7 @@ class ViewTest extends \Test\TestCase {
$this->assertTrue($exists);
}
public function resolvePathTestProvider() {
public static function resolvePathTestProvider(): array {
return [
['foo.txt', 'foo.txt'],
['foo.txt', '/foo.txt'],
@ -940,7 +951,7 @@ class ViewTest extends \Test\TestCase {
$this->assertEquals(6, $info->getSize());
}
public function absolutePathProvider() {
public static function absolutePathProvider(): array {
return [
['/files/', ''],
['/files/0', '0'],
@ -961,8 +972,8 @@ class ViewTest extends \Test\TestCase {
$this->assertEquals($expectedPath, $view->getRelativePath($absolutePath));
}
public function chrootRelativePathProvider() {
return $this->relativePathProvider('/');
public static function chrootRelativePathProvider(): array {
return self::relativePathProvider('/');
}
/**
@ -973,11 +984,11 @@ class ViewTest extends \Test\TestCase {
$this->assertEquals($expectedPath, $view->getRelativePath($absolutePath));
}
public function initRelativePathProvider() {
return $this->relativePathProvider(null);
public static function initRelativePathProvider(): array {
return self::relativePathProvider(null);
}
public function relativePathProvider($missingRootExpectedPath) {
public static function relativePathProvider($missingRootExpectedPath): array {
return [
// No root - returns the path
['', '/files', '/files'],
@ -1097,7 +1108,7 @@ class ViewTest extends \Test\TestCase {
call_user_func([$rootView, $operation], $longPath, $param0);
}
public function tooLongPathDataProvider() {
public static function tooLongPathDataProvider(): array {
return [
['getAbsolutePath'],
['getRelativePath'],
@ -1180,7 +1191,7 @@ class ViewTest extends \Test\TestCase {
/** @var \PHPUnit\Framework\MockObject\MockObject|Temporary $storage2 */
$storage2 = $this->getMockBuilder(TemporaryNoCross::class)
->setConstructorArgs([[]])
->setMethods(['fopen', 'writeStream'])
->onlyMethods(['fopen', 'writeStream'])
->getMock();
$storage2->method('writeStream')
@ -1226,7 +1237,7 @@ class ViewTest extends \Test\TestCase {
/** @var Temporary|\PHPUnit\Framework\MockObject\MockObject $storage */
$storage = $this->getMockBuilder(Temporary::class)
->setConstructorArgs([[]])
->setMethods(['unlink'])
->onlyMethods(['unlink'])
->getMock();
$storage->expects($this->once())
->method('unlink')
@ -1243,7 +1254,7 @@ class ViewTest extends \Test\TestCase {
$this->assertTrue($cache->inCache('foo.txt'));
}
public function directoryTraversalProvider() {
public static function directoryTraversalProvider(): array {
return [
['../test/'],
['..\\test\\my/../folder'],
@ -1481,7 +1492,7 @@ class ViewTest extends \Test\TestCase {
$lockingProvider->releaseAll();
}
public function dataLockPaths() {
public static function dataLockPaths(): array {
return [
['/testuser/{folder}', ''],
['/testuser', '/{folder}'],
@ -1489,7 +1500,7 @@ class ViewTest extends \Test\TestCase {
];
}
public function pathRelativeToFilesProvider() {
public static function pathRelativeToFilesProvider(): array {
return [
['admin/files', ''],
['admin/files/x', 'x'],
@ -1509,7 +1520,7 @@ class ViewTest extends \Test\TestCase {
$this->assertEquals($expectedPath, $view->getPathRelativeToFiles($path));
}
public function pathRelativeToFilesProviderExceptionCases() {
public static function pathRelativeToFilesProviderExceptionCases(): array {
return [
[''],
['x'],
@ -1552,7 +1563,7 @@ class ViewTest extends \Test\TestCase {
$this->assertFalse($this->isFileLocked($view, '/test//sub', ILockingProvider::LOCK_EXCLUSIVE));
}
public function hookPathProvider() {
public static function hookPathProvider(): array {
return [
['/foo/files', '/foo', true],
['/foo/files/bar', '/foo', true],
@ -1593,7 +1604,7 @@ class ViewTest extends \Test\TestCase {
$mounts = [];
foreach ($mountPoints as $mountPoint) {
$storage = $this->getMockBuilder(Storage::class)
->setMethods([])
->onlyMethods([])
->getMock();
$storage->method('getId')->willReturn('non-null-id');
$storage->method('getStorageCache')->willReturnCallback(function () use ($storage) {
@ -1601,7 +1612,7 @@ class ViewTest extends \Test\TestCase {
});
$mounts[] = $this->getMockBuilder(TestMoveableMountPoint::class)
->setMethods(['moveMount'])
->onlyMethods(['moveMount'])
->setConstructorArgs([$storage, $mountPoint])
->getMock();
}
@ -1746,7 +1757,7 @@ class ViewTest extends \Test\TestCase {
$userObject->delete();
}
public function basicOperationProviderForLocks() {
public static function basicOperationProviderForLocks(): array {
return [
// --- write hook ----
[
@ -1931,7 +1942,7 @@ class ViewTest extends \Test\TestCase {
/** @var Temporary&MockObject $storage */
$storage = $this->getMockBuilder(Temporary::class)
->setMethods([$operation])
->onlyMethods([$operation])
->getMock();
/* Pause trash to avoid the trashbin intercepting rmdir and unlink calls */
@ -1987,7 +1998,7 @@ class ViewTest extends \Test\TestCase {
$path = 'test_file_put_contents.txt';
/** @var Temporary|\PHPUnit\Framework\MockObject\MockObject $storage */
$storage = $this->getMockBuilder(Temporary::class)
->setMethods(['fopen'])
->onlyMethods(['fopen'])
->getMock();
Filesystem::mount($storage, [], $this->user . '/');
@ -2026,7 +2037,7 @@ class ViewTest extends \Test\TestCase {
$path = 'test_file_put_contents.txt';
/** @var Temporary|\PHPUnit\Framework\MockObject\MockObject $storage */
$storage = $this->getMockBuilder(Temporary::class)
->setMethods(['fopen'])
->onlyMethods(['fopen'])
->getMock();
Filesystem::mount($storage, [], $this->user . '/');
@ -2081,7 +2092,7 @@ class ViewTest extends \Test\TestCase {
/** @var Temporary|\PHPUnit\Framework\MockObject\MockObject $storage */
$storage = $this->getMockBuilder(Temporary::class)
->setMethods([$operation])
->onlyMethods([$operation])
->getMock();
/* Pause trash to avoid the trashbin intercepting rmdir and unlink calls */
@ -2169,7 +2180,7 @@ class ViewTest extends \Test\TestCase {
/** @var Temporary|\PHPUnit\Framework\MockObject\MockObject $storage */
$storage = $this->getMockBuilder(Temporary::class)
->setMethods([$operation])
->onlyMethods([$operation])
->getMock();
Filesystem::mount($storage, [], $this->user . '/');
@ -2187,7 +2198,7 @@ class ViewTest extends \Test\TestCase {
$this->assertNull($this->getFileLockType($view, $path), 'File got unlocked after exception');
}
public function lockFileRenameOrCopyDataProvider() {
public static function lockFileRenameOrCopyDataProvider(): array {
return [
['rename', ILockingProvider::LOCK_EXCLUSIVE],
['copy', ILockingProvider::LOCK_SHARED],
@ -2208,7 +2219,7 @@ class ViewTest extends \Test\TestCase {
/** @var Temporary|\PHPUnit\Framework\MockObject\MockObject $storage */
$storage = $this->getMockBuilder(Temporary::class)
->setMethods([$operation, 'getMetaData', 'filemtime'])
->onlyMethods([$operation, 'getMetaData', 'filemtime'])
->getMock();
$storage->expects($this->any())
@ -2274,7 +2285,7 @@ class ViewTest extends \Test\TestCase {
/** @var Temporary|\PHPUnit\Framework\MockObject\MockObject $storage */
$storage = $this->getMockBuilder(Temporary::class)
->setMethods(['copy'])
->onlyMethods(['copy'])
->getMock();
$sourcePath = 'original.txt';
@ -2371,7 +2382,7 @@ class ViewTest extends \Test\TestCase {
$this->assertEquals('test', $folderInfo[0]->getOwner()->getUID());
}
public function lockFileRenameOrCopyCrossStorageDataProvider() {
public static function lockFileRenameOrCopyCrossStorageDataProvider(): array {
return [
['rename', 'moveFromStorage', ILockingProvider::LOCK_EXCLUSIVE],
['copy', 'copyFromStorage', ILockingProvider::LOCK_SHARED],
@ -2393,11 +2404,11 @@ class ViewTest extends \Test\TestCase {
/** @var Temporary|\PHPUnit\Framework\MockObject\MockObject $storage */
$storage = $this->getMockBuilder(Temporary::class)
->setMethods([$storageOperation])
->onlyMethods([$storageOperation])
->getMock();
/** @var Temporary|\PHPUnit\Framework\MockObject\MockObject $storage2 */
$storage2 = $this->getMockBuilder(Temporary::class)
->setMethods([$storageOperation, 'getMetaData', 'filemtime'])
->onlyMethods([$storageOperation, 'getMetaData', 'filemtime'])
->getMock();
$storage2->expects($this->any())
@ -2532,8 +2543,8 @@ class ViewTest extends \Test\TestCase {
return;
}
$eventHandler = $this->getMockBuilder(\stdclass::class)
->setMethods(['preCallback', 'postCallback'])
$eventHandler = $this->getMockBuilder(TestEventHandler::class)
->onlyMethods(['preCallback', 'postCallback'])
->getMock();
$eventHandler->expects($this->any())
@ -2607,8 +2618,8 @@ class ViewTest extends \Test\TestCase {
Filesystem::getMountManager()->addMount($mount);
// Listen for events
$eventHandler = $this->getMockBuilder(\stdclass::class)
->setMethods(['umount', 'post_umount'])
$eventHandler = $this->getMockBuilder(TestEventHandler::class)
->onlyMethods(['umount', 'post_umount'])
->getMock();
$eventHandler->expects($this->once())
->method('umount')
@ -2634,7 +2645,7 @@ class ViewTest extends \Test\TestCase {
$this->assertEquals('foo', $view->rmdir('mount'));
}
public function mimeFilterProvider() {
public static function mimeFilterProvider(): array {
return [
[null, ['test1.txt', 'test2.txt', 'test3.md', 'test4.png']],
['text/plain', ['test1.txt', 'test2.txt']],
@ -2742,7 +2753,7 @@ class ViewTest extends \Test\TestCase {
public function testCreateParentDirectories(): void {
$view = $this->getMockBuilder(View::class)
->disableOriginalConstructor()
->setMethods([
->onlyMethods([
'is_file',
'file_exists',
'mkdir',
@ -2751,29 +2762,26 @@ class ViewTest extends \Test\TestCase {
$view->expects($this->exactly(3))
->method('is_file')
->withConsecutive(
['/new'],
['/new/folder'],
['/new/folder/structure'],
)
->willReturn(false);
->willReturnMap([
['/new', false],
['/new/folder', false],
['/new/folder/structure', false],
]);
$view->expects($this->exactly(3))
->method('file_exists')
->withConsecutive(
['/new'],
['/new/folder'],
['/new/folder/structure'],
)->willReturnOnConsecutiveCalls(
true,
false,
false,
);
->willReturnMap([
['/new', true],
['/new/folder', false],
['/new/folder/structure', false],
]);
$calls = ['/new/folder', '/new/folder/structure'];
$view->expects($this->exactly(2))
->method('mkdir')
->withConsecutive(
['/new/folder'],
['/new/folder/structure'],
);
->willReturnCallback(function ($dir) use (&$calls) {
$expected = array_shift($calls);
$this->assertEquals($expected, $dir);
});
$this->assertTrue(self::invokePrivate($view, 'createParentDirectories', ['/new/folder/structure']));
}
@ -2781,7 +2789,7 @@ class ViewTest extends \Test\TestCase {
public function testCreateParentDirectoriesWithExistingFile(): void {
$view = $this->getMockBuilder(View::class)
->disableOriginalConstructor()
->setMethods([
->onlyMethods([
'is_file',
'file_exists',
'mkdir',

@ -92,14 +92,10 @@ class ClientTest extends \Test\TestCase {
$this->config
->expects($this->exactly(2))
->method('getSystemValueString')
->withConsecutive(
['proxy', ''],
['proxyuserpwd', ''],
)
->willReturnOnConsecutiveCalls(
'foo',
'username:password',
);
->willReturnMap([
['proxy', '', 'foo'],
['proxyuserpwd', '', 'username:password'],
]);
$this->assertEquals([
'http' => 'username:password@foo',
'https' => 'username:password@foo'
@ -115,14 +111,10 @@ class ClientTest extends \Test\TestCase {
$this->config
->expects($this->exactly(2))
->method('getSystemValueString')
->withConsecutive(
['proxy', ''],
['proxyuserpwd', ''],
)
->willReturnOnConsecutiveCalls(
'foo',
'username:password',
);
->willReturnMap([
['proxy', '', 'foo'],
['proxyuserpwd', '', 'username:password'],
]);
$this->assertEquals([
'http' => 'username:password@foo',
'https' => 'username:password@foo',
@ -137,7 +129,7 @@ class ClientTest extends \Test\TestCase {
self::invokePrivate($this->client, 'preventLocalAddress', ['!@#$', []]);
}
public function dataPreventLocalAddress():array {
public static function dataPreventLocalAddress(): array {
return [
['https://localhost/foo.bar'],
['https://localHost/foo.bar'],
@ -461,14 +453,10 @@ class ClientTest extends \Test\TestCase {
$this->config
->expects($this->exactly(2))
->method('getSystemValueBool')
->withConsecutive(
['installed', false],
['allow_local_remote_servers', false],
)
->willReturnOnConsecutiveCalls(
false,
false,
);
->willReturnMap([
['installed', false, false],
['allow_local_remote_servers', false, false],
]);
$this->config
->expects($this->once())
->method('getSystemValueString')
@ -503,14 +491,10 @@ class ClientTest extends \Test\TestCase {
$this->config
->expects($this->exactly(2))
->method('getSystemValueBool')
->withConsecutive(
['installed', false],
['allow_local_remote_servers', false],
)
->willReturnOnConsecutiveCalls(
true,
false,
);
->willReturnMap([
['installed', false, true],
['allow_local_remote_servers', false, false],
]);
$this->config
->expects($this->once())
->method('getSystemValue')
@ -519,14 +503,10 @@ class ClientTest extends \Test\TestCase {
$this->config
->expects($this->exactly(2))
->method('getSystemValueString')
->withConsecutive(
['proxy', ''],
['proxyuserpwd', ''],
)
->willReturnOnConsecutiveCalls(
'foo',
'',
);
->willReturnMap([
['proxy', '', 'foo'],
['proxyuserpwd', '', ''],
]);
$this->certificateManager
->expects($this->once())
->method('getAbsoluteBundlePath')
@ -562,14 +542,10 @@ class ClientTest extends \Test\TestCase {
$this->config
->expects($this->exactly(2))
->method('getSystemValueBool')
->withConsecutive(
['installed', false],
['allow_local_remote_servers', false],
)
->willReturnOnConsecutiveCalls(
true,
false,
);
->willReturnMap([
['installed', false, true],
['allow_local_remote_servers', false, false],
]);
$this->config
->expects($this->once())
->method('getSystemValue')
@ -578,14 +554,10 @@ class ClientTest extends \Test\TestCase {
$this->config
->expects($this->exactly(2))
->method('getSystemValueString')
->withConsecutive(
['proxy', ''],
['proxyuserpwd', ''],
)
->willReturnOnConsecutiveCalls(
'foo',
'',
);
->willReturnMap([
['proxy', '', 'foo'],
['proxyuserpwd', '', ''],
]);
$this->certificateManager
->expects($this->once())
->method('getAbsoluteBundlePath')

@ -200,14 +200,10 @@ class CheckerTest extends TestCase {
$this->fileAccessHelper
->expects($this->exactly(2))
->method('file_get_contents')
->withConsecutive(
[\OC::$SERVERROOT . '/tests/data/integritycheck/app//appinfo/signature.json'],
['/resources/codesigning/root.crt'],
)
->willReturnOnConsecutiveCalls(
$signatureDataFile,
file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')
);
->willReturnMap([
[\OC::$SERVERROOT . '/tests/data/integritycheck/app//appinfo/signature.json', $signatureDataFile],
['/resources/codesigning/root.crt', file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')],
]);
$this->assertSame([], $this->checker->verifyAppSignature('SomeApp'));
}
@ -239,14 +235,10 @@ class CheckerTest extends TestCase {
$this->fileAccessHelper
->expects($this->exactly(2))
->method('file_get_contents')
->withConsecutive(
[\OC::$SERVERROOT . '/tests/data/integritycheck/app//appinfo/signature.json'],
['/resources/codesigning/root.crt'],
)
->willReturnOnConsecutiveCalls(
$signatureDataFile,
file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')
);
->willReturnMap([
[\OC::$SERVERROOT . '/tests/data/integritycheck/app//appinfo/signature.json', $signatureDataFile],
['/resources/codesigning/root.crt', file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')],
]);
$expected = [
'EXCEPTION' => [
@ -284,14 +276,10 @@ class CheckerTest extends TestCase {
$this->fileAccessHelper
->expects($this->exactly(2))
->method('file_get_contents')
->withConsecutive(
[\OC::$SERVERROOT . '/tests/data/integritycheck/appWithInvalidData//appinfo/signature.json'],
['/resources/codesigning/root.crt'],
)
->willReturnOnConsecutiveCalls(
$signatureDataFile,
file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')
);
->willReturnMap([
[\OC::$SERVERROOT . '/tests/data/integritycheck/appWithInvalidData//appinfo/signature.json', $signatureDataFile],
['/resources/codesigning/root.crt', file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')],
]);
$expected = [
@ -344,15 +332,10 @@ class CheckerTest extends TestCase {
$this->fileAccessHelper
->expects($this->exactly(2))
->method('file_get_contents')
->withConsecutive(
[\OC::$SERVERROOT . '/tests/data/integritycheck/appWithInvalidData//appinfo/signature.json'],
['/resources/codesigning/root.crt'],
)
->willReturnOnConsecutiveCalls(
$signatureDataFile,
file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')
);
->willReturnMap([
[\OC::$SERVERROOT . '/tests/data/integritycheck/appWithInvalidData//appinfo/signature.json', $signatureDataFile],
['/resources/codesigning/root.crt', file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')],
]);
$expected = [
'INVALID_HASH' => [
@ -405,13 +388,10 @@ class CheckerTest extends TestCase {
$this->fileAccessHelper
->expects($this->exactly(2))
->method('file_get_contents')
->withConsecutive(
[\OC::$SERVERROOT . '/tests/data/integritycheck/appWithInvalidData//appinfo/signature.json'],
['/resources/codesigning/root.crt'],
)->willReturnOnConsecutiveCalls(
$signatureDataFile,
file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')
);
->willReturnMap([
[\OC::$SERVERROOT . '/tests/data/integritycheck/appWithInvalidData//appinfo/signature.json', $signatureDataFile],
['/resources/codesigning/root.crt', file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')],
]);
$expected = [
'EXCEPTION' => [
@ -449,13 +429,10 @@ class CheckerTest extends TestCase {
$this->fileAccessHelper
->expects($this->exactly(2))
->method('file_get_contents')
->withConsecutive(
[\OC::$SERVERROOT . '/tests/data/integritycheck/app//appinfo/signature.json'],
['/resources/codesigning/root.crt'],
)->willReturnOnConsecutiveCalls(
$signatureDataFile,
file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')
);
->willReturnMap([
[\OC::$SERVERROOT . '/tests/data/integritycheck/app//appinfo/signature.json', $signatureDataFile],
['/resources/codesigning/root.crt', file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')],
]);
$this->assertSame([], $this->checker->verifyAppSignature('SomeApp'));
}
@ -689,13 +666,10 @@ class CheckerTest extends TestCase {
$this->fileAccessHelper
->expects($this->exactly(2))
->method('file_get_contents')
->withConsecutive(
[\OC::$SERVERROOT . '/tests/data/integritycheck/app//core/signature.json'],
[\OC::$SERVERROOT . '/tests/data/integritycheck/app//resources/codesigning/root.crt'],
)->willReturnOnConsecutiveCalls(
$signatureDataFile,
file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')
);
->willReturnMap([
[\OC::$SERVERROOT . '/tests/data/integritycheck/app//core/signature.json', $signatureDataFile],
[\OC::$SERVERROOT . '/tests/data/integritycheck/app//resources/codesigning/root.crt', file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')],
]);
$this->assertSame([], $this->checker->verifyCoreSignature());
}
@ -726,14 +700,10 @@ class CheckerTest extends TestCase {
$this->fileAccessHelper
->expects($this->exactly(2))
->method('file_get_contents')
->withConsecutive(
[\OC::$SERVERROOT . '/tests/data/integritycheck/htaccessWithValidModifiedContent/core/signature.json'],
[\OC::$SERVERROOT . '/tests/data/integritycheck/htaccessWithValidModifiedContent/resources/codesigning/root.crt'],
)
->willReturnOnConsecutiveCalls(
$signatureDataFile,
file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')
);
->willReturnMap([
[\OC::$SERVERROOT . '/tests/data/integritycheck/htaccessWithValidModifiedContent/core/signature.json', $signatureDataFile],
[\OC::$SERVERROOT . '/tests/data/integritycheck/htaccessWithValidModifiedContent/resources/codesigning/root.crt', file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')],
]);
$this->assertSame([], $this->checker->verifyCoreSignature());
}
@ -816,13 +786,10 @@ class CheckerTest extends TestCase {
$this->fileAccessHelper
->expects($this->exactly(2))
->method('file_get_contents')
->withConsecutive(
[\OC::$SERVERROOT . '/tests/data/integritycheck/app//core/signature.json'],
[\OC::$SERVERROOT . '/tests/data/integritycheck/app//resources/codesigning/root.crt'],
)->willReturnOnConsecutiveCalls(
$signatureDataFile,
file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')
);
->willReturnMap([
[\OC::$SERVERROOT . '/tests/data/integritycheck/app//core/signature.json', $signatureDataFile],
[\OC::$SERVERROOT . '/tests/data/integritycheck/app//resources/codesigning/root.crt', file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')],
]);
$this->assertSame([], $this->checker->verifyCoreSignature());
}
@ -853,13 +820,10 @@ class CheckerTest extends TestCase {
$this->fileAccessHelper
->expects($this->exactly(2))
->method('file_get_contents')
->withConsecutive(
[\OC::$SERVERROOT . '/tests/data/integritycheck/appWithInvalidData//core/signature.json'],
[\OC::$SERVERROOT . '/tests/data/integritycheck/appWithInvalidData//resources/codesigning/root.crt'],
)->willReturnOnConsecutiveCalls(
$signatureDataFile,
file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')
);
->willReturnMap([
[\OC::$SERVERROOT . '/tests/data/integritycheck/appWithInvalidData//core/signature.json', $signatureDataFile],
[\OC::$SERVERROOT . '/tests/data/integritycheck/appWithInvalidData//resources/codesigning/root.crt', file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')],
]);
$expected = [
'EXCEPTION' => [
@ -896,13 +860,10 @@ class CheckerTest extends TestCase {
$this->fileAccessHelper
->expects($this->exactly(2))
->method('file_get_contents')
->withConsecutive(
[\OC::$SERVERROOT . '/tests/data/integritycheck/appWithInvalidData//core/signature.json'],
[\OC::$SERVERROOT . '/tests/data/integritycheck/appWithInvalidData//resources/codesigning/root.crt'],
)->willReturnOnConsecutiveCalls(
$signatureDataFile,
file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')
);
->willReturnMap([
[\OC::$SERVERROOT . '/tests/data/integritycheck/appWithInvalidData//core/signature.json', $signatureDataFile],
[\OC::$SERVERROOT . '/tests/data/integritycheck/appWithInvalidData//resources/codesigning/root.crt', file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')],
]);
$expected = [
'INVALID_HASH' => [
@ -954,13 +915,10 @@ class CheckerTest extends TestCase {
$this->fileAccessHelper
->expects($this->exactly(2))
->method('file_get_contents')
->withConsecutive(
[\OC::$SERVERROOT . '/tests/data/integritycheck/app//core/signature.json'],
[\OC::$SERVERROOT . '/tests/data/integritycheck/app//resources/codesigning/root.crt'],
)->willReturnOnConsecutiveCalls(
$signatureDataFile,
file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')
);
->willReturnMap([
[\OC::$SERVERROOT . '/tests/data/integritycheck/app//core/signature.json', $signatureDataFile],
[\OC::$SERVERROOT . '/tests/data/integritycheck/app//resources/codesigning/root.crt', file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')],
]);
$expected = [
'EXCEPTION' => [
@ -997,13 +955,10 @@ class CheckerTest extends TestCase {
$this->fileAccessHelper
->expects($this->exactly(2))
->method('file_get_contents')
->withConsecutive(
[\OC::$SERVERROOT . '/tests/data/integritycheck/app//core/signature.json'],
[\OC::$SERVERROOT . '/tests/data/integritycheck/app//resources/codesigning/root.crt'],
)->willReturnOnConsecutiveCalls(
$signatureDataFile,
file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')
);
->willReturnMap([
[\OC::$SERVERROOT . '/tests/data/integritycheck/app//core/signature.json', $signatureDataFile],
[\OC::$SERVERROOT . '/tests/data/integritycheck/app//resources/codesigning/root.crt', file_get_contents(__DIR__ . '/../../data/integritycheck/root.crt')],
]);
$expected = [
'EXCEPTION' => [
@ -1027,7 +982,7 @@ class CheckerTest extends TestCase {
$this->appManager,
$this->mimeTypeDetector,
])
->setMethods([
->onlyMethods([
'verifyCoreSignature',
'verifyAppSignature',
])
@ -1048,45 +1003,40 @@ class CheckerTest extends TestCase {
$this->appManager
->expects($this->exactly(4))
->method('isShipped')
->withConsecutive(
['files'],
['calendar'],
['contacts'],
['dav'],
)->willReturnOnConsecutiveCalls(
true,
false,
false,
true,
);
->willReturnMap([
['files', true],
['calendar', false],
['contacts', false],
['dav', true],
]);
$calls = [
'files',
'calendar',
'dav',
];
$this->checker
->expects($this->exactly(3))
->method('verifyAppSignature')
->withConsecutive(
['files'],
['calendar'],
['dav'],
);
->willReturnCallback(function ($app) use (&$calls) {
$expected = array_shift($calls);
$this->assertSame($expected, $app);
return [];
});
$this->appLocator
->expects($this->exactly(2))
->method('getAppPath')
->withConsecutive(
['calendar'],
['contacts'],
)->willReturnOnConsecutiveCalls(
'/apps/calendar',
'/apps/contacts',
);
->willReturnMap([
['calendar', '/apps/calendar'],
['contacts', '/apps/contacts'],
]);
$this->fileAccessHelper
->expects($this->exactly(2))
->method('file_exists')
->withConsecutive(
['/apps/calendar/appinfo/signature.json'],
['/apps/contacts/appinfo/signature.json'],
)->willReturnOnConsecutiveCalls(
true,
false,
);
->willReturnMap([
['/apps/calendar/appinfo/signature.json', true],
['/apps/contacts/appinfo/signature.json', false],
]);
$this->appConfig
->expects($this->once())
->method('deleteKey')
@ -1110,10 +1060,7 @@ class CheckerTest extends TestCase {
$this->assertSame($expected, $this->checker->verifyAppSignature('SomeApp'));
}
/**
* @return array
*/
public function channelDataProvider() {
public static function channelDataProvider(): array {
return [
['stable', true],
['git', false],

File diff suppressed because it is too large Load Diff