Skip to content

Commit c24f5fb

Browse files
committed
test: Finish migrating tests/Core/ to PHPUnit 10 compatible code
Signed-off-by: Joas Schilling <coding@schilljs.com>
1 parent 9a16e4f commit c24f5fb

Some content is hidden

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

46 files changed

+864
-880
lines changed

tests/Core/Command/Apps/AppsDisableTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function testCommandInput($appId, $statusCode, $pattern): void {
5050
$this->assertSame($statusCode, $this->commandTester->getStatusCode());
5151
}
5252

53-
public function dataCommandInput(): array {
53+
public static function dataCommandInput(): array {
5454
return [
5555
[['admin_audit'], 0, 'admin_audit ([\d\.]*) disabled'],
5656
[['comments'], 0, 'comments ([\d\.]*) disabled'],

tests/Core/Command/Apps/AppsEnableTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function testCommandInput($appId, $groups, $statusCode, $pattern): void {
5757
$this->assertSame($statusCode, $this->commandTester->getStatusCode());
5858
}
5959

60-
public function dataCommandInput(): array {
60+
public static function dataCommandInput(): array {
6161
return [
6262
[['admin_audit'], null, 0, 'admin_audit ([\d\.]*) enabled'],
6363
[['comments'], null, 0, 'comments ([\d\.]*) enabled'],

tests/Core/Command/Config/ImportTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ protected function setUp(): void {
3838
$this->command = new Import($config);
3939
}
4040

41-
public function validateAppsArrayData() {
41+
public static function validateAppsArrayData(): array {
4242
return [
4343
[0],
4444
[1],
@@ -58,7 +58,7 @@ public function testValidateAppsArray($configValue): void {
5858
$this->assertTrue(true, 'Asserting that no exception is thrown');
5959
}
6060

61-
public function validateAppsArrayThrowsData() {
61+
public static function validateAppsArrayThrowsData(): array {
6262
return [
6363
[false],
6464
[true],
@@ -81,7 +81,7 @@ public function testValidateAppsArrayThrows($configValue): void {
8181
}
8282
}
8383

84-
public function checkTypeRecursivelyData() {
84+
public static function checkTypeRecursivelyData(): array {
8585
return [
8686
[0],
8787
[1],
@@ -107,7 +107,7 @@ public function testCheckTypeRecursively($configValue): void {
107107
$this->assertTrue(true, 'Asserting that no exception is thrown');
108108
}
109109

110-
public function checkTypeRecursivelyThrowsData() {
110+
public static function checkTypeRecursivelyThrowsData(): array {
111111
return [
112112
[new \Exception()],
113113
[[new \Exception()]],
@@ -130,7 +130,7 @@ public function testCheckTypeRecursivelyThrows($configValue): void {
130130
}
131131
}
132132

133-
public function validateArrayData() {
133+
public static function validateArrayData(): array {
134134
return [
135135
[['system' => []]],
136136
[['apps' => []]],
@@ -148,7 +148,7 @@ public function testValidateArray($configArray): void {
148148
$this->assertTrue(true, 'Asserting that no exception is thrown');
149149
}
150150

151-
public function validateArrayThrowsData() {
151+
public static function validateArrayThrowsData(): array {
152152
return [
153153
[[], 'At least one key of the following is expected:'],
154154
[[0 => []], 'Found invalid entries in root'],

tests/Core/Command/Config/ListConfigsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ protected function setUp(): void {
4646
$this->command = new ListConfigs($systemConfig, $appConfig);
4747
}
4848

49-
public function listData() {
49+
public static function listData(): array {
5050
return [
5151
[
5252
'all',

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ protected function setUp(): void {
3838
$this->command = new DeleteConfig($systemConfig);
3939
}
4040

41-
public function deleteData() {
41+
public static function deleteData(): array {
4242
return [
4343
[
4444
'name1',
@@ -105,7 +105,7 @@ public function testDelete($configName, $configExists, $checkIfExists, $expected
105105
$this->assertSame($expectedReturn, $this->invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]));
106106
}
107107

108-
public function deleteArrayData() {
108+
public static function deleteArrayData(): array {
109109
return [
110110
[
111111
['name', 'sub'],

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ protected function setUp(): void {
3939
}
4040

4141

42-
public function getData() {
42+
public static function getData(): array {
4343
return [
4444
// String output as json
4545
['name', 'newvalue', true, null, false, 'json', 0, json_encode('newvalue')],

tests/Core/Command/Config/System/SetConfigTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function testSet($configNames, $newValue, $existingData, $expectedValue):
7676
$this->invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]);
7777
}
7878

79-
public function setUpdateOnlyProvider() {
79+
public static function setUpdateOnlyProvider(): array {
8080
return [
8181
[['name'], null],
8282
[['a', 'b', 'c'], null],
@@ -113,7 +113,7 @@ public function testSetUpdateOnly($configNames, $existingData): void {
113113
$this->invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]);
114114
}
115115

116-
public function castValueProvider() {
116+
public static function castValueProvider(): array {
117117
return [
118118
[null, 'string', ['value' => '', 'readable-value' => 'empty string']],
119119

@@ -141,7 +141,7 @@ public function testCastValue($value, $type, $expectedValue): void {
141141
);
142142
}
143143

144-
public function castValueInvalidProvider() {
144+
public static function castValueInvalidProvider(): array {
145145
return [
146146
['123', 'foobar'],
147147

tests/Core/Command/Encryption/ChangeKeyStorageRootTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public function testExecute($newRoot, $answer, $successMoveKey): void {
8989
$this->util,
9090
$this->questionHelper
9191
]
92-
)->setMethods(['moveAllKeys'])->getMock();
92+
)->onlyMethods(['moveAllKeys'])->getMock();
9393

9494
$this->util->expects($this->once())->method('getKeyStorageRoot')
9595
->willReturn('');
@@ -122,7 +122,7 @@ public function testExecute($newRoot, $answer, $successMoveKey): void {
122122
);
123123
}
124124

125-
public function dataTestExecute() {
125+
public static function dataTestExecute(): array {
126126
return [
127127
[null, true, true],
128128
[null, true, false],
@@ -143,7 +143,7 @@ public function testMoveAllKeys(): void {
143143
$this->util,
144144
$this->questionHelper
145145
]
146-
)->setMethods(['prepareNewRoot', 'moveSystemKeys', 'moveUserKeys'])->getMock();
146+
)->onlyMethods(['prepareNewRoot', 'moveSystemKeys', 'moveUserKeys'])->getMock();
147147

148148
$changeKeyStorageRoot->expects($this->once())->method('prepareNewRoot')->with('newRoot');
149149
$changeKeyStorageRoot->expects($this->once())->method('moveSystemKeys')->with('oldRoot', 'newRoot');
@@ -179,7 +179,7 @@ public function testPrepareNewRootException($dirExists, $couldCreateFile): void
179179
$this->invokePrivate($this->changeKeyStorageRoot, 'prepareNewRoot', ['newRoot']);
180180
}
181181

182-
public function dataTestPrepareNewRootException() {
182+
public static function dataTestPrepareNewRootException(): array {
183183
return [
184184
[true, false],
185185
[true, null],
@@ -204,7 +204,7 @@ public function testMoveSystemKeys($dirExists, $targetExists, $executeRename): v
204204
$this->util,
205205
$this->questionHelper
206206
]
207-
)->setMethods(['targetExists'])->getMock();
207+
)->onlyMethods(['targetExists'])->getMock();
208208

209209
$this->view->expects($this->once())->method('is_dir')
210210
->with('oldRoot/files_encryption')->willReturn($dirExists);
@@ -221,7 +221,7 @@ public function testMoveSystemKeys($dirExists, $targetExists, $executeRename): v
221221
$this->invokePrivate($changeKeyStorageRoot, 'moveSystemKeys', ['oldRoot', 'newRoot']);
222222
}
223223

224-
public function dataTestMoveSystemKeys() {
224+
public static function dataTestMoveSystemKeys(): array {
225225
return [
226226
[true, false, true],
227227
[false, true, false],
@@ -241,7 +241,7 @@ public function testMoveUserKeys(): void {
241241
$this->util,
242242
$this->questionHelper
243243
]
244-
)->setMethods(['setupUserFS', 'moveUserEncryptionFolder'])->getMock();
244+
)->onlyMethods(['setupUserFS', 'moveUserEncryptionFolder'])->getMock();
245245

246246
$this->userManager->expects($this->once())->method('getBackends')
247247
->willReturn([$this->userInterface]);
@@ -271,7 +271,7 @@ public function testMoveUserEncryptionFolder($userExists, $isDir, $targetExists,
271271
$this->util,
272272
$this->questionHelper
273273
]
274-
)->setMethods(['targetExists', 'prepareParentFolder'])->getMock();
274+
)->onlyMethods(['targetExists', 'prepareParentFolder'])->getMock();
275275

276276
$this->userManager->expects($this->once())->method('userExists')
277277
->willReturn($userExists);
@@ -293,7 +293,7 @@ public function testMoveUserEncryptionFolder($userExists, $isDir, $targetExists,
293293
$this->invokePrivate($changeKeyStorageRoot, 'moveUserEncryptionFolder', ['user1', 'oldRoot', 'newRoot']);
294294
}
295295

296-
public function dataTestMoveUserEncryptionFolder() {
296+
public static function dataTestMoveUserEncryptionFolder(): array {
297297
return [
298298
[true, true, false, true],
299299
[true, false, true, false],
@@ -334,7 +334,7 @@ function ($fileExistsPath) use ($path, $pathExists) {
334334
);
335335
}
336336

337-
public function dataTestPrepareParentFolder() {
337+
public static function dataTestPrepareParentFolder(): array {
338338
return [
339339
['/user/folder/sub_folder/keystorage', true],
340340
['/user/folder/sub_folder/keystorage', false]

tests/Core/Command/Encryption/DecryptAllTest.php

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,16 @@ protected function setUp(): void {
7373
public function testMaintenanceAndTrashbin(): void {
7474
// on construct we enable single-user-mode and disable the trash bin
7575
// on destruct we disable single-user-mode again and enable the trash bin
76+
$calls = [
77+
['maintenance', true],
78+
['maintenance', false],
79+
];
7680
$this->config->expects($this->exactly(2))
7781
->method('setSystemValue')
78-
->withConsecutive(
79-
['maintenance', true],
80-
['maintenance', false],
81-
);
82+
->willReturnCallback(function () use (&$calls) {
83+
$expected = array_shift($calls);
84+
$this->assertEquals($expected, func_get_args());
85+
});
8286
$this->appManager->expects($this->once())
8387
->method('disableApp')
8488
->with('files_trashbin');
@@ -127,12 +131,16 @@ public function testExecute($encryptionEnabled, $continue): void {
127131
->willReturn('user1');
128132

129133
if ($encryptionEnabled) {
134+
$calls = [
135+
['core', 'encryption_enabled', 'no'],
136+
['core', 'encryption_enabled', 'yes'],
137+
];
130138
$this->config->expects($this->exactly(2))
131139
->method('setAppValue')
132-
->withConsecutive(
133-
['core', 'encryption_enabled', 'no'],
134-
['core', 'encryption_enabled', 'yes'],
135-
);
140+
->willReturnCallback(function () use (&$calls) {
141+
$expected = array_shift($calls);
142+
$this->assertEquals($expected, func_get_args());
143+
});
136144
$this->questionHelper->expects($this->once())
137145
->method('ask')
138146
->willReturn($continue);
@@ -152,7 +160,7 @@ public function testExecute($encryptionEnabled, $continue): void {
152160
$this->invokePrivate($instance, 'execute', [$this->consoleInput, $this->consoleOutput]);
153161
}
154162

155-
public function dataTestExecute() {
163+
public static function dataTestExecute(): array {
156164
return [
157165
[true, true],
158166
[true, false],
@@ -174,13 +182,16 @@ public function testExecuteFailure(): void {
174182
);
175183

176184
// make sure that we enable encryption again after a exception was thrown
185+
$calls = [
186+
['core', 'encryption_enabled', 'no'],
187+
['core', 'encryption_enabled', 'yes'],
188+
];
177189
$this->config->expects($this->exactly(2))
178190
->method('setAppValue')
179-
->withConsecutive(
180-
['core', 'encryption_enabled', 'no'],
181-
['core', 'encryption_enabled', 'yes'],
182-
);
183-
191+
->willReturnCallback(function () use (&$calls) {
192+
$expected = array_shift($calls);
193+
$this->assertEquals($expected, func_get_args());
194+
});
184195
$this->encryptionManager->expects($this->once())
185196
->method('isEnabled')
186197
->willReturn(true);

tests/Core/Command/Encryption/DisableTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ protected function setUp(): void {
3838
}
3939

4040

41-
public function dataDisable() {
41+
public static function dataDisable(): array {
4242
return [
4343
['yes', true, 'Encryption disabled'],
4444
['no', false, 'Encryption is already disabled'],

0 commit comments

Comments
 (0)