Skip to content

Commit efb6411

Browse files
authored
Merge pull request #33732 from nextcloud/fix/remove-at-matcher-in-lib-tests-2
2 parents 702ae46 + 6f80fe6 commit efb6411

11 files changed

Lines changed: 405 additions & 475 deletions

File tree

tests/lib/L10N/FactoryTest.php

Lines changed: 41 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -146,20 +146,21 @@ public function testFindLanguageWithNotExistingRequestLanguageAndExistingStoredU
146146
public function testFindLanguageWithNotExistingRequestLanguageAndNotExistingStoredUserLanguage(): void {
147147
$factory = $this->getFactory(['languageExists'], true);
148148
$this->invokePrivate($factory, 'requestLanguage', ['de']);
149-
$factory->expects(self::at(0))
150-
->method('languageExists')
151-
->with('MyApp', 'de')
152-
->willReturn(false);
149+
$factory->expects($this->exactly(3))
150+
->method('languageExists')
151+
->willReturnMap([
152+
['MyApp', 'de', false],
153+
['MyApp', 'jp', false],
154+
['MyApp', 'es', true],
155+
]);
153156
$this->config
154-
->expects(self::at(0))
157+
->expects($this->exactly(3))
155158
->method('getSystemValue')
156-
->with('force_language', false)
157-
->willReturn(false);
158-
$this->config
159-
->expects(self::at(1))
160-
->method('getSystemValue')
161-
->with('installed', false)
162-
->willReturn(true);
159+
->willReturnMap([
160+
['force_language', false, false],
161+
['installed', false, true],
162+
['default_language', false, 'es']
163+
]);
163164
$user = $this->getMockBuilder(IUser::class)
164165
->getMock();
165166
$user->expects(self::once())
@@ -174,40 +175,28 @@ public function testFindLanguageWithNotExistingRequestLanguageAndNotExistingStor
174175
->method('getUserValue')
175176
->with('MyUserUid', 'core', 'lang', null)
176177
->willReturn('jp');
177-
$factory->expects(self::at(1))
178-
->method('languageExists')
179-
->with('MyApp', 'jp')
180-
->willReturn(false);
181-
$this->config
182-
->expects(self::at(3))
183-
->method('getSystemValue')
184-
->with('default_language', false)
185-
->willReturn('es');
186-
$factory->expects(self::at(2))
187-
->method('languageExists')
188-
->with('MyApp', 'es')
189-
->willReturn(true);
190178

191179
self::assertSame('es', $factory->findLanguage('MyApp'));
192180
}
193181

194182
public function testFindLanguageWithNotExistingRequestLanguageAndNotExistingStoredUserLanguageAndNotExistingDefault(): void {
195183
$factory = $this->getFactory(['languageExists'], true);
196184
$this->invokePrivate($factory, 'requestLanguage', ['de']);
197-
$factory->expects(self::at(0))
198-
->method('languageExists')
199-
->with('MyApp', 'de')
200-
->willReturn(false);
185+
$factory->expects($this->exactly(3))
186+
->method('languageExists')
187+
->willReturnMap([
188+
['MyApp', 'de', false],
189+
['MyApp', 'jp', false],
190+
['MyApp', 'es', false],
191+
]);
201192
$this->config
202-
->expects(self::at(0))
193+
->expects($this->exactly(3))
203194
->method('getSystemValue')
204-
->with('force_language', false)
205-
->willReturn(false);
206-
$this->config
207-
->expects(self::at(1))
208-
->method('getSystemValue')
209-
->with('installed', false)
210-
->willReturn(true);
195+
->willReturnMap([
196+
['force_language', false, false],
197+
['installed', false, true],
198+
['default_language', false, 'es']
199+
]);
211200
$user = $this->getMockBuilder(IUser::class)
212201
->getMock();
213202
$user->expects(self::once())
@@ -222,19 +211,6 @@ public function testFindLanguageWithNotExistingRequestLanguageAndNotExistingStor
222211
->method('getUserValue')
223212
->with('MyUserUid', 'core', 'lang', null)
224213
->willReturn('jp');
225-
$factory->expects(self::at(1))
226-
->method('languageExists')
227-
->with('MyApp', 'jp')
228-
->willReturn(false);
229-
$this->config
230-
->expects(self::at(3))
231-
->method('getSystemValue')
232-
->with('default_language', false)
233-
->willReturn('es');
234-
$factory->expects(self::at(2))
235-
->method('languageExists')
236-
->with('MyApp', 'es')
237-
->willReturn(false);
238214
$this->config
239215
->expects(self::never())
240216
->method('setUserValue');
@@ -245,20 +221,21 @@ public function testFindLanguageWithNotExistingRequestLanguageAndNotExistingStor
245221
public function testFindLanguageWithNotExistingRequestLanguageAndNotExistingStoredUserLanguageAndNotExistingDefaultAndNoAppInScope(): void {
246222
$factory = $this->getFactory(['languageExists'], true);
247223
$this->invokePrivate($factory, 'requestLanguage', ['de']);
248-
$factory->expects(self::at(0))
249-
->method('languageExists')
250-
->with('MyApp', 'de')
251-
->willReturn(false);
224+
$factory->expects($this->exactly(3))
225+
->method('languageExists')
226+
->willReturnMap([
227+
['MyApp', 'de', false],
228+
['MyApp', 'jp', false],
229+
['MyApp', 'es', false],
230+
]);
252231
$this->config
253-
->expects(self::at(0))
232+
->expects($this->exactly(3))
254233
->method('getSystemValue')
255-
->with('force_language', false)
256-
->willReturn(false);
257-
$this->config
258-
->expects(self::at(1))
259-
->method('getSystemValue')
260-
->with('installed', false)
261-
->willReturn(true);
234+
->willReturnMap([
235+
['force_language', false, false],
236+
['installed', false, true],
237+
['default_language', false, 'es']
238+
]);
262239
$user = $this->getMockBuilder(IUser::class)
263240
->getMock();
264241
$user->expects(self::once())
@@ -273,19 +250,6 @@ public function testFindLanguageWithNotExistingRequestLanguageAndNotExistingStor
273250
->method('getUserValue')
274251
->with('MyUserUid', 'core', 'lang', null)
275252
->willReturn('jp');
276-
$factory->expects(self::at(1))
277-
->method('languageExists')
278-
->with('MyApp', 'jp')
279-
->willReturn(false);
280-
$this->config
281-
->expects(self::at(3))
282-
->method('getSystemValue')
283-
->with('default_language', false)
284-
->willReturn('es');
285-
$factory->expects(self::at(2))
286-
->method('languageExists')
287-
->with('MyApp', 'es')
288-
->willReturn(false);
289253
$this->config
290254
->expects(self::never())
291255
->method('setUserValue')
@@ -298,12 +262,12 @@ public function testFindLanguageWithNotExistingRequestLanguageAndNotExistingStor
298262
public function testFindLanguageWithForcedLanguage(): void {
299263
$factory = $this->getFactory(['languageExists']);
300264
$this->config
301-
->expects(self::at(0))
265+
->expects($this->once())
302266
->method('getSystemValue')
303267
->with('force_language', false)
304268
->willReturn('de');
305269

306-
$factory->expects(self::once())
270+
$factory->expects($this->once())
307271
->method('languageExists')
308272
->with('MyApp', 'de')
309273
->willReturn(true);

tests/lib/Mail/MailerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public function testEvents() {
135135
$message = $this->createMock(Message::class);
136136

137137
$event = new BeforeMessageSent($message);
138-
$this->dispatcher->expects($this->at(0))
138+
$this->dispatcher->expects($this->once())
139139
->method('dispatchTyped')
140140
->with($this->equalTo($event));
141141

tests/lib/OCS/ProviderTest.php

Lines changed: 33 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,14 @@ protected function setUp(): void {
4141

4242
public function testBuildProviderListWithoutAnythingEnabled() {
4343
$this->appManager
44-
->expects($this->at(0))
44+
->expects($this->exactly(4))
4545
->method('isEnabledForUser')
46-
->with('files_sharing')
47-
->willReturn(false);
48-
$this->appManager
49-
->expects($this->at(1))
50-
->method('isEnabledForUser')
51-
->with('federation')
52-
->willReturn(false);
53-
$this->appManager
54-
->expects($this->at(2))
55-
->method('isEnabledForUser')
56-
->with('activity')
57-
->willReturn(false);
58-
$this->appManager
59-
->expects($this->at(3))
60-
->method('isEnabledForUser')
61-
->with('provisioning_api')
46+
->withConsecutive(
47+
['files_sharing'],
48+
['federation'],
49+
['activity'],
50+
['provisioning_api']
51+
)
6252
->willReturn(false);
6353

6454
$expected = new \OCP\AppFramework\Http\JSONResponse(
@@ -82,25 +72,20 @@ public function testBuildProviderListWithoutAnythingEnabled() {
8272

8373
public function testBuildProviderListWithSharingEnabled() {
8474
$this->appManager
85-
->expects($this->at(0))
86-
->method('isEnabledForUser')
87-
->with('files_sharing')
88-
->willReturn(true);
89-
$this->appManager
90-
->expects($this->at(1))
91-
->method('isEnabledForUser')
92-
->with('federation')
93-
->willReturn(false);
94-
$this->appManager
95-
->expects($this->at(2))
75+
->expects($this->exactly(4))
9676
->method('isEnabledForUser')
97-
->with('activity')
98-
->willReturn(false);
99-
$this->appManager
100-
->expects($this->at(3))
101-
->method('isEnabledForUser')
102-
->with('provisioning_api')
103-
->willReturn(false);
77+
->withConsecutive(
78+
['files_sharing'],
79+
['federation'],
80+
['activity'],
81+
['provisioning_api']
82+
)
83+
->willReturnOnConsecutiveCalls(
84+
true,
85+
false,
86+
false,
87+
false
88+
);
10489

10590
$expected = new \OCP\AppFramework\Http\JSONResponse(
10691
[
@@ -136,25 +121,20 @@ public function testBuildProviderListWithSharingEnabled() {
136121

137122
public function testBuildProviderListWithFederationEnabled() {
138123
$this->appManager
139-
->expects($this->at(0))
140-
->method('isEnabledForUser')
141-
->with('files_sharing')
142-
->willReturn(false);
143-
$this->appManager
144-
->expects($this->at(1))
124+
->expects($this->exactly(4))
145125
->method('isEnabledForUser')
146-
->with('federation')
147-
->willReturn(true);
148-
$this->appManager
149-
->expects($this->at(2))
150-
->method('isEnabledForUser')
151-
->with('activity')
152-
->willReturn(false);
153-
$this->appManager
154-
->expects($this->at(3))
155-
->method('isEnabledForUser')
156-
->with('provisioning_api')
157-
->willReturn(false);
126+
->withConsecutive(
127+
['files_sharing'],
128+
['federation'],
129+
['activity'],
130+
['provisioning_api']
131+
)
132+
->willReturnOnConsecutiveCalls(
133+
false,
134+
true,
135+
false,
136+
false
137+
);
158138

159139
$expected = new \OCP\AppFramework\Http\JSONResponse(
160140
[

tests/lib/Repair/ClearFrontendCachesTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function testRun() {
6161
->with('');
6262
$this->jsCombiner->expects($this->once())
6363
->method('resetCache');
64-
$this->cacheFactory->expects($this->at(0))
64+
$this->cacheFactory->expects($this->once())
6565
->method('createDistributed')
6666
->with('imagePath')
6767
->willReturn($imagePathCache);

tests/lib/Repair/NC11/FixMountStoragesTest.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,17 @@ public function testRun() {
7070

7171
/** @var IOutput|\PHPUnit\Framework\MockObject\MockObject $output */
7272
$output = $this->createMock(IOutput::class);
73-
$output->expects($this->at(0))
73+
$output->expects($this->exactly(2))
7474
->method('info')
75-
->with('1 mounts updated');
75+
->withConsecutive(
76+
['1 mounts updated'],
77+
['No mounts updated']
78+
);
7679

7780
$this->repair->run($output);
7881
$this->assertStorage($mount1, 42);
7982
$this->assertStorage($mount2, 23);
8083

81-
$output->expects($this->at(0))
82-
->method('info')
83-
->with('No mounts updated');
84-
8584
$this->repair->run($output);
8685
$this->assertStorage($mount1, 42);
8786
$this->assertStorage($mount2, 23);

tests/lib/Security/CertificateManagerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public function testNeedRebundling($CaBundleMtime,
163163
$certificateManager->expects($this->any())->method('getFilemtimeOfCaBundle')
164164
->willReturn($CaBundleMtime);
165165

166-
$certificateManager->expects($this->at(0))->method('getCertificateBundle')
166+
$certificateManager->expects($this->once())->method('getCertificateBundle')
167167
->willReturn('targetBundlePath');
168168

169169
$view->expects($this->any())->method('file_exists')

0 commit comments

Comments
 (0)