Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 9 additions & 18 deletions tests/Core/Command/Config/ListConfigsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,39 +273,31 @@ public static function listData(): array {
*/
#[\PHPUnit\Framework\Attributes\DataProvider('listData')]
public function testList($app, $systemConfigs, $systemConfigMap, $appConfig, $private, $expected): void {
$this->systemConfig->expects($this->any())
->method('getKeys')
$this->systemConfig->method('getKeys')
->willReturn($systemConfigs);
if ($private) {
$this->systemConfig->expects($this->any())
->method('getValue')
$this->systemConfig->method('getValue')
->willReturnMap($systemConfigMap);
$this->appConfig->expects($this->any())
->method('getAllValues')
$this->appConfig->method('getAllValues')
->willReturnMap($appConfig);
} else {
$this->systemConfig->expects($this->any())
->method('getFilteredValue')
$this->systemConfig->method('getFilteredValue')
->willReturnMap($systemConfigMap);
$this->appConfig->expects($this->any())
->method('getFilteredValues')
$this->appConfig->method('getFilteredValues')
->willReturnMap($appConfig);
}

$this->appConfig->expects($this->any())
->method('getApps')
$this->appConfig->method('getApps')
->willReturn(['core', 'files']);
$this->appConfig->expects($this->any())
->method('getAllValues')
$this->appConfig->method('getAllValues')
->willReturnMap($appConfig);

$this->consoleInput->expects($this->once())
->method('getArgument')
->with('app')
->willReturn($app);

$this->consoleInput->expects($this->any())
->method('getOption')
$this->consoleInput->method('getOption')
->willReturnMap([
['output', 'json'],
['private', $private],
Expand All @@ -314,8 +306,7 @@ public function testList($app, $systemConfigs, $systemConfigMap, $appConfig, $pr
global $output;

$output = '';
$this->consoleOutput->expects($this->any())
->method('writeln')
$this->consoleOutput->method('writeln')
->willReturnCallback(function ($value) use (&$output) {
$output .= $value . "\n";
return $output;
Expand Down
12 changes: 4 additions & 8 deletions tests/Core/Command/Config/System/DeleteConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,11 @@ public function testDelete($configName, $configExists, $checkIfExists, $expected
->method('getArgument')
->with('name')
->willReturn([$configName]);
$this->consoleInput->expects($this->any())
->method('hasParameterOption')
$this->consoleInput->method('hasParameterOption')
->with('--error-if-not-exists')
->willReturn($checkIfExists);

$this->consoleOutput->expects($this->any())
->method('writeln')
$this->consoleOutput->method('writeln')
->with($this->stringContains($expectedMessage));

$this->assertSame($expectedReturn, $this->invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]));
Expand Down Expand Up @@ -194,13 +192,11 @@ public function testArrayDelete(array $configNames, $configKeyExists, $checkIfKe
->method('getArgument')
->with('name')
->willReturn($configNames);
$this->consoleInput->expects($this->any())
->method('hasParameterOption')
$this->consoleInput->method('hasParameterOption')
->with('--error-if-not-exists')
->willReturn($checkIfKeyExists);

$this->consoleOutput->expects($this->any())
->method('writeln')
$this->consoleOutput->method('writeln')
->with($this->stringContains($expectedMessage));

$this->assertSame($expectedReturn, $this->invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]));
Expand Down
9 changes: 3 additions & 6 deletions tests/Core/Command/Config/System/GetConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,12 @@ public function testGet($configNames, $value, $configExists, $defaultValue, $has
->method('getArgument')
->with('name')
->willReturn($configNames);
$this->consoleInput->expects($this->any())
->method('getOption')
$this->consoleInput->method('getOption')
->willReturnMap([
['default-value', $defaultValue],
['output', $outputFormat],
]);
$this->consoleInput->expects($this->any())
->method('hasParameterOption')
$this->consoleInput->method('hasParameterOption')
->willReturnMap([
['--output', false, true],
['--default-value', false,$hasDefault],
Expand All @@ -140,8 +138,7 @@ public function testGet($configNames, $value, $configExists, $defaultValue, $has
global $output;

$output = '';
$this->consoleOutput->expects($this->any())
->method('writeln')
$this->consoleOutput->method('writeln')
->willReturnCallback(function ($value) {
global $output;
$output .= $value . "\n";
Expand Down
12 changes: 6 additions & 6 deletions tests/Core/Command/Encryption/ChangeKeyStorageRootTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ protected function setUp(): void {
$outputFormatter->method('isDecorated')->willReturn(false);
$outputFormatter->method('format')->willReturnArgument(0);

$this->outputInterface->expects($this->any())->method('getFormatter')
$this->outputInterface->method('getFormatter')
->willReturn($outputFormatter);

$this->changeKeyStorageRoot = new ChangeKeyStorageRoot(
Expand Down Expand Up @@ -183,7 +183,7 @@ public function testPrepareNewRootException($dirExists, $couldCreateFile): void

$this->view->expects($this->once())->method('is_dir')->with('newRoot')
->willReturn($dirExists);
$this->view->expects($this->any())->method('file_put_contents')->willReturn($couldCreateFile);
$this->view->method('file_put_contents')->willReturn($couldCreateFile);

$this->invokePrivate($this->changeKeyStorageRoot, 'prepareNewRoot', ['newRoot']);
}
Expand Down Expand Up @@ -218,7 +218,7 @@ public function testMoveSystemKeys($dirExists, $targetExists, $executeRename): v

$this->view->expects($this->once())->method('is_dir')
->with('oldRoot/files_encryption')->willReturn($dirExists);
$changeKeyStorageRoot->expects($this->any())->method('targetExists')
$changeKeyStorageRoot->method('targetExists')
->with('newRoot/files_encryption')->willReturn($targetExists);

if ($executeRename) {
Expand Down Expand Up @@ -286,9 +286,9 @@ public function testMoveUserEncryptionFolder($userExists, $isDir, $targetExists,

$this->userManager->expects($this->once())->method('userExists')
->willReturn($userExists);
$this->view->expects($this->any())->method('is_dir')
$this->view->method('is_dir')
->willReturn($isDir);
$changeKeyStorageRoot->expects($this->any())->method('targetExists')
$changeKeyStorageRoot->method('targetExists')
->willReturn($targetExists);

if ($shouldRename) {
Expand Down Expand Up @@ -318,7 +318,7 @@ public static function dataTestMoveUserEncryptionFolder(): array {

#[\PHPUnit\Framework\Attributes\DataProvider('dataTestPrepareParentFolder')]
public function testPrepareParentFolder($path, $pathExists): void {
$this->view->expects($this->any())->method('file_exists')
$this->view->method('file_exists')
->willReturnCallback(
function ($fileExistsPath) use ($path, $pathExists) {
if ($path === $fileExistsPath) {
Expand Down
15 changes: 5 additions & 10 deletions tests/Core/Command/Encryption/DecryptAllTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,14 @@ protected function setUp(): void {
$this->decryptAll = $this->createMock(\OC\Encryption\DecryptAll::class);

$this->consoleInput = $this->getMockBuilder(InputInterface::class)->getMock();
$this->consoleInput->expects($this->any())
->method('isInteractive')
$this->consoleInput->method('isInteractive')
->willReturn(true);
$this->consoleOutput = $this->getMockBuilder(OutputInterface::class)->getMock();

$this->config->expects($this->any())
->method('getSystemValue')
$this->config->method('getSystemValue')
->with('maintenance', false)
->willReturn(false);
$this->appManager->expects($this->any())
->method('isEnabledForUser')
$this->appManager->method('isEnabledForUser')
->with('files_trashbin')->willReturn(true);
}

Expand Down Expand Up @@ -106,8 +103,7 @@ public function testExecute($encryptionEnabled, $continue): void {
->with('core', 'encryption_enabled', false)
->willReturn($encryptionEnabled);

$this->consoleInput->expects($this->any())
->method('getArgument')
$this->consoleInput->method('getArgument')
->with('user')
->willReturn('user1');

Expand Down Expand Up @@ -178,8 +174,7 @@ public function testExecuteFailure(): void {
->with('core', 'encryption_enabled', false)
->willReturn(true);

$this->consoleInput->expects($this->any())
->method('getArgument')
$this->consoleInput->method('getArgument')
->with('user')
->willReturn('user1');

Expand Down
3 changes: 1 addition & 2 deletions tests/Core/Command/Encryption/EncryptAllTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ protected function setUp(): void {
$this->encryptionModule = $this->createMock(IEncryptionModule::class);
$this->questionHelper = $this->createMock(QuestionHelper::class);
$this->consoleInput = $this->createMock(InputInterface::class);
$this->consoleInput->expects($this->any())
->method('isInteractive')
$this->consoleInput->method('isInteractive')
->willReturn(true);
$this->consoleOutput = $this->createMock(OutputInterface::class);
}
Expand Down
6 changes: 2 additions & 4 deletions tests/Core/Command/Maintenance/ModeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,7 @@ public function testExecute(
$expectedMaintenanceState,
string $expectedOutput,
): void {
$this->config->expects($this->any())
->method('getSystemValueBool')
$this->config->method('getSystemValueBool')
->willReturn($currentMaintenanceState);

if ($expectedMaintenanceState !== null) {
Expand All @@ -138,8 +137,7 @@ public function testExecute(
->with('maintenance', $expectedMaintenanceState);
}

$this->input->expects($this->any())
->method('getOption')
$this->input->method('getOption')
->willReturnCallback(function ($callOption) use ($option) {
return $callOption === $option;
});
Expand Down
24 changes: 8 additions & 16 deletions tests/Core/Command/User/ProfileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,11 @@ public static function dataCheckInput(): array {

#[\PHPUnit\Framework\Attributes\DataProvider('dataCheckInput')]
public function testCheckInput(array $arguments, array $options, array $parameterOptions, bool $existingUser, ?string $expectedException): void {
$this->consoleInput->expects($this->any())
->method('getArgument')
$this->consoleInput->method('getArgument')
->willReturnMap($arguments);
$this->consoleInput->expects($this->any())
->method('getOption')
$this->consoleInput->method('getOption')
->willReturnMap($options);
$this->consoleInput->expects($this->any())
->method('hasParameterOption')
$this->consoleInput->method('hasParameterOption')
->willReturnCallback(function (string|array $values, bool $onlyParams = false) use ($parameterOptions): bool {
$arguments = func_get_args();
foreach ($parameterOptions as $parameterOption) {
Expand Down Expand Up @@ -243,8 +240,7 @@ public function testExecuteDeleteProfileProperty(string $configKey, string $valu
'checkInput',
]);

$this->consoleInput->expects($this->any())
->method('getArgument')
$this->consoleInput->method('getArgument')
->willReturnMap([
['uid', $uid],
['app', $appName],
Expand Down Expand Up @@ -335,8 +331,7 @@ public function testExecuteGet(string $key, string $value, ?string $defaultValue

$uid = 'username';

$this->consoleInput->expects($this->any())
->method('getArgument')
$this->consoleInput->method('getArgument')
->willReturnMap([
['uid', $uid],
['key', $key],
Expand Down Expand Up @@ -383,8 +378,7 @@ public function testExecuteList(): void {
'checkInput',
]);

$this->consoleInput->expects($this->any())
->method('getArgument')
$this->consoleInput->method('getArgument')
->willReturnMap([
['uid', $uid],
['key', ''],
Expand Down Expand Up @@ -454,11 +448,9 @@ private function getAccountPropertyMock(string $name, string $value): IAccountPr
$propertyMock = $this->getMockBuilder(IAccountProperty::class)
->disableOriginalConstructor()
->getMock();
$propertyMock->expects($this->any())
->method('getName')
$propertyMock->method('getName')
->willReturn($name);
$propertyMock->expects($this->any())
->method('getValue')
$propertyMock->method('getValue')
->willReturn($value);

return $propertyMock;
Expand Down
18 changes: 6 additions & 12 deletions tests/Core/Command/User/SettingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,11 @@ public static function dataCheckInput(): array {
*/
#[\PHPUnit\Framework\Attributes\DataProvider('dataCheckInput')]
public function testCheckInput($arguments, $options, $parameterOptions, $user, $expectedException): void {
$this->consoleInput->expects($this->any())
->method('getArgument')
$this->consoleInput->method('getArgument')
->willReturnMap($arguments);
$this->consoleInput->expects($this->any())
->method('getOption')
$this->consoleInput->method('getOption')
->willReturnMap($options);
$this->consoleInput->expects($this->any())
->method('hasParameterOption')
$this->consoleInput->method('hasParameterOption')
->willReturnCallback(function (string|array $config, bool $default = false) use ($parameterOptions): bool {
foreach ($parameterOptions as $parameterOption) {
if ($config === $parameterOption[0]
Expand Down Expand Up @@ -275,8 +272,7 @@ public function testExecuteDelete($value, $errorIfNotExists, $expectedLine, $exp
'getUserSettings',
]);

$this->consoleInput->expects($this->any())
->method('getArgument')
$this->consoleInput->method('getArgument')
->willReturnMap([
['uid', 'username'],
['app', 'appname'],
Expand Down Expand Up @@ -519,8 +515,7 @@ public function testExecuteGet($value, $defaultValue, $expectedLine, $expectedRe
'getUserSettings',
]);

$this->consoleInput->expects($this->any())
->method('getArgument')
$this->consoleInput->method('getArgument')
->willReturnMap([
['uid', 'username'],
['app', 'appname'],
Expand Down Expand Up @@ -570,8 +565,7 @@ public function testExecuteList(): void {
'getUserSettings',
]);

$this->consoleInput->expects($this->any())
->method('getArgument')
$this->consoleInput->method('getArgument')
->willReturnMap([
['uid', 'username'],
['app', 'appname'],
Expand Down
3 changes: 0 additions & 3 deletions tests/Core/Controller/ClientFlowLoginControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ protected function setUp(): void {
$this->userSession = $this->createMock(IUserSession::class);
$this->l10n = $this->createMock(IL10N::class);
$this->l10n
->expects($this->any())
->method('t')
->willReturnCallback(function ($text, $parameters = []) {
return vsprintf($text, $parameters);
Expand Down Expand Up @@ -408,7 +407,6 @@ public function testGeneratePasswordWithPassword(): void {
->method('getServerHost')
->willReturn('example.com');
$this->request
->expects($this->any())
->method('getHeader')
->willReturn('');

Expand Down Expand Up @@ -573,7 +571,6 @@ public function testGeneratePasswordWithoutPassword(): void {
->method('getServerHost')
->willReturn('example.com');
$this->request
->expects($this->any())
->method('getHeader')
->willReturn('');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ protected function setUp(): void {
$this->initialState = $this->createMock(IInitialState::class);
$this->l = $this->createMock(IL10N::class);
$this->l
->expects($this->any())
->method('t')
->willReturnCallback(function ($text, $parameters = []) {
return vsprintf($text, $parameters);
Expand Down
Loading