diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2020-03-25 22:21:27 +0100 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2020-03-25 22:21:27 +0100 |
commit | 2ee65f177e4f7e09ad2287f14d564e7068d322fb (patch) | |
tree | 39075e87ea7927e20e8956824cb7c49bf626b178 /tests/Core | |
parent | 3cf321fdfc4235a87015a9af2f59c63220016c65 (diff) | |
download | nextcloud-server-2ee65f177e4f7e09ad2287f14d564e7068d322fb.tar.gz nextcloud-server-2ee65f177e4f7e09ad2287f14d564e7068d322fb.zip |
Use the shorter phpunit syntax for mocked return values
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'tests/Core')
-rw-r--r-- | tests/Core/Command/Config/System/SetConfigTest.php | 8 | ||||
-rw-r--r-- | tests/Core/Command/Log/FileTest.php | 16 | ||||
-rw-r--r-- | tests/Core/Command/Log/ManageTest.php | 12 | ||||
-rw-r--r-- | tests/Core/Command/Maintenance/Mimetype/UpdateDBTest.php | 16 | ||||
-rw-r--r-- | tests/Core/Controller/AvatarControllerTest.php | 2 | ||||
-rw-r--r-- | tests/Core/Controller/ChangePasswordControllerTest.php | 2 | ||||
-rw-r--r-- | tests/Core/Controller/ClientFlowLoginControllerTest.php | 4 | ||||
-rw-r--r-- | tests/Core/Controller/ClientFlowLoginV2ControllerTest.php | 28 | ||||
-rw-r--r-- | tests/Core/Controller/CssControllerTest.php | 4 | ||||
-rw-r--r-- | tests/Core/Controller/JsControllerTest.php | 4 | ||||
-rw-r--r-- | tests/Core/Controller/LoginControllerTest.php | 24 | ||||
-rw-r--r-- | tests/Core/Controller/LostControllerTest.php | 56 | ||||
-rw-r--r-- | tests/Core/Controller/TwoFactorChallengeControllerTest.php | 64 | ||||
-rw-r--r-- | tests/Core/Controller/UserControllerTest.php | 4 | ||||
-rw-r--r-- | tests/Core/Middleware/TwoFactorMiddlewareTest.php | 40 |
15 files changed, 142 insertions, 142 deletions
diff --git a/tests/Core/Command/Config/System/SetConfigTest.php b/tests/Core/Command/Config/System/SetConfigTest.php index 9b34afed691..1ed7cf2758f 100644 --- a/tests/Core/Command/Config/System/SetConfigTest.php +++ b/tests/Core/Command/Config/System/SetConfigTest.php @@ -83,10 +83,10 @@ class SetConfigTest extends TestCase { ->with('name') ->willReturn($configNames); $this->consoleInput->method('getOption') - ->will($this->returnValueMap([ + ->willReturnMap([ ['value', $newValue], ['type', 'string'], - ])); + ]); $this->invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); } @@ -119,11 +119,11 @@ class SetConfigTest extends TestCase { ->with('name') ->willReturn($configNames); $this->consoleInput->method('getOption') - ->will($this->returnValueMap([ + ->willReturnMap([ ['value', 'foobar'], ['type', 'string'], ['update-only', true], - ])); + ]); $this->invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); } diff --git a/tests/Core/Command/Log/FileTest.php b/tests/Core/Command/Log/FileTest.php index 524a193d86f..c1d005e0c56 100644 --- a/tests/Core/Command/Log/FileTest.php +++ b/tests/Core/Command/Log/FileTest.php @@ -53,9 +53,9 @@ class FileTest extends TestCase { public function testEnable() { $this->consoleInput->method('getOption') - ->will($this->returnValueMap([ + ->willReturnMap([ ['enable', 'true'] - ])); + ]); $this->config->expects($this->once()) ->method('setSystemValue') ->with('log_type', 'file'); @@ -65,9 +65,9 @@ class FileTest extends TestCase { public function testChangeFile() { $this->consoleInput->method('getOption') - ->will($this->returnValueMap([ + ->willReturnMap([ ['file', '/foo/bar/file.log'] - ])); + ]); $this->config->expects($this->once()) ->method('setSystemValue') ->with('logfile', '/foo/bar/file.log'); @@ -89,9 +89,9 @@ class FileTest extends TestCase { */ public function testChangeRotateSize($optionValue, $configValue) { $this->consoleInput->method('getOption') - ->will($this->returnValueMap([ + ->willReturnMap([ ['rotate-size', $optionValue] - ])); + ]); $this->config->expects($this->once()) ->method('setSystemValue') ->with('log_rotate_size', $configValue); @@ -101,12 +101,12 @@ class FileTest extends TestCase { public function testGetConfiguration() { $this->config->method('getSystemValue') - ->will($this->returnValueMap([ + ->willReturnMap([ ['log_type', 'file', 'log_type_value'], ['datadirectory', \OC::$SERVERROOT.'/data', '/data/directory/'], ['logfile', '/data/directory/nextcloud.log', '/var/log/nextcloud.log'], ['log_rotate_size', 100 * 1024 * 1024, 5 * 1024 * 1024], - ])); + ]); $this->consoleOutput->expects($this->at(0)) ->method('writeln') diff --git a/tests/Core/Command/Log/ManageTest.php b/tests/Core/Command/Log/ManageTest.php index d73bc7ed9c2..cae6293abd1 100644 --- a/tests/Core/Command/Log/ManageTest.php +++ b/tests/Core/Command/Log/ManageTest.php @@ -53,9 +53,9 @@ class ManageTest extends TestCase { public function testChangeBackend() { $this->consoleInput->method('getOption') - ->will($this->returnValueMap([ + ->willReturnMap([ ['backend', 'syslog'] - ])); + ]); $this->config->expects($this->once()) ->method('setSystemValue') ->with('log_type', 'syslog'); @@ -65,9 +65,9 @@ class ManageTest extends TestCase { public function testChangeLevel() { $this->consoleInput->method('getOption') - ->will($this->returnValueMap([ + ->willReturnMap([ ['level', 'debug'] - ])); + ]); $this->config->expects($this->once()) ->method('setSystemValue') ->with('loglevel', 0); @@ -77,9 +77,9 @@ class ManageTest extends TestCase { public function testChangeTimezone() { $this->consoleInput->method('getOption') - ->will($this->returnValueMap([ + ->willReturnMap([ ['timezone', 'UTC'] - ])); + ]); $this->config->expects($this->once()) ->method('setSystemValue') ->with('logtimezone', 'UTC'); diff --git a/tests/Core/Command/Maintenance/Mimetype/UpdateDBTest.php b/tests/Core/Command/Maintenance/Mimetype/UpdateDBTest.php index 32608796864..d7238921af5 100644 --- a/tests/Core/Command/Maintenance/Mimetype/UpdateDBTest.php +++ b/tests/Core/Command/Maintenance/Mimetype/UpdateDBTest.php @@ -101,16 +101,16 @@ class UpdateDBTest extends TestCase { ]); $this->loader->expects($this->exactly(2)) ->method('exists') - ->will($this->returnValueMap([ + ->willReturnMap([ ['testing/existingmimetype', true], ['testing/newmimetype', false], - ])); + ]); $this->loader->expects($this->exactly(2)) ->method('getId') - ->will($this->returnValueMap([ + ->willReturnMap([ ['testing/existingmimetype', 1], ['testing/newmimetype', 2], - ])); + ]); $this->loader->expects($this->once()) ->method('updateFilecache') @@ -158,14 +158,14 @@ class UpdateDBTest extends TestCase { ]); $this->loader->expects($this->exactly(1)) ->method('exists') - ->will($this->returnValueMap([ + ->willReturnMap([ ['testing/existingmimetype', true], - ])); + ]); $this->loader->expects($this->exactly(1)) ->method('getId') - ->will($this->returnValueMap([ + ->willReturnMap([ ['testing/existingmimetype', 1], - ])); + ]); $this->loader->expects($this->once()) ->method('updateFilecache') diff --git a/tests/Core/Controller/AvatarControllerTest.php b/tests/Core/Controller/AvatarControllerTest.php index 5c66c06a2c5..d2ae9b036b9 100644 --- a/tests/Core/Controller/AvatarControllerTest.php +++ b/tests/Core/Controller/AvatarControllerTest.php @@ -92,7 +92,7 @@ class AvatarControllerTest extends \Test\TestCase { $this->cache = $this->getMockBuilder('OCP\ICache') ->disableOriginalConstructor()->getMock(); $this->l = $this->getMockBuilder(IL10N::class)->getMock(); - $this->l->method('t')->will($this->returnArgument(0)); + $this->l->method('t')->willReturnArgument(0); $this->userManager = $this->getMockBuilder(IUserManager::class)->getMock(); $this->request = $this->getMockBuilder(IRequest::class)->getMock(); $this->rootFolder = $this->getMockBuilder('OCP\Files\IRootFolder')->getMock(); diff --git a/tests/Core/Controller/ChangePasswordControllerTest.php b/tests/Core/Controller/ChangePasswordControllerTest.php index a55b0bc232e..175628552bc 100644 --- a/tests/Core/Controller/ChangePasswordControllerTest.php +++ b/tests/Core/Controller/ChangePasswordControllerTest.php @@ -57,7 +57,7 @@ class ChangePasswordControllerTest extends \Test\TestCase { $this->groupManager = $this->createMock(\OC\Group\Manager::class); $this->appManager = $this->createMock(IAppManager::class); $this->l = $this->createMock(IL10N::class); - $this->l->method('t')->will($this->returnArgument(0)); + $this->l->method('t')->willReturnArgument(0); /** @var IRequest|\PHPUnit_Framework_MockObject_MockObject $request */ $request = $this->createMock(IRequest::class); diff --git a/tests/Core/Controller/ClientFlowLoginControllerTest.php b/tests/Core/Controller/ClientFlowLoginControllerTest.php index 3932cb9e144..cd90918144d 100644 --- a/tests/Core/Controller/ClientFlowLoginControllerTest.php +++ b/tests/Core/Controller/ClientFlowLoginControllerTest.php @@ -83,9 +83,9 @@ class ClientFlowLoginControllerTest extends TestCase { $this->l10n ->expects($this->any()) ->method('t') - ->will($this->returnCallback(function($text, $parameters = array()) { + ->willReturnCallback(function($text, $parameters = array()) { return vsprintf($text, $parameters); - })); + }); $this->defaults = $this->createMock(Defaults::class); $this->session = $this->createMock(ISession::class); $this->tokenProvider = $this->createMock(IProvider::class); diff --git a/tests/Core/Controller/ClientFlowLoginV2ControllerTest.php b/tests/Core/Controller/ClientFlowLoginV2ControllerTest.php index 3c39a402f55..01c60dd7511 100644 --- a/tests/Core/Controller/ClientFlowLoginV2ControllerTest.php +++ b/tests/Core/Controller/ClientFlowLoginV2ControllerTest.php @@ -183,9 +183,9 @@ class ClientFlowLoginV2ControllerTest extends TestCase { public function testGrantPageInvalidStateToken() { $this->session->method('get') - ->will($this->returnCallback(function($name) { + ->willReturnCallback(function($name) { return null; - })); + }); $result = $this->controller->grantPage('stateToken'); $this->assertSame(Http::STATUS_FORBIDDEN, $result->getStatus()); @@ -193,7 +193,7 @@ class ClientFlowLoginV2ControllerTest extends TestCase { public function testGrantPageInvalidLoginToken() { $this->session->method('get') - ->will($this->returnCallback(function($name) { + ->willReturnCallback(function($name) { if ($name === 'client.flow.v2.state.token') { return 'stateToken'; } @@ -201,7 +201,7 @@ class ClientFlowLoginV2ControllerTest extends TestCase { return 'loginToken'; } return null; - })); + }); $this->loginFlowV2Service->method('getByLoginToken') ->with('loginToken') @@ -213,7 +213,7 @@ class ClientFlowLoginV2ControllerTest extends TestCase { public function testGrantPageValid() { $this->session->method('get') - ->will($this->returnCallback(function($name) { + ->willReturnCallback(function($name) { if ($name === 'client.flow.v2.state.token') { return 'stateToken'; } @@ -221,7 +221,7 @@ class ClientFlowLoginV2ControllerTest extends TestCase { return 'loginToken'; } return null; - })); + }); $flow = new LoginFlowV2(); $this->loginFlowV2Service->method('getByLoginToken') @@ -235,9 +235,9 @@ class ClientFlowLoginV2ControllerTest extends TestCase { public function testGenerateAppPasswordInvalidStateToken() { $this->session->method('get') - ->will($this->returnCallback(function($name) { + ->willReturnCallback(function($name) { return null; - })); + }); $result = $this->controller->generateAppPassword('stateToken'); $this->assertSame(Http::STATUS_FORBIDDEN, $result->getStatus()); @@ -245,7 +245,7 @@ class ClientFlowLoginV2ControllerTest extends TestCase { public function testGenerateAppPassworInvalidLoginToken() { $this->session->method('get') - ->will($this->returnCallback(function($name) { + ->willReturnCallback(function($name) { if ($name === 'client.flow.v2.state.token') { return 'stateToken'; } @@ -253,7 +253,7 @@ class ClientFlowLoginV2ControllerTest extends TestCase { return 'loginToken'; } return null; - })); + }); $this->loginFlowV2Service->method('getByLoginToken') ->with('loginToken') @@ -265,7 +265,7 @@ class ClientFlowLoginV2ControllerTest extends TestCase { public function testGenerateAppPassworValid() { $this->session->method('get') - ->will($this->returnCallback(function($name) { + ->willReturnCallback(function($name) { if ($name === 'client.flow.v2.state.token') { return 'stateToken'; } @@ -273,7 +273,7 @@ class ClientFlowLoginV2ControllerTest extends TestCase { return 'loginToken'; } return null; - })); + }); $flow = new LoginFlowV2(); $this->loginFlowV2Service->method('getByLoginToken') @@ -283,14 +283,14 @@ class ClientFlowLoginV2ControllerTest extends TestCase { $clearedState = false; $clearedLogin = false; $this->session->method('remove') - ->will($this->returnCallback(function ($name) use (&$clearedLogin, &$clearedState) { + ->willReturnCallback(function ($name) use (&$clearedLogin, &$clearedState) { if ($name === 'client.flow.v2.state.token') { $clearedState = true; } if ($name === 'client.flow.v2.login.token') { $clearedLogin = true; } - })); + }); $this->session->method('getId') ->willReturn('sessionId'); diff --git a/tests/Core/Controller/CssControllerTest.php b/tests/Core/Controller/CssControllerTest.php index c0d1ea42f41..daccee82705 100644 --- a/tests/Core/Controller/CssControllerTest.php +++ b/tests/Core/Controller/CssControllerTest.php @@ -158,13 +158,13 @@ class CssControllerTest extends TestCase { ->willReturn($folder); $folder->method('getFile') - ->will($this->returnCallback( + ->willReturnCallback( function($fileName) use ($file) { if ($fileName === 'file.css') { return $file; } throw new NotFoundException(); - }) + } ); $this->request->method('getHeader') diff --git a/tests/Core/Controller/JsControllerTest.php b/tests/Core/Controller/JsControllerTest.php index 26df6d181ef..4476b3ee6ed 100644 --- a/tests/Core/Controller/JsControllerTest.php +++ b/tests/Core/Controller/JsControllerTest.php @@ -158,13 +158,13 @@ class JsControllerTest extends TestCase { ->willReturn($folder); $folder->method('getFile') - ->will($this->returnCallback( + ->willReturnCallback( function($fileName) use ($file) { if ($fileName === 'file.js') { return $file; } throw new NotFoundException(); - }) + } ); $this->request->method('getHeader') diff --git a/tests/Core/Controller/LoginControllerTest.php b/tests/Core/Controller/LoginControllerTest.php index 6a6795a8e82..cddf89527db 100644 --- a/tests/Core/Controller/LoginControllerTest.php +++ b/tests/Core/Controller/LoginControllerTest.php @@ -315,10 +315,10 @@ class LoginControllerTest extends TestCase { $this->config ->expects($this->exactly(2)) ->method('getSystemValue') - ->will($this->returnValueMap([ + ->willReturnMap([ ['login_form_autocomplete', true, true], ['lost_password_link', '', false], - ])); + ]); $user = $this->createMock(IUser::class); $user ->expects($this->once()) @@ -363,10 +363,10 @@ class LoginControllerTest extends TestCase { $this->config ->expects($this->exactly(2)) ->method('getSystemValue') - ->will($this->returnValueMap([ + ->willReturnMap([ ['login_form_autocomplete', true, true], ['lost_password_link', '', false], - ])); + ]); $user = $this->createMock(IUser::class); $user->expects($this->once()) ->method('canChangePassword') @@ -435,7 +435,7 @@ class LoginControllerTest extends TestCase { 'user' => $user, 'redirect_url' => '/apps/files', ]) - ->will($this->returnValue($loginPageUrl)); + ->willReturn($loginPageUrl); $expected = new \OCP\AppFramework\Http\RedirectResponse($loginPageUrl); $expected->throttle(['user' => 'MyUserName']); @@ -475,7 +475,7 @@ class LoginControllerTest extends TestCase { $user = $this->createMock(IUser::class); $user->expects($this->any()) ->method('getUID') - ->will($this->returnValue('jane')); + ->willReturn('jane'); $password = 'secret'; $originalUrl = 'another%20url'; @@ -486,7 +486,7 @@ class LoginControllerTest extends TestCase { $this->userSession->expects($this->once()) ->method('isLoggedIn') ->with() - ->will($this->returnValue(false)); + ->willReturn(false); $this->config->expects($this->never()) ->method('deleteUserValue'); $this->userSession->expects($this->never()) @@ -501,7 +501,7 @@ class LoginControllerTest extends TestCase { $user = $this->createMock(IUser::class); $user->expects($this->any()) ->method('getUID') - ->will($this->returnValue('jane')); + ->willReturn('jane'); $password = 'secret'; $originalUrl = 'another%20url'; $redirectUrl = 'http://localhost/another url'; @@ -513,11 +513,11 @@ class LoginControllerTest extends TestCase { $this->userSession->expects($this->once()) ->method('isLoggedIn') ->with() - ->will($this->returnValue(true)); + ->willReturn(true); $this->urlGenerator->expects($this->once()) ->method('getAbsoluteURL') ->with(urldecode($originalUrl)) - ->will($this->returnValue($redirectUrl)); + ->willReturn($redirectUrl); $this->config->expects($this->never()) ->method('deleteUserValue'); $this->userSession->expects($this->never()) @@ -558,7 +558,7 @@ class LoginControllerTest extends TestCase { $this->urlGenerator->expects($this->once()) ->method('getAbsoluteURL') ->with(urldecode('/apps/mail')) - ->will($this->returnValue($redirectUrl)); + ->willReturn($redirectUrl); $expected = new \OCP\AppFramework\Http\RedirectResponse($redirectUrl); $response = $this->loginController->tryLogin($user, $password, '%2Fapps%2Fmail'); @@ -592,7 +592,7 @@ class LoginControllerTest extends TestCase { 'user' => 'john@doe.com', 'redirect_url' => '/apps/files', ]) - ->will($this->returnValue($loginPageUrl)); + ->willReturn($loginPageUrl); $expected = new \OCP\AppFramework\Http\RedirectResponse($loginPageUrl); $expected->throttle(['user' => 'john']); diff --git a/tests/Core/Controller/LostControllerTest.php b/tests/Core/Controller/LostControllerTest.php index 27344102f0a..fdbca1ea3b1 100644 --- a/tests/Core/Controller/LostControllerTest.php +++ b/tests/Core/Controller/LostControllerTest.php @@ -110,9 +110,9 @@ class LostControllerTest extends \Test\TestCase { $this->l10n ->expects($this->any()) ->method('t') - ->will($this->returnCallback(function($text, $parameters = array()) { + ->willReturnCallback(function($text, $parameters = array()) { return vsprintf($text, $parameters); - })); + }); $this->defaults = $this->getMockBuilder('\OCP\Defaults') ->disableOriginalConstructor()->getMock(); $this->userManager = $this->getMockBuilder(IUserManager::class) @@ -179,7 +179,7 @@ class LostControllerTest extends \Test\TestCase { ->with('ValidTokenUser', 'core', 'lostpassword', null) ->willReturn('encryptedToken'); $this->existingUser->method('getLastLogin') - ->will($this->returnValue(12344)); + ->willReturn(12344); $this->userManager->method('get') ->with('ValidTokenUser') ->willReturn($this->existingUser); @@ -210,7 +210,7 @@ class LostControllerTest extends \Test\TestCase { ->expects($this->once()) ->method('getUserValue') ->with('ValidTokenUser', 'core', 'lostpassword', null) - ->will($this->returnValue('encryptedToken')); + ->willReturn('encryptedToken'); $this->crypto->method('decrypt') ->with( $this->equalTo('encryptedToken'), @@ -257,7 +257,7 @@ class LostControllerTest extends \Test\TestCase { ->expects($this->once()) ->method('linkToRouteAbsolute') ->with('core.lost.setPassword', array('userId' => 'ValidTokenUser', 'token' => 'TheOnlyAndOnlyOneTokenToResetThePassword')) - ->will($this->returnValue('https://example.tld/index.php/lostpassword/')); + ->willReturn('https://example.tld/index.php/lostpassword/'); $this->initialStateService->expects($this->at(0)) ->method('provideInitialState') @@ -280,10 +280,10 @@ class LostControllerTest extends \Test\TestCase { $this->userManager ->expects($this->any()) ->method('userExists') - ->will($this->returnValueMap(array( + ->willReturnMap(array( array(true, $existingUser), array(false, $nonExistingUser) - ))); + )); $this->logger->expects($this->exactly(0)) ->method('logException'); @@ -307,7 +307,7 @@ class LostControllerTest extends \Test\TestCase { ->expects($this->any()) ->method('getUserValue') ->with($existingUser, 'settings', 'email') - ->will($this->returnValue(null)); + ->willReturn(null); $response = $this->lostController->email($existingUser); $expectedResponse = new JSONResponse([ 'status' => 'success', @@ -321,7 +321,7 @@ class LostControllerTest extends \Test\TestCase { ->expects($this->once()) ->method('generate') ->with('21') - ->will($this->returnValue('ThisIsMaybeANotSoSecretToken!')); + ->willReturn('ThisIsMaybeANotSoSecretToken!'); $this->userManager ->expects($this->any()) ->method('get') @@ -330,7 +330,7 @@ class LostControllerTest extends \Test\TestCase { $this->timeFactory ->expects($this->once()) ->method('getTime') - ->will($this->returnValue(12348)); + ->willReturn(12348); $this->config ->expects($this->once()) ->method('setUserValue') @@ -339,7 +339,7 @@ class LostControllerTest extends \Test\TestCase { ->expects($this->once()) ->method('linkToRouteAbsolute') ->with('core.lost.resetform', array('userId' => 'ExistingUser', 'token' => 'ThisIsMaybeANotSoSecretToken!')) - ->will($this->returnValue('https://example.tld/index.php/lostpassword/')); + ->willReturn('https://example.tld/index.php/lostpassword/'); $message = $this->getMockBuilder('\OC\Mail\Message') ->disableOriginalConstructor()->getMock(); $message @@ -371,7 +371,7 @@ class LostControllerTest extends \Test\TestCase { $this->mailer ->expects($this->at(1)) ->method('createMessage') - ->will($this->returnValue($message)); + ->willReturn($message); $this->mailer ->expects($this->at(2)) ->method('send') @@ -394,7 +394,7 @@ class LostControllerTest extends \Test\TestCase { ->expects($this->once()) ->method('generate') ->with('21') - ->will($this->returnValue('ThisIsMaybeANotSoSecretToken!')); + ->willReturn('ThisIsMaybeANotSoSecretToken!'); $this->userManager ->expects($this->any()) ->method('get') @@ -408,7 +408,7 @@ class LostControllerTest extends \Test\TestCase { $this->timeFactory ->expects($this->once()) ->method('getTime') - ->will($this->returnValue(12348)); + ->willReturn(12348); $this->config ->expects($this->once()) ->method('setUserValue') @@ -417,7 +417,7 @@ class LostControllerTest extends \Test\TestCase { ->expects($this->once()) ->method('linkToRouteAbsolute') ->with('core.lost.resetform', array('userId' => 'ExistingUser', 'token' => 'ThisIsMaybeANotSoSecretToken!')) - ->will($this->returnValue('https://example.tld/index.php/lostpassword/')); + ->willReturn('https://example.tld/index.php/lostpassword/'); $message = $this->getMockBuilder('\OC\Mail\Message') ->disableOriginalConstructor()->getMock(); $message @@ -449,7 +449,7 @@ class LostControllerTest extends \Test\TestCase { $this->mailer ->expects($this->at(1)) ->method('createMessage') - ->will($this->returnValue($message)); + ->willReturn($message); $this->mailer ->expects($this->at(2)) ->method('send') @@ -472,7 +472,7 @@ class LostControllerTest extends \Test\TestCase { ->expects($this->once()) ->method('generate') ->with('21') - ->will($this->returnValue('ThisIsMaybeANotSoSecretToken!')); + ->willReturn('ThisIsMaybeANotSoSecretToken!'); $this->userManager ->expects($this->any()) ->method('get') @@ -485,12 +485,12 @@ class LostControllerTest extends \Test\TestCase { $this->timeFactory ->expects($this->once()) ->method('getTime') - ->will($this->returnValue(12348)); + ->willReturn(12348); $this->urlGenerator ->expects($this->once()) ->method('linkToRouteAbsolute') ->with('core.lost.resetform', array('userId' => 'ExistingUser', 'token' => 'ThisIsMaybeANotSoSecretToken!')) - ->will($this->returnValue('https://example.tld/index.php/lostpassword/')); + ->willReturn('https://example.tld/index.php/lostpassword/'); $message = $this->createMock(Message::class); $message ->expects($this->at(0)) @@ -521,7 +521,7 @@ class LostControllerTest extends \Test\TestCase { $this->mailer ->expects($this->at(1)) ->method('createMessage') - ->will($this->returnValue($message)); + ->willReturn($message); $this->mailer ->expects($this->at(2)) ->method('send') @@ -548,7 +548,7 @@ class LostControllerTest extends \Test\TestCase { ->with('ValidTokenUser', 'core', 'lostpassword', null) ->willReturn('encryptedData'); $this->existingUser->method('getLastLogin') - ->will($this->returnValue(12344)); + ->willReturn(12344); $this->existingUser->expects($this->once()) ->method('setPassword') ->with('NewPassword') @@ -559,7 +559,7 @@ class LostControllerTest extends \Test\TestCase { $this->config->expects($this->never()) ->method('deleteUserValue'); $this->timeFactory->method('getTime') - ->will($this->returnValue(12348)); + ->willReturn(12348); $this->crypto->method('decrypt') ->with( @@ -577,7 +577,7 @@ class LostControllerTest extends \Test\TestCase { ->with('ValidTokenUser', 'core', 'lostpassword', null) ->willReturn('encryptedData'); $this->existingUser->method('getLastLogin') - ->will($this->returnValue(12344)); + ->willReturn(12344); $this->existingUser->expects($this->once()) ->method('setPassword') ->with('NewPassword') @@ -589,7 +589,7 @@ class LostControllerTest extends \Test\TestCase { ->method('deleteUserValue') ->with('ValidTokenUser', 'core', 'lostpassword'); $this->timeFactory->method('getTime') - ->will($this->returnValue(12348)); + ->willReturn(12348); $this->crypto->method('decrypt') ->with( @@ -654,14 +654,14 @@ class LostControllerTest extends \Test\TestCase { ->with('ValidTokenUser', 'core', 'lostpassword', null) ->willReturn('encryptedData'); $this->existingUser->method('getLastLogin') - ->will($this->returnValue(12346)); + ->willReturn(12346); $this->userManager ->method('get') ->with('ValidTokenUser') ->willReturn($this->existingUser); $this->timeFactory ->method('getTime') - ->will($this->returnValue(12345)); + ->willReturn(12345); $this->crypto->method('decrypt') ->with( @@ -781,7 +781,7 @@ class LostControllerTest extends \Test\TestCase { ->with('ValidTokenUser', 'core', 'lostpassword', null) ->willReturn('encryptedData'); $this->existingUser->method('getLastLogin') - ->will($this->returnValue(12344)); + ->willReturn(12344); $this->existingUser->expects($this->once()) ->method('setPassword') ->with('NewPassword') @@ -793,7 +793,7 @@ class LostControllerTest extends \Test\TestCase { ->method('deleteUserValue') ->with('ValidTokenUser', 'core', 'lostpassword'); $this->timeFactory->method('getTime') - ->will($this->returnValue(12348)); + ->willReturn(12348); $this->crypto->method('decrypt') ->with( diff --git a/tests/Core/Controller/TwoFactorChallengeControllerTest.php b/tests/Core/Controller/TwoFactorChallengeControllerTest.php index 40453db5729..fa155500567 100644 --- a/tests/Core/Controller/TwoFactorChallengeControllerTest.php +++ b/tests/Core/Controller/TwoFactorChallengeControllerTest.php @@ -100,11 +100,11 @@ class TwoFactorChallengeControllerTest extends TestCase { $this->userSession->expects($this->once()) ->method('getUser') - ->will($this->returnValue($user)); + ->willReturn($user); $this->twoFactorManager->expects($this->once()) ->method('getProviderSet') ->with($user) - ->will($this->returnValue($providerSet)); + ->willReturn($providerSet); $expected = new StandaloneTemplateResponse('core', 'twofactorselectchallenge', [ 'providers' => [ @@ -131,32 +131,32 @@ class TwoFactorChallengeControllerTest extends TestCase { $this->userSession->expects($this->once()) ->method('getUser') - ->will($this->returnValue($user)); + ->willReturn($user); $this->twoFactorManager->expects($this->once()) ->method('getProviderSet') ->with($user) - ->will($this->returnValue($providerSet)); + ->willReturn($providerSet); $provider->expects($this->once()) ->method('getId') - ->will($this->returnValue('u2f')); + ->willReturn('u2f'); $backupProvider->expects($this->once()) ->method('getId') - ->will($this->returnValue('backup_codes')); + ->willReturn('backup_codes'); $this->session->expects($this->once()) ->method('exists') ->with('two_factor_auth_error') - ->will($this->returnValue(true)); + ->willReturn(true); $this->session->expects($this->exactly(2)) ->method('remove') ->with($this->logicalOr($this->equalTo('two_factor_auth_error'), $this->equalTo('two_factor_auth_error_message'))); $provider->expects($this->once()) ->method('getTemplate') ->with($user) - ->will($this->returnValue($tmpl)); + ->willReturn($tmpl); $tmpl->expects($this->once()) ->method('fetchPage') - ->will($this->returnValue('<html/>')); + ->willReturn('<html/>'); $expected = new StandaloneTemplateResponse('core', 'twofactorshowchallenge', [ 'error' => true, @@ -177,15 +177,15 @@ class TwoFactorChallengeControllerTest extends TestCase { $this->userSession->expects($this->once()) ->method('getUser') - ->will($this->returnValue($user)); + ->willReturn($user); $this->twoFactorManager->expects($this->once()) ->method('getProviderSet') ->with($user) - ->will($this->returnValue($providerSet)); + ->willReturn($providerSet); $this->urlGenerator->expects($this->once()) ->method('linkToRoute') ->with('core.TwoFactorChallenge.selectChallenge') - ->will($this->returnValue('select/challenge/url')); + ->willReturn('select/challenge/url'); $expected = new RedirectResponse('select/challenge/url'); @@ -198,16 +198,16 @@ class TwoFactorChallengeControllerTest extends TestCase { $this->userSession->expects($this->once()) ->method('getUser') - ->will($this->returnValue($user)); + ->willReturn($user); $this->twoFactorManager->expects($this->once()) ->method('getProvider') ->with($user, 'myprovider') - ->will($this->returnValue($provider)); + ->willReturn($provider); $this->twoFactorManager->expects($this->once()) ->method('verifyChallenge') ->with('myprovider', $user, 'token') - ->will($this->returnValue(true)); + ->willReturn(true); $expected = new RedirectResponse(OC_Util::getDefaultPageUrl()); $this->assertEquals($expected, $this->controller->solveChallenge('myprovider', 'token')); @@ -219,11 +219,11 @@ class TwoFactorChallengeControllerTest extends TestCase { $this->userSession->expects($this->once()) ->method('getUser') - ->will($this->returnValue($user)); + ->willReturn($user); $this->twoFactorManager->expects($this->once()) ->method('getProvider') ->with($user, 'myprovider') - ->will($this->returnValue($provider)); + ->willReturn($provider); $this->twoFactorManager->expects($this->once()) ->method('verifyChallenge') @@ -243,15 +243,15 @@ class TwoFactorChallengeControllerTest extends TestCase { $this->userSession->expects($this->once()) ->method('getUser') - ->will($this->returnValue($user)); + ->willReturn($user); $this->twoFactorManager->expects($this->once()) ->method('getProvider') ->with($user, 'myprovider') - ->will($this->returnValue(null)); + ->willReturn(null); $this->urlGenerator->expects($this->once()) ->method('linkToRoute') ->with('core.TwoFactorChallenge.selectChallenge') - ->will($this->returnValue('select/challenge/url')); + ->willReturn('select/challenge/url'); $expected = new RedirectResponse('select/challenge/url'); @@ -264,16 +264,16 @@ class TwoFactorChallengeControllerTest extends TestCase { $this->userSession->expects($this->once()) ->method('getUser') - ->will($this->returnValue($user)); + ->willReturn($user); $this->twoFactorManager->expects($this->once()) ->method('getProvider') ->with($user, 'myprovider') - ->will($this->returnValue($provider)); + ->willReturn($provider); $this->twoFactorManager->expects($this->once()) ->method('verifyChallenge') ->with('myprovider', $user, 'token') - ->will($this->returnValue(false)); + ->willReturn(false); $this->session->expects($this->once()) ->method('set') ->with('two_factor_auth_error', true); @@ -283,10 +283,10 @@ class TwoFactorChallengeControllerTest extends TestCase { 'challengeProviderId' => 'myprovider', 'redirect_url' => '/url', ]) - ->will($this->returnValue('files/index/url')); + ->willReturn('files/index/url'); $provider->expects($this->once()) ->method('getId') - ->will($this->returnValue('myprovider')); + ->willReturn('myprovider'); $expected = new RedirectResponse('files/index/url'); $this->assertEquals($expected, $this->controller->solveChallenge('myprovider', 'token', '/url')); @@ -299,11 +299,11 @@ class TwoFactorChallengeControllerTest extends TestCase { $this->userSession->expects($this->once()) ->method('getUser') - ->will($this->returnValue($user)); + ->willReturn($user); $this->twoFactorManager->expects($this->once()) ->method('getProvider') ->with($user, 'myprovider') - ->will($this->returnValue($provider)); + ->willReturn($provider); $this->twoFactorManager->expects($this->once()) ->method('verifyChallenge') @@ -321,10 +321,10 @@ class TwoFactorChallengeControllerTest extends TestCase { 'challengeProviderId' => 'myprovider', 'redirect_url' => '/url', ]) - ->will($this->returnValue('files/index/url')); + ->willReturn('files/index/url'); $provider->expects($this->once()) ->method('getId') - ->will($this->returnValue('myprovider')); + ->willReturn('myprovider'); $expected = new RedirectResponse('files/index/url'); $this->assertEquals($expected, $this->controller->solveChallenge('myprovider', 'token', '/url')); @@ -334,7 +334,7 @@ class TwoFactorChallengeControllerTest extends TestCase { $user = $this->createMock(IUser::class); $this->userSession->expects($this->once()) ->method('getUser') - ->will($this->returnValue($user)); + ->willReturn($user); $provider = $this->createMock(IActivatableAtLogin::class); $this->twoFactorManager->expects($this->once()) ->method('getLoginSetupProviders') @@ -363,7 +363,7 @@ class TwoFactorChallengeControllerTest extends TestCase { $user = $this->createMock(IUser::class); $this->userSession->expects($this->once()) ->method('getUser') - ->will($this->returnValue($user)); + ->willReturn($user); $provider = $this->createMock(IActivatableAtLogin::class); $provider->expects($this->any()) ->method('getId') @@ -389,7 +389,7 @@ class TwoFactorChallengeControllerTest extends TestCase { $user = $this->createMock(IUser::class); $this->userSession->expects($this->once()) ->method('getUser') - ->will($this->returnValue($user)); + ->willReturn($user); $provider = $this->createMock(IActivatableAtLogin::class); $provider->expects($this->any()) ->method('getId') diff --git a/tests/Core/Controller/UserControllerTest.php b/tests/Core/Controller/UserControllerTest.php index b5e43b2999d..78112f09fd6 100644 --- a/tests/Core/Controller/UserControllerTest.php +++ b/tests/Core/Controller/UserControllerTest.php @@ -56,12 +56,12 @@ class UserControllerTest extends TestCase { $this->userManager ->method('get') - ->will($this->returnCallback(function ($uid) use ($user) { + ->willReturnCallback(function ($uid) use ($user) { if ($uid === 'foo') { return $user; } return null; - })); + }); $expected = new JSONResponse([ 'users' => [ diff --git a/tests/Core/Middleware/TwoFactorMiddlewareTest.php b/tests/Core/Middleware/TwoFactorMiddlewareTest.php index 2198cc7d5b4..ac3a5fbc017 100644 --- a/tests/Core/Middleware/TwoFactorMiddlewareTest.php +++ b/tests/Core/Middleware/TwoFactorMiddlewareTest.php @@ -100,10 +100,10 @@ class TwoFactorMiddlewareTest extends TestCase { $this->reflector->expects($this->once()) ->method('hasAnnotation') ->with('PublicPage') - ->will($this->returnValue(false)); + ->willReturn(false); $this->userSession->expects($this->once()) ->method('isLoggedIn') - ->will($this->returnValue(false)); + ->willReturn(false); $this->userSession->expects($this->never()) ->method('getUser'); @@ -115,7 +115,7 @@ class TwoFactorMiddlewareTest extends TestCase { $this->reflector->expects($this->once()) ->method('hasAnnotation') ->with('PublicPage') - ->will($this->returnValue(true)); + ->willReturn(true); $this->userSession->expects($this->never()) ->method('isLoggedIn'); @@ -147,17 +147,17 @@ class TwoFactorMiddlewareTest extends TestCase { $this->reflector->expects($this->once()) ->method('hasAnnotation') ->with('PublicPage') - ->will($this->returnValue(false)); + ->willReturn(false); $this->userSession->expects($this->once()) ->method('isLoggedIn') - ->will($this->returnValue(true)); + ->willReturn(true); $this->userSession->expects($this->once()) ->method('getUser') - ->will($this->returnValue($user)); + ->willReturn($user); $this->twoFactorManager->expects($this->once()) ->method('isTwoFactorAuthenticated') ->with($user) - ->will($this->returnValue(false)); + ->willReturn(false); $this->middleware->beforeController($this->controller, 'index'); } @@ -171,21 +171,21 @@ class TwoFactorMiddlewareTest extends TestCase { $this->reflector->expects($this->once()) ->method('hasAnnotation') ->with('PublicPage') - ->will($this->returnValue(false)); + ->willReturn(false); $this->userSession->expects($this->once()) ->method('isLoggedIn') - ->will($this->returnValue(true)); + ->willReturn(true); $this->userSession->expects($this->once()) ->method('getUser') - ->will($this->returnValue($user)); + ->willReturn($user); $this->twoFactorManager->expects($this->once()) ->method('isTwoFactorAuthenticated') ->with($user) - ->will($this->returnValue(true)); + ->willReturn(true); $this->twoFactorManager->expects($this->once()) ->method('needsSecondFactor') ->with($user) - ->will($this->returnValue(true)); + ->willReturn(true); $this->middleware->beforeController($this->controller, 'index'); } @@ -201,18 +201,18 @@ class TwoFactorMiddlewareTest extends TestCase { ->willReturn(false); $this->userSession->expects($this->once()) ->method('isLoggedIn') - ->will($this->returnValue(true)); + ->willReturn(true); $this->userSession ->method('getUser') - ->will($this->returnValue($user)); + ->willReturn($user); $this->twoFactorManager->expects($this->once()) ->method('isTwoFactorAuthenticated') ->with($user) - ->will($this->returnValue(true)); + ->willReturn(true); $this->twoFactorManager->expects($this->once()) ->method('needsSecondFactor') ->with($user) - ->will($this->returnValue(false)); + ->willReturn(false); $twoFactorChallengeController = $this->getMockBuilder('\OC\Core\Controller\TwoFactorChallengeController') ->disableOriginalConstructor() @@ -226,7 +226,7 @@ class TwoFactorMiddlewareTest extends TestCase { $this->urlGenerator->expects($this->once()) ->method('linkToRoute') ->with('core.TwoFactorChallenge.selectChallenge') - ->will($this->returnValue('test/url')); + ->willReturn('test/url'); $expected = new \OCP\AppFramework\Http\RedirectResponse('test/url'); $this->assertEquals($expected, $this->middleware->afterException($this->controller, 'index', $ex)); @@ -238,7 +238,7 @@ class TwoFactorMiddlewareTest extends TestCase { $this->urlGenerator->expects($this->once()) ->method('linkToRoute') ->with('files.view.index') - ->will($this->returnValue('redirect/url')); + ->willReturn('redirect/url'); $expected = new \OCP\AppFramework\Http\RedirectResponse('redirect/url'); $this->assertEquals($expected, $this->middleware->afterException($this->controller, 'index', $ex)); @@ -249,9 +249,9 @@ class TwoFactorMiddlewareTest extends TestCase { $this->reflector ->method('hasAnnotation') - ->will($this->returnCallback(function (string $annotation) { + ->willReturnCallback(function (string $annotation) { return $annotation === 'TwoFactorSetUpDoneRequired'; - })); + }); $this->userSession->expects($this->once()) ->method('isLoggedIn') ->willReturn(true); |