Skip to content

Commit

Permalink
Fix a bunch of deprecation in the phpunit for core
Browse files Browse the repository at this point in the history
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
  • Loading branch information
CarlSchwan committed May 24, 2022
1 parent 45a75c6 commit 01f156a
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 52 deletions.
2 changes: 1 addition & 1 deletion tests/Core/Command/Apps/AppsDisableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function testCommandInput($appId, $statusCode, $pattern): void {

$this->commandTester->execute($input);

$this->assertRegExp('/' . $pattern . '/', $this->commandTester->getDisplay());
$this->assertMatchesRegularExpression('/' . $pattern . '/', $this->commandTester->getDisplay());
$this->assertSame($statusCode, $this->commandTester->getStatusCode());
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Core/Command/Apps/AppsEnableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function testCommandInput($appId, $groups, $statusCode, $pattern): void {

$this->commandTester->execute($input);

$this->assertRegExp('/' . $pattern . '/', $this->commandTester->getDisplay());
$this->assertMatchesRegularExpression('/' . $pattern . '/', $this->commandTester->getDisplay());
$this->assertSame($statusCode, $this->commandTester->getStatusCode());
}

Expand Down
58 changes: 28 additions & 30 deletions tests/Core/Controller/LoginControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,27 +258,30 @@ public function testShowLoginFormWithErrorsInSession() {
],
]
);
$this->initialStateService->expects($this->at(0))
$this->initialStateService->expects($this->exactly(10))
->method('provideInitialState')
->with(
->withConsecutive([
'core',
'loginMessages',
[
'MessageArray1',
'MessageArray2',
'This community release of Nextcloud is unsupported and instant notifications are unavailable.',
]
);
$this->initialStateService->expects($this->at(1))
->method('provideInitialState')
->with(
],
],
[
'core',
'loginErrors',
[
'ErrorArray1',
'ErrorArray2',
]
);
],
],
[
'core',
'loginUsername',
'',
]);

$expectedResponse = new TemplateResponse(
'core',
Expand All @@ -296,13 +299,17 @@ public function testShowLoginFormForFlowAuth() {
->expects($this->once())
->method('isLoggedIn')
->willReturn(false);
$this->initialStateService->expects($this->at(4))
$this->initialStateService->expects($this->exactly(11))
->method('provideInitialState')
->with(
->withConsecutive([], [], [], [
'core',
'loginAutocomplete',
false
], [
'core',
'loginRedirectUrl',
'login/flow'
);
]);

$expectedResponse = new TemplateResponse(
'core',
Expand Down Expand Up @@ -357,20 +364,17 @@ public function testShowLoginFormWithPasswordResetOption($canChangePassword,
->method('get')
->with('LdapUser')
->willReturn($user);
$this->initialStateService->expects($this->at(2))
$this->initialStateService->expects($this->exactly(10))
->method('provideInitialState')
->with(
->withConsecutive([], [], [
'core',
'loginUsername',
'LdapUser'
);
$this->initialStateService->expects($this->at(6))
->method('provideInitialState')
->with(
], [], [], [], [
'core',
'loginCanResetPassword',
$expectedResult
);
]);

$expectedResponse = new TemplateResponse(
'core',
Expand Down Expand Up @@ -404,27 +408,21 @@ public function testShowLoginFormForUserNamed0() {
->method('get')
->with('0')
->willReturn($user);
$this->initialStateService->expects($this->at(3))
$this->initialStateService->expects($this->exactly(10))
->method('provideInitialState')
->with(
->withConsecutive([], [], [], [
'core',
'loginAutocomplete',
true
);
$this->initialStateService->expects($this->at(5))
->method('provideInitialState')
->with(
], [], [
'core',
'loginResetPasswordLink',
false
);
$this->initialStateService->expects($this->at(6))
->method('provideInitialState')
->with(
], [
'core',
'loginCanResetPassword',
false
);
]);

$expectedResponse = new TemplateResponse(
'core',
Expand Down
29 changes: 15 additions & 14 deletions tests/Core/Controller/NavigationControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,13 @@ public function testGetAppNavigation($absolute) {
$this->urlGenerator->expects($this->any())
->method('getBaseURL')
->willReturn('http://localhost/');
$this->urlGenerator->expects($this->at(1))
$this->urlGenerator->expects($this->exactly(2))
->method('getAbsoluteURL')
->with('/index.php/apps/files')
->willReturn('http://localhost/index.php/apps/files');
$this->urlGenerator->expects($this->at(3))
->method('getAbsoluteURL')
->with('icon')
->willReturn('http://localhost/icon');
->withConsecutive(['/index.php/apps/files'], ['icon'])
->willReturnOnConsecutiveCalls(
'http://localhost/index.php/apps/files',
'http://localhost/icon'
);
$actual = $this->controller->getAppsNavigation($absolute);
$this->assertInstanceOf(DataResponse::class, $actual);
$this->assertEquals('http://localhost/index.php/apps/files', $actual->getData()[0]['href']);
Expand All @@ -105,14 +104,16 @@ public function testGetSettingsNavigation($absolute) {
$this->urlGenerator->expects($this->any())
->method('getBaseURL')
->willReturn('http://localhost/');
$this->urlGenerator->expects($this->at(1))
->method('getAbsoluteURL')
->with('/index.php/settings/user')
->willReturn('http://localhost/index.php/settings/user');
$this->urlGenerator->expects($this->at(3))
$this->urlGenerator->expects($this->exactly(2))
->method('getAbsoluteURL')
->with('/core/img/settings.svg')
->willReturn('http://localhost/core/img/settings.svg');
->withConsecutive(
['/index.php/settings/user'],
['/core/img/settings.svg']
)
->willReturnOnConsecutiveCalls(
'http://localhost/index.php/settings/user',
'http://localhost/core/img/settings.svg'
);
$actual = $this->controller->getSettingsNavigation($absolute);
$this->assertInstanceOf(DataResponse::class, $actual);
$this->assertEquals('http://localhost/index.php/settings/user', $actual->getData()[0]['href']);
Expand Down
10 changes: 5 additions & 5 deletions tests/Core/Controller/TwoFactorChallengeControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,12 +317,12 @@ public function testSolveChallengeTwoFactorException() {
->method('verifyChallenge')
->with('myprovider', $user, 'token')
->will($this->throwException($exception));
$this->session->expects($this->at(0))
->method('set')
->with('two_factor_auth_error_message', "2FA failed");
$this->session->expects($this->at(1))
$this->session->expects($this->exactly(2))
->method('set')
->with('two_factor_auth_error', true);
->withConsecutive(
['two_factor_auth_error_message', '2FA failed'],
['two_factor_auth_error', true]
);
$this->urlGenerator->expects($this->once())
->method('linkToRoute')
->with('core.TwoFactorChallenge.showChallenge', [
Expand Down
2 changes: 1 addition & 1 deletion tests/Core/Service/LoginFlowV2ServiceUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ public function testFlowDone() {

// app password is encrypted and must look like:
// ZACZOOzxTpKz4+KXL5kZ/gCK0xvkaVi/8yzupAn6Ui6+5qCSKvfPKGgeDRKs0sivvSLzk/XSp811SZCZmH0Y3g==
$this->assertRegExp('/[a-zA-Z\/0-9+=]+/', $loginFlowV2->getAppPassword());
$this->assertMatchesRegularExpression('/[a-zA-Z\/0-9+=]+/', $loginFlowV2->getAppPassword());

$this->assertEquals('server', $loginFlowV2->getServer());
}
Expand Down

0 comments on commit 01f156a

Please sign in to comment.