Skip to content

Commit

Permalink
Merge pull request #33732 from nextcloud/fix/remove-at-matcher-in-lib…
Browse files Browse the repository at this point in the history
…-tests-2
  • Loading branch information
skjnldsv authored Aug 30, 2022
2 parents 702ae46 + 6f80fe6 commit efb6411
Show file tree
Hide file tree
Showing 11 changed files with 405 additions and 475 deletions.
118 changes: 41 additions & 77 deletions tests/lib/L10N/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,20 +146,21 @@ public function testFindLanguageWithNotExistingRequestLanguageAndExistingStoredU
public function testFindLanguageWithNotExistingRequestLanguageAndNotExistingStoredUserLanguage(): void {
$factory = $this->getFactory(['languageExists'], true);
$this->invokePrivate($factory, 'requestLanguage', ['de']);
$factory->expects(self::at(0))
->method('languageExists')
->with('MyApp', 'de')
->willReturn(false);
$factory->expects($this->exactly(3))
->method('languageExists')
->willReturnMap([
['MyApp', 'de', false],
['MyApp', 'jp', false],
['MyApp', 'es', true],
]);
$this->config
->expects(self::at(0))
->expects($this->exactly(3))
->method('getSystemValue')
->with('force_language', false)
->willReturn(false);
$this->config
->expects(self::at(1))
->method('getSystemValue')
->with('installed', false)
->willReturn(true);
->willReturnMap([
['force_language', false, false],
['installed', false, true],
['default_language', false, 'es']
]);
$user = $this->getMockBuilder(IUser::class)
->getMock();
$user->expects(self::once())
Expand All @@ -174,40 +175,28 @@ public function testFindLanguageWithNotExistingRequestLanguageAndNotExistingStor
->method('getUserValue')
->with('MyUserUid', 'core', 'lang', null)
->willReturn('jp');
$factory->expects(self::at(1))
->method('languageExists')
->with('MyApp', 'jp')
->willReturn(false);
$this->config
->expects(self::at(3))
->method('getSystemValue')
->with('default_language', false)
->willReturn('es');
$factory->expects(self::at(2))
->method('languageExists')
->with('MyApp', 'es')
->willReturn(true);

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

public function testFindLanguageWithNotExistingRequestLanguageAndNotExistingStoredUserLanguageAndNotExistingDefault(): void {
$factory = $this->getFactory(['languageExists'], true);
$this->invokePrivate($factory, 'requestLanguage', ['de']);
$factory->expects(self::at(0))
->method('languageExists')
->with('MyApp', 'de')
->willReturn(false);
$factory->expects($this->exactly(3))
->method('languageExists')
->willReturnMap([
['MyApp', 'de', false],
['MyApp', 'jp', false],
['MyApp', 'es', false],
]);
$this->config
->expects(self::at(0))
->expects($this->exactly(3))
->method('getSystemValue')
->with('force_language', false)
->willReturn(false);
$this->config
->expects(self::at(1))
->method('getSystemValue')
->with('installed', false)
->willReturn(true);
->willReturnMap([
['force_language', false, false],
['installed', false, true],
['default_language', false, 'es']
]);
$user = $this->getMockBuilder(IUser::class)
->getMock();
$user->expects(self::once())
Expand All @@ -222,19 +211,6 @@ public function testFindLanguageWithNotExistingRequestLanguageAndNotExistingStor
->method('getUserValue')
->with('MyUserUid', 'core', 'lang', null)
->willReturn('jp');
$factory->expects(self::at(1))
->method('languageExists')
->with('MyApp', 'jp')
->willReturn(false);
$this->config
->expects(self::at(3))
->method('getSystemValue')
->with('default_language', false)
->willReturn('es');
$factory->expects(self::at(2))
->method('languageExists')
->with('MyApp', 'es')
->willReturn(false);
$this->config
->expects(self::never())
->method('setUserValue');
Expand All @@ -245,20 +221,21 @@ public function testFindLanguageWithNotExistingRequestLanguageAndNotExistingStor
public function testFindLanguageWithNotExistingRequestLanguageAndNotExistingStoredUserLanguageAndNotExistingDefaultAndNoAppInScope(): void {
$factory = $this->getFactory(['languageExists'], true);
$this->invokePrivate($factory, 'requestLanguage', ['de']);
$factory->expects(self::at(0))
->method('languageExists')
->with('MyApp', 'de')
->willReturn(false);
$factory->expects($this->exactly(3))
->method('languageExists')
->willReturnMap([
['MyApp', 'de', false],
['MyApp', 'jp', false],
['MyApp', 'es', false],
]);
$this->config
->expects(self::at(0))
->expects($this->exactly(3))
->method('getSystemValue')
->with('force_language', false)
->willReturn(false);
$this->config
->expects(self::at(1))
->method('getSystemValue')
->with('installed', false)
->willReturn(true);
->willReturnMap([
['force_language', false, false],
['installed', false, true],
['default_language', false, 'es']
]);
$user = $this->getMockBuilder(IUser::class)
->getMock();
$user->expects(self::once())
Expand All @@ -273,19 +250,6 @@ public function testFindLanguageWithNotExistingRequestLanguageAndNotExistingStor
->method('getUserValue')
->with('MyUserUid', 'core', 'lang', null)
->willReturn('jp');
$factory->expects(self::at(1))
->method('languageExists')
->with('MyApp', 'jp')
->willReturn(false);
$this->config
->expects(self::at(3))
->method('getSystemValue')
->with('default_language', false)
->willReturn('es');
$factory->expects(self::at(2))
->method('languageExists')
->with('MyApp', 'es')
->willReturn(false);
$this->config
->expects(self::never())
->method('setUserValue')
Expand All @@ -298,12 +262,12 @@ public function testFindLanguageWithNotExistingRequestLanguageAndNotExistingStor
public function testFindLanguageWithForcedLanguage(): void {
$factory = $this->getFactory(['languageExists']);
$this->config
->expects(self::at(0))
->expects($this->once())
->method('getSystemValue')
->with('force_language', false)
->willReturn('de');

$factory->expects(self::once())
$factory->expects($this->once())
->method('languageExists')
->with('MyApp', 'de')
->willReturn(true);
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/Mail/MailerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public function testEvents() {
$message = $this->createMock(Message::class);

$event = new BeforeMessageSent($message);
$this->dispatcher->expects($this->at(0))
$this->dispatcher->expects($this->once())
->method('dispatchTyped')
->with($this->equalTo($event));

Expand Down
86 changes: 33 additions & 53 deletions tests/lib/OCS/ProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,14 @@ protected function setUp(): void {

public function testBuildProviderListWithoutAnythingEnabled() {
$this->appManager
->expects($this->at(0))
->expects($this->exactly(4))
->method('isEnabledForUser')
->with('files_sharing')
->willReturn(false);
$this->appManager
->expects($this->at(1))
->method('isEnabledForUser')
->with('federation')
->willReturn(false);
$this->appManager
->expects($this->at(2))
->method('isEnabledForUser')
->with('activity')
->willReturn(false);
$this->appManager
->expects($this->at(3))
->method('isEnabledForUser')
->with('provisioning_api')
->withConsecutive(
['files_sharing'],
['federation'],
['activity'],
['provisioning_api']
)
->willReturn(false);

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

public function testBuildProviderListWithSharingEnabled() {
$this->appManager
->expects($this->at(0))
->method('isEnabledForUser')
->with('files_sharing')
->willReturn(true);
$this->appManager
->expects($this->at(1))
->method('isEnabledForUser')
->with('federation')
->willReturn(false);
$this->appManager
->expects($this->at(2))
->expects($this->exactly(4))
->method('isEnabledForUser')
->with('activity')
->willReturn(false);
$this->appManager
->expects($this->at(3))
->method('isEnabledForUser')
->with('provisioning_api')
->willReturn(false);
->withConsecutive(
['files_sharing'],
['federation'],
['activity'],
['provisioning_api']
)
->willReturnOnConsecutiveCalls(
true,
false,
false,
false
);

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

public function testBuildProviderListWithFederationEnabled() {
$this->appManager
->expects($this->at(0))
->method('isEnabledForUser')
->with('files_sharing')
->willReturn(false);
$this->appManager
->expects($this->at(1))
->expects($this->exactly(4))
->method('isEnabledForUser')
->with('federation')
->willReturn(true);
$this->appManager
->expects($this->at(2))
->method('isEnabledForUser')
->with('activity')
->willReturn(false);
$this->appManager
->expects($this->at(3))
->method('isEnabledForUser')
->with('provisioning_api')
->willReturn(false);
->withConsecutive(
['files_sharing'],
['federation'],
['activity'],
['provisioning_api']
)
->willReturnOnConsecutiveCalls(
false,
true,
false,
false
);

$expected = new \OCP\AppFramework\Http\JSONResponse(
[
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/Repair/ClearFrontendCachesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function testRun() {
->with('');
$this->jsCombiner->expects($this->once())
->method('resetCache');
$this->cacheFactory->expects($this->at(0))
$this->cacheFactory->expects($this->once())
->method('createDistributed')
->with('imagePath')
->willReturn($imagePathCache);
Expand Down
11 changes: 5 additions & 6 deletions tests/lib/Repair/NC11/FixMountStoragesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,17 @@ public function testRun() {

/** @var IOutput|\PHPUnit\Framework\MockObject\MockObject $output */
$output = $this->createMock(IOutput::class);
$output->expects($this->at(0))
$output->expects($this->exactly(2))
->method('info')
->with('1 mounts updated');
->withConsecutive(
['1 mounts updated'],
['No mounts updated']
);

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

$output->expects($this->at(0))
->method('info')
->with('No mounts updated');

$this->repair->run($output);
$this->assertStorage($mount1, 42);
$this->assertStorage($mount2, 23);
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/Security/CertificateManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public function testNeedRebundling($CaBundleMtime,
$certificateManager->expects($this->any())->method('getFilemtimeOfCaBundle')
->willReturn($CaBundleMtime);

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

$view->expects($this->any())->method('file_exists')
Expand Down
Loading

0 comments on commit efb6411

Please sign in to comment.