Skip to content

Commit 4b5ce61

Browse files
committed
test: drop redundant expects($this->any()) from mocks
Calling method() on a mock already allows any number of calls, so the explicit any() matcher only adds noise to test setup. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Tomas Votruba <tomas.vot@gmail.com>
1 parent f780892 commit 4b5ce61

110 files changed

Lines changed: 783 additions & 1439 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎tests/Core/Command/Config/ListConfigsTest.php‎

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -273,39 +273,31 @@ public static function listData(): array {
273273
*/
274274
#[\PHPUnit\Framework\Attributes\DataProvider('listData')]
275275
public function testList($app, $systemConfigs, $systemConfigMap, $appConfig, $private, $expected): void {
276-
$this->systemConfig->expects($this->any())
277-
->method('getKeys')
276+
$this->systemConfig->method('getKeys')
278277
->willReturn($systemConfigs);
279278
if ($private) {
280-
$this->systemConfig->expects($this->any())
281-
->method('getValue')
279+
$this->systemConfig->method('getValue')
282280
->willReturnMap($systemConfigMap);
283-
$this->appConfig->expects($this->any())
284-
->method('getAllValues')
281+
$this->appConfig->method('getAllValues')
285282
->willReturnMap($appConfig);
286283
} else {
287-
$this->systemConfig->expects($this->any())
288-
->method('getFilteredValue')
284+
$this->systemConfig->method('getFilteredValue')
289285
->willReturnMap($systemConfigMap);
290-
$this->appConfig->expects($this->any())
291-
->method('getFilteredValues')
286+
$this->appConfig->method('getFilteredValues')
292287
->willReturnMap($appConfig);
293288
}
294289

295-
$this->appConfig->expects($this->any())
296-
->method('getApps')
290+
$this->appConfig->method('getApps')
297291
->willReturn(['core', 'files']);
298-
$this->appConfig->expects($this->any())
299-
->method('getAllValues')
292+
$this->appConfig->method('getAllValues')
300293
->willReturnMap($appConfig);
301294

302295
$this->consoleInput->expects($this->once())
303296
->method('getArgument')
304297
->with('app')
305298
->willReturn($app);
306299

307-
$this->consoleInput->expects($this->any())
308-
->method('getOption')
300+
$this->consoleInput->method('getOption')
309301
->willReturnMap([
310302
['output', 'json'],
311303
['private', $private],
@@ -314,8 +306,7 @@ public function testList($app, $systemConfigs, $systemConfigMap, $appConfig, $pr
314306
global $output;
315307

316308
$output = '';
317-
$this->consoleOutput->expects($this->any())
318-
->method('writeln')
309+
$this->consoleOutput->method('writeln')
319310
->willReturnCallback(function ($value) use (&$output) {
320311
$output .= $value . "\n";
321312
return $output;

‎tests/Core/Command/Config/System/DeleteConfigTest.php‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,11 @@ public function testDelete($configName, $configExists, $checkIfExists, $expected
9595
->method('getArgument')
9696
->with('name')
9797
->willReturn([$configName]);
98-
$this->consoleInput->expects($this->any())
99-
->method('hasParameterOption')
98+
$this->consoleInput->method('hasParameterOption')
10099
->with('--error-if-not-exists')
101100
->willReturn($checkIfExists);
102101

103-
$this->consoleOutput->expects($this->any())
104-
->method('writeln')
102+
$this->consoleOutput->method('writeln')
105103
->with($this->stringContains($expectedMessage));
106104

107105
$this->assertSame($expectedReturn, $this->invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]));
@@ -194,13 +192,11 @@ public function testArrayDelete(array $configNames, $configKeyExists, $checkIfKe
194192
->method('getArgument')
195193
->with('name')
196194
->willReturn($configNames);
197-
$this->consoleInput->expects($this->any())
198-
->method('hasParameterOption')
195+
$this->consoleInput->method('hasParameterOption')
199196
->with('--error-if-not-exists')
200197
->willReturn($checkIfKeyExists);
201198

202-
$this->consoleOutput->expects($this->any())
203-
->method('writeln')
199+
$this->consoleOutput->method('writeln')
204200
->with($this->stringContains($expectedMessage));
205201

206202
$this->assertSame($expectedReturn, $this->invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]));

‎tests/Core/Command/Config/System/GetConfigTest.php‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,12 @@ public function testGet($configNames, $value, $configExists, $defaultValue, $has
123123
->method('getArgument')
124124
->with('name')
125125
->willReturn($configNames);
126-
$this->consoleInput->expects($this->any())
127-
->method('getOption')
126+
$this->consoleInput->method('getOption')
128127
->willReturnMap([
129128
['default-value', $defaultValue],
130129
['output', $outputFormat],
131130
]);
132-
$this->consoleInput->expects($this->any())
133-
->method('hasParameterOption')
131+
$this->consoleInput->method('hasParameterOption')
134132
->willReturnMap([
135133
['--output', false, true],
136134
['--default-value', false,$hasDefault],
@@ -140,8 +138,7 @@ public function testGet($configNames, $value, $configExists, $defaultValue, $has
140138
global $output;
141139

142140
$output = '';
143-
$this->consoleOutput->expects($this->any())
144-
->method('writeln')
141+
$this->consoleOutput->method('writeln')
145142
->willReturnCallback(function ($value) {
146143
global $output;
147144
$output .= $value . "\n";

‎tests/Core/Command/Encryption/ChangeKeyStorageRootTest.php‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ protected function setUp(): void {
7272
$outputFormatter->method('isDecorated')->willReturn(false);
7373
$outputFormatter->method('format')->willReturnArgument(0);
7474

75-
$this->outputInterface->expects($this->any())->method('getFormatter')
75+
$this->outputInterface->method('getFormatter')
7676
->willReturn($outputFormatter);
7777

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

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

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

219219
$this->view->expects($this->once())->method('is_dir')
220220
->with('oldRoot/files_encryption')->willReturn($dirExists);
221-
$changeKeyStorageRoot->expects($this->any())->method('targetExists')
221+
$changeKeyStorageRoot->method('targetExists')
222222
->with('newRoot/files_encryption')->willReturn($targetExists);
223223

224224
if ($executeRename) {
@@ -286,9 +286,9 @@ public function testMoveUserEncryptionFolder($userExists, $isDir, $targetExists,
286286

287287
$this->userManager->expects($this->once())->method('userExists')
288288
->willReturn($userExists);
289-
$this->view->expects($this->any())->method('is_dir')
289+
$this->view->method('is_dir')
290290
->willReturn($isDir);
291-
$changeKeyStorageRoot->expects($this->any())->method('targetExists')
291+
$changeKeyStorageRoot->method('targetExists')
292292
->willReturn($targetExists);
293293

294294
if ($shouldRename) {
@@ -318,7 +318,7 @@ public static function dataTestMoveUserEncryptionFolder(): array {
318318

319319
#[\PHPUnit\Framework\Attributes\DataProvider('dataTestPrepareParentFolder')]
320320
public function testPrepareParentFolder($path, $pathExists): void {
321-
$this->view->expects($this->any())->method('file_exists')
321+
$this->view->method('file_exists')
322322
->willReturnCallback(
323323
function ($fileExistsPath) use ($path, $pathExists) {
324324
if ($path === $fileExistsPath) {

‎tests/Core/Command/Encryption/DecryptAllTest.php‎

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,14 @@ protected function setUp(): void {
3838
$this->decryptAll = $this->createMock(\OC\Encryption\DecryptAll::class);
3939

4040
$this->consoleInput = $this->getMockBuilder(InputInterface::class)->getMock();
41-
$this->consoleInput->expects($this->any())
42-
->method('isInteractive')
41+
$this->consoleInput->method('isInteractive')
4342
->willReturn(true);
4443
$this->consoleOutput = $this->getMockBuilder(OutputInterface::class)->getMock();
4544

46-
$this->config->expects($this->any())
47-
->method('getSystemValue')
45+
$this->config->method('getSystemValue')
4846
->with('maintenance', false)
4947
->willReturn(false);
50-
$this->appManager->expects($this->any())
51-
->method('isEnabledForUser')
48+
$this->appManager->method('isEnabledForUser')
5249
->with('files_trashbin')->willReturn(true);
5350
}
5451

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

109-
$this->consoleInput->expects($this->any())
110-
->method('getArgument')
106+
$this->consoleInput->method('getArgument')
111107
->with('user')
112108
->willReturn('user1');
113109

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

181-
$this->consoleInput->expects($this->any())
182-
->method('getArgument')
177+
$this->consoleInput->method('getArgument')
183178
->with('user')
184179
->willReturn('user1');
185180

‎tests/Core/Command/Encryption/EncryptAllTest.php‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ protected function setUp(): void {
4040
$this->encryptionModule = $this->createMock(IEncryptionModule::class);
4141
$this->questionHelper = $this->createMock(QuestionHelper::class);
4242
$this->consoleInput = $this->createMock(InputInterface::class);
43-
$this->consoleInput->expects($this->any())
44-
->method('isInteractive')
43+
$this->consoleInput->method('isInteractive')
4544
->willReturn(true);
4645
$this->consoleOutput = $this->createMock(OutputInterface::class);
4746
}

‎tests/Core/Command/Maintenance/ModeTest.php‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,7 @@ public function testExecute(
128128
$expectedMaintenanceState,
129129
string $expectedOutput,
130130
): void {
131-
$this->config->expects($this->any())
132-
->method('getSystemValueBool')
131+
$this->config->method('getSystemValueBool')
133132
->willReturn($currentMaintenanceState);
134133

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

141-
$this->input->expects($this->any())
142-
->method('getOption')
140+
$this->input->method('getOption')
143141
->willReturnCallback(function ($callOption) use ($option) {
144142
return $callOption === $option;
145143
});

‎tests/Core/Command/User/ProfileTest.php‎

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,11 @@ public static function dataCheckInput(): array {
170170

171171
#[\PHPUnit\Framework\Attributes\DataProvider('dataCheckInput')]
172172
public function testCheckInput(array $arguments, array $options, array $parameterOptions, bool $existingUser, ?string $expectedException): void {
173-
$this->consoleInput->expects($this->any())
174-
->method('getArgument')
173+
$this->consoleInput->method('getArgument')
175174
->willReturnMap($arguments);
176-
$this->consoleInput->expects($this->any())
177-
->method('getOption')
175+
$this->consoleInput->method('getOption')
178176
->willReturnMap($options);
179-
$this->consoleInput->expects($this->any())
180-
->method('hasParameterOption')
177+
$this->consoleInput->method('hasParameterOption')
181178
->willReturnCallback(function (string|array $values, bool $onlyParams = false) use ($parameterOptions): bool {
182179
$arguments = func_get_args();
183180
foreach ($parameterOptions as $parameterOption) {
@@ -243,8 +240,7 @@ public function testExecuteDeleteProfileProperty(string $configKey, string $valu
243240
'checkInput',
244241
]);
245242

246-
$this->consoleInput->expects($this->any())
247-
->method('getArgument')
243+
$this->consoleInput->method('getArgument')
248244
->willReturnMap([
249245
['uid', $uid],
250246
['app', $appName],
@@ -335,8 +331,7 @@ public function testExecuteGet(string $key, string $value, ?string $defaultValue
335331

336332
$uid = 'username';
337333

338-
$this->consoleInput->expects($this->any())
339-
->method('getArgument')
334+
$this->consoleInput->method('getArgument')
340335
->willReturnMap([
341336
['uid', $uid],
342337
['key', $key],
@@ -383,8 +378,7 @@ public function testExecuteList(): void {
383378
'checkInput',
384379
]);
385380

386-
$this->consoleInput->expects($this->any())
387-
->method('getArgument')
381+
$this->consoleInput->method('getArgument')
388382
->willReturnMap([
389383
['uid', $uid],
390384
['key', ''],
@@ -454,11 +448,9 @@ private function getAccountPropertyMock(string $name, string $value): IAccountPr
454448
$propertyMock = $this->getMockBuilder(IAccountProperty::class)
455449
->disableOriginalConstructor()
456450
->getMock();
457-
$propertyMock->expects($this->any())
458-
->method('getName')
451+
$propertyMock->method('getName')
459452
->willReturn($name);
460-
$propertyMock->expects($this->any())
461-
->method('getValue')
453+
$propertyMock->method('getValue')
462454
->willReturn($value);
463455

464456
return $propertyMock;

‎tests/Core/Command/User/SettingTest.php‎

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -201,14 +201,11 @@ public static function dataCheckInput(): array {
201201
*/
202202
#[\PHPUnit\Framework\Attributes\DataProvider('dataCheckInput')]
203203
public function testCheckInput($arguments, $options, $parameterOptions, $user, $expectedException): void {
204-
$this->consoleInput->expects($this->any())
205-
->method('getArgument')
204+
$this->consoleInput->method('getArgument')
206205
->willReturnMap($arguments);
207-
$this->consoleInput->expects($this->any())
208-
->method('getOption')
206+
$this->consoleInput->method('getOption')
209207
->willReturnMap($options);
210-
$this->consoleInput->expects($this->any())
211-
->method('hasParameterOption')
208+
$this->consoleInput->method('hasParameterOption')
212209
->willReturnCallback(function (string|array $config, bool $default = false) use ($parameterOptions): bool {
213210
foreach ($parameterOptions as $parameterOption) {
214211
if ($config === $parameterOption[0]
@@ -275,8 +272,7 @@ public function testExecuteDelete($value, $errorIfNotExists, $expectedLine, $exp
275272
'getUserSettings',
276273
]);
277274

278-
$this->consoleInput->expects($this->any())
279-
->method('getArgument')
275+
$this->consoleInput->method('getArgument')
280276
->willReturnMap([
281277
['uid', 'username'],
282278
['app', 'appname'],
@@ -519,8 +515,7 @@ public function testExecuteGet($value, $defaultValue, $expectedLine, $expectedRe
519515
'getUserSettings',
520516
]);
521517

522-
$this->consoleInput->expects($this->any())
523-
->method('getArgument')
518+
$this->consoleInput->method('getArgument')
524519
->willReturnMap([
525520
['uid', 'username'],
526521
['app', 'appname'],
@@ -570,8 +565,7 @@ public function testExecuteList(): void {
570565
'getUserSettings',
571566
]);
572567

573-
$this->consoleInput->expects($this->any())
574-
->method('getArgument')
568+
$this->consoleInput->method('getArgument')
575569
->willReturnMap([
576570
['uid', 'username'],
577571
['app', 'appname'],

‎tests/Core/Controller/ClientFlowLoginControllerTest.php‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ protected function setUp(): void {
6969
$this->userSession = $this->createMock(IUserSession::class);
7070
$this->l10n = $this->createMock(IL10N::class);
7171
$this->l10n
72-
->expects($this->any())
7372
->method('t')
7473
->willReturnCallback(function ($text, $parameters = []) {
7574
return vsprintf($text, $parameters);
@@ -408,7 +407,6 @@ public function testGeneratePasswordWithPassword(): void {
408407
->method('getServerHost')
409408
->willReturn('example.com');
410409
$this->request
411-
->expects($this->any())
412410
->method('getHeader')
413411
->willReturn('');
414412

@@ -573,7 +571,6 @@ public function testGeneratePasswordWithoutPassword(): void {
573571
->method('getServerHost')
574572
->willReturn('example.com');
575573
$this->request
576-
->expects($this->any())
577574
->method('getHeader')
578575
->willReturn('');
579576

0 commit comments

Comments
 (0)