Skip to content

Commit f0b2153

Browse files
committed
fix(phpunit): Remove some more withConsecutive calls
Signed-off-by: Joas Schilling <coding@schilljs.com>
1 parent 9ccb701 commit f0b2153

8 files changed

Lines changed: 183 additions & 240 deletions

File tree

tests/Core/Command/Encryption/EnableTest.php

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ protected function setUp(): void {
4545
}
4646

4747

48-
public function dataEnable() {
48+
public static function dataEnable(): array {
4949
return [
5050
['no', null, [], true, 'Encryption enabled', 'No encryption module is loaded'],
5151
['yes', null, [], false, 'Encryption is already enabled', 'No encryption module is loaded'],
@@ -57,15 +57,8 @@ public function dataEnable() {
5757

5858
/**
5959
* @dataProvider dataEnable
60-
*
61-
* @param string $oldStatus
62-
* @param string $defaultModule
63-
* @param array $availableModules
64-
* @param bool $isUpdating
65-
* @param string $expectedString
66-
* @param string $expectedDefaultModuleString
6760
*/
68-
public function testEnable($oldStatus, $defaultModule, $availableModules, $isUpdating, $expectedString, $expectedDefaultModuleString): void {
61+
public function testEnable(string $oldStatus, ?string $defaultModule, array $availableModules, bool $isUpdating, string $expectedString, string $expectedDefaultModuleString): void {
6962
if ($isUpdating) {
7063
$this->config->expects($this->once())
7164
->method('setAppValue')
@@ -79,27 +72,30 @@ public function testEnable($oldStatus, $defaultModule, $availableModules, $isUpd
7972
if (empty($availableModules)) {
8073
$this->config->expects($this->once())
8174
->method('getAppValue')
82-
->with('core', 'encryption_enabled', $this->anything())
83-
->willReturn($oldStatus);
75+
->willReturnMap([
76+
['core', 'encryption_enabled', 'no', $oldStatus],
77+
]);
8478
} else {
8579
$this->config->expects($this->exactly(2))
8680
->method('getAppValue')
87-
->withConsecutive(
88-
['core', 'encryption_enabled', $this->anything()],
89-
['core', 'default_encryption_module', $this->anything()],
90-
)->willReturnOnConsecutiveCalls(
91-
$oldStatus,
92-
$defaultModule,
93-
);
81+
->willReturnMap([
82+
['core', 'encryption_enabled', 'no', $oldStatus],
83+
['core', 'default_encryption_module', null, $defaultModule],
84+
]);
9485
}
9586

87+
$calls = [
88+
[$expectedString, 0],
89+
['', 0],
90+
[$expectedDefaultModuleString, 0],
91+
];
9692
$this->consoleOutput->expects($this->exactly(3))
9793
->method('writeln')
98-
->withConsecutive(
99-
[$this->stringContains($expectedString)],
100-
[''],
101-
[$this->stringContains($expectedDefaultModuleString)],
102-
);
94+
->willReturnCallback(function(string $message, int $level) use(&$calls): void {
95+
$call = array_shift($calls);
96+
$this->assertStringContainsString($call[0], $message);
97+
$this->assertSame($call[1], $level);
98+
});
10399

104100
self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]);
105101
}

tests/Core/Command/Log/ManageTest.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function testValidateTimezone(): void {
8787
self::invokePrivate($this->command, 'validateTimezone', ['Mars/OlympusMons']);
8888
}
8989

90-
public function convertLevelStringProvider() {
90+
public static function dataConvertLevelString(): array {
9191
return [
9292
['dEbug', 0],
9393
['inFO', 1],
@@ -100,9 +100,9 @@ public function convertLevelStringProvider() {
100100
}
101101

102102
/**
103-
* @dataProvider convertLevelStringProvider
103+
* @dataProvider dataConvertLevelString
104104
*/
105-
public function testConvertLevelString($levelString, $expectedInt): void {
105+
public function testConvertLevelString(string $levelString, int $expectedInt): void {
106106
$this->assertEquals($expectedInt,
107107
self::invokePrivate($this->command, 'convertLevelString', [$levelString])
108108
);
@@ -115,7 +115,7 @@ public function testConvertLevelStringInvalid(): void {
115115
self::invokePrivate($this->command, 'convertLevelString', ['abc']);
116116
}
117117

118-
public function convertLevelNumberProvider() {
118+
public static function dataConvertLevelNumber(): array {
119119
return [
120120
[0, 'Debug'],
121121
[1, 'Info'],
@@ -126,9 +126,9 @@ public function convertLevelNumberProvider() {
126126
}
127127

128128
/**
129-
* @dataProvider convertLevelNumberProvider
129+
* @dataProvider dataConvertLevelNumber
130130
*/
131-
public function testConvertLevelNumber($levelNum, $expectedString): void {
131+
public function testConvertLevelNumber(int $levelNum, string $expectedString): void {
132132
$this->assertEquals($expectedString,
133133
self::invokePrivate($this->command, 'convertLevelNumber', [$levelNum])
134134
);
@@ -144,23 +144,23 @@ public function testConvertLevelNumberInvalid(): void {
144144
public function testGetConfiguration(): void {
145145
$this->config->expects($this->exactly(3))
146146
->method('getSystemValue')
147-
->withConsecutive(
148-
['log_type', 'file'],
149-
['loglevel', 2],
150-
['logtimezone', 'UTC'],
151-
)->willReturnOnConsecutiveCalls(
152-
'log_type_value',
153-
0,
154-
'logtimezone_value'
155-
);
147+
->willReturnMap([
148+
['log_type', 'file', 'log_type_value'],
149+
['loglevel', 2, 0],
150+
['logtimezone', 'UTC', 'logtimezone_value'],
151+
]);
156152

153+
$calls = [
154+
['Enabled logging backend: log_type_value'],
155+
['Log level: Debug (0)'],
156+
['Log timezone: logtimezone_value'],
157+
];
157158
$this->consoleOutput->expects($this->exactly(3))
158159
->method('writeln')
159-
->withConsecutive(
160-
['Enabled logging backend: log_type_value'],
161-
['Log level: Debug (0)'],
162-
['Log timezone: logtimezone_value'],
163-
);
160+
->willReturnCallback(function(string $message) use(&$calls): void {
161+
$call = array_shift($calls);
162+
$this->assertStringContainsString($call[0], $message);
163+
});
164164

165165
self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]);
166166
}

tests/Core/Command/User/AuthTokens/DeleteTest.php

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ protected function setUp(): void {
4040
public function testDeleteTokenById(): void {
4141
$this->consoleInput->expects($this->exactly(2))
4242
->method('getArgument')
43-
->withConsecutive(['uid'], ['id'])
44-
->willReturnOnConsecutiveCalls('user', 42);
43+
->willReturnMap([
44+
['uid', 'user'],
45+
['id', '42']
46+
]);
4547

4648
$this->consoleInput->expects($this->once())
4749
->method('getOption')
@@ -59,8 +61,10 @@ public function testDeleteTokenById(): void {
5961
public function testDeleteTokenByIdRequiresTokenId(): void {
6062
$this->consoleInput->expects($this->exactly(2))
6163
->method('getArgument')
62-
->withConsecutive(['uid'], ['id'])
63-
->willReturnOnConsecutiveCalls('user', null);
64+
->willReturnMap([
65+
['uid', 'user'],
66+
['id', null]
67+
]);
6468

6569
$this->consoleInput->expects($this->once())
6670
->method('getOption')
@@ -78,8 +82,10 @@ public function testDeleteTokenByIdRequiresTokenId(): void {
7882
public function testDeleteTokensLastUsedBefore(): void {
7983
$this->consoleInput->expects($this->exactly(2))
8084
->method('getArgument')
81-
->withConsecutive(['uid'], ['id'])
82-
->willReturnOnConsecutiveCalls('user', null);
85+
->willReturnMap([
86+
['uid', 'user'],
87+
['id', null]
88+
]);
8389

8490
$this->consoleInput->expects($this->once())
8591
->method('getOption')
@@ -97,8 +103,10 @@ public function testDeleteTokensLastUsedBefore(): void {
97103
public function testLastUsedBeforeAcceptsIso8601Expanded(): void {
98104
$this->consoleInput->expects($this->exactly(2))
99105
->method('getArgument')
100-
->withConsecutive(['uid'], ['id'])
101-
->willReturnOnConsecutiveCalls('user', null);
106+
->willReturnMap([
107+
['uid', 'user'],
108+
['id', null]
109+
]);
102110

103111
$this->consoleInput->expects($this->once())
104112
->method('getOption')
@@ -116,8 +124,10 @@ public function testLastUsedBeforeAcceptsIso8601Expanded(): void {
116124
public function testLastUsedBeforeAcceptsYmd(): void {
117125
$this->consoleInput->expects($this->exactly(2))
118126
->method('getArgument')
119-
->withConsecutive(['uid'], ['id'])
120-
->willReturnOnConsecutiveCalls('user', null);
127+
->willReturnMap([
128+
['uid', 'user'],
129+
['id', null]
130+
]);
121131

122132
$this->consoleInput->expects($this->once())
123133
->method('getOption')
@@ -135,8 +145,10 @@ public function testLastUsedBeforeAcceptsYmd(): void {
135145
public function testIdAndLastUsedBeforeAreMutuallyExclusive(): void {
136146
$this->consoleInput->expects($this->exactly(2))
137147
->method('getArgument')
138-
->withConsecutive(['uid'], ['id'])
139-
->willReturnOnConsecutiveCalls('user', 42);
148+
->willReturnMap([
149+
['uid', 'user'],
150+
['id', '42']
151+
]);
140152

141153
$this->consoleInput->expects($this->once())
142154
->method('getOption')

tests/Core/Controller/NavigationControllerTest.php

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,14 @@ protected function setUp(): void {
4242
);
4343
}
4444

45-
public function dataGetNavigation() {
45+
public static function dataGetNavigation(): array {
4646
return [
47-
[false], [true]
47+
[false],
48+
[true],
4849
];
4950
}
5051
/** @dataProvider dataGetNavigation */
51-
public function testGetAppNavigation($absolute): void {
52+
public function testGetAppNavigation(bool $absolute): void {
5253
$this->navigationManager->expects($this->once())
5354
->method('getAll')
5455
->with('link')
@@ -59,11 +60,10 @@ public function testGetAppNavigation($absolute): void {
5960
->willReturn('http://localhost/');
6061
$this->urlGenerator->expects($this->exactly(2))
6162
->method('getAbsoluteURL')
62-
->withConsecutive(['/index.php/apps/files'], ['icon'])
63-
->willReturnOnConsecutiveCalls(
64-
'http://localhost/index.php/apps/files',
65-
'http://localhost/icon'
66-
);
63+
->willReturnMap([
64+
['/index.php/apps/files', 'http://localhost/index.php/apps/files'],
65+
['icon', 'http://localhost/icon'],
66+
]);
6767
$actual = $this->controller->getAppsNavigation($absolute);
6868
$this->assertInstanceOf(DataResponse::class, $actual);
6969
$this->assertEquals('http://localhost/index.php/apps/files', $actual->getData()[0]['href']);
@@ -77,7 +77,7 @@ public function testGetAppNavigation($absolute): void {
7777
}
7878

7979
/** @dataProvider dataGetNavigation */
80-
public function testGetSettingsNavigation($absolute): void {
80+
public function testGetSettingsNavigation(bool $absolute): void {
8181
$this->navigationManager->expects($this->once())
8282
->method('getAll')
8383
->with('settings')
@@ -88,14 +88,10 @@ public function testGetSettingsNavigation($absolute): void {
8888
->willReturn('http://localhost/');
8989
$this->urlGenerator->expects($this->exactly(2))
9090
->method('getAbsoluteURL')
91-
->withConsecutive(
92-
['/index.php/settings/user'],
93-
['/core/img/settings.svg']
94-
)
95-
->willReturnOnConsecutiveCalls(
96-
'http://localhost/index.php/settings/user',
97-
'http://localhost/core/img/settings.svg'
98-
);
91+
->willReturnMap([
92+
['/index.php/settings/user', 'http://localhost/index.php/settings/user'],
93+
['/core/img/settings.svg', 'http://localhost/core/img/settings.svg']
94+
]);
9995
$actual = $this->controller->getSettingsNavigation($absolute);
10096
$this->assertInstanceOf(DataResponse::class, $actual);
10197
$this->assertEquals('http://localhost/index.php/settings/user', $actual->getData()[0]['href']);

tests/lib/AppFramework/Http/RequestIdTest.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,7 @@ public function testGetIdWithoutModUnique(): void {
4949
$this->secureRandom->expects($this->once())
5050
->method('generate')
5151
->with('20')
52-
->willReturnOnConsecutiveCalls(
53-
'GeneratedByNextcloudItself1',
54-
'GeneratedByNextcloudItself2',
55-
'GeneratedByNextcloudItself3'
56-
);
52+
->willReturn('GeneratedByNextcloudItself1');
5753

5854
$this->assertSame('GeneratedByNextcloudItself1', $requestId->getId());
5955
$this->assertSame('GeneratedByNextcloudItself1', $requestId->getId());

0 commit comments

Comments
 (0)