From 4d3b92e68782ce7ab3ef58b6be715a76df2a6955 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Fri, 2 Sep 2016 11:07:26 +0200 Subject: [PATCH] Fix getMock Authentication --- .../Token/DefaultTokenMapperTest.php | 9 +++++---- .../Token/DefaultTokenProviderTest.php | 19 ++++++++++++------- .../TwoFactorAuth/ManagerTest.php | 10 +++++----- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/tests/lib/Authentication/Token/DefaultTokenMapperTest.php b/tests/lib/Authentication/Token/DefaultTokenMapperTest.php index 6b73cab5ed..d71d946847 100644 --- a/tests/lib/Authentication/Token/DefaultTokenMapperTest.php +++ b/tests/lib/Authentication/Token/DefaultTokenMapperTest.php @@ -27,6 +27,7 @@ use OC\Authentication\Token\DefaultToken; use OC\Authentication\Token\DefaultTokenMapper; use OC\Authentication\Token\IToken; use OCP\DB\QueryBuilder\IQueryBuilder; +use OCP\IUser; use Test\TestCase; /** @@ -150,7 +151,7 @@ class DefaultTokenMapperTest extends TestCase { } public function testGetTokenByUser() { - $user = $this->getMock('\OCP\IUser'); + $user = $this->createMock(IUser::class); $user->expects($this->once()) ->method('getUID') ->will($this->returnValue('user1')); @@ -159,7 +160,7 @@ class DefaultTokenMapperTest extends TestCase { } public function testGetTokenByUserNotFound() { - $user = $this->getMock('\OCP\IUser'); + $user = $this->createMock(IUser::class); $user->expects($this->once()) ->method('getUID') ->will($this->returnValue('user1000')); @@ -168,7 +169,7 @@ class DefaultTokenMapperTest extends TestCase { } public function testDeleteById() { - $user = $this->getMock('\OCP\IUser'); + $user = $this->createMock(IUser::class); $qb = $this->dbConnection->getQueryBuilder(); $qb->select('id') ->from('authtoken') @@ -184,7 +185,7 @@ class DefaultTokenMapperTest extends TestCase { } public function testDeleteByIdWrongUser() { - $user = $this->getMock('\OCP\IUser'); + $user = $this->createMock(IUser::class); $id = 33; $user->expects($this->once()) ->method('getUID') diff --git a/tests/lib/Authentication/Token/DefaultTokenProviderTest.php b/tests/lib/Authentication/Token/DefaultTokenProviderTest.php index 28a59529de..7f90cf051f 100644 --- a/tests/lib/Authentication/Token/DefaultTokenProviderTest.php +++ b/tests/lib/Authentication/Token/DefaultTokenProviderTest.php @@ -26,6 +26,11 @@ use OC\Authentication\Token\DefaultToken; use OC\Authentication\Token\DefaultTokenProvider; use OC\Authentication\Token\IToken; use OCP\AppFramework\Db\DoesNotExistException; +use OCP\AppFramework\Utility\ITimeFactory; +use OCP\IConfig; +use OCP\ILogger; +use OCP\IUser; +use OCP\Security\ICrypto; use Test\TestCase; class DefaultTokenProviderTest extends TestCase { @@ -45,10 +50,10 @@ class DefaultTokenProviderTest extends TestCase { $this->mapper = $this->getMockBuilder('\OC\Authentication\Token\DefaultTokenMapper') ->disableOriginalConstructor() ->getMock(); - $this->crypto = $this->getMock('\OCP\Security\ICrypto'); - $this->config = $this->getMock('\OCP\IConfig'); - $this->logger = $this->getMock('\OCP\ILogger'); - $this->timeFactory = $this->getMock('\OCP\AppFramework\Utility\ITimeFactory'); + $this->crypto = $this->createMock(ICrypto::class); + $this->config = $this->createMock(IConfig::class); + $this->logger = $this->createMock(ILogger::class); + $this->timeFactory = $this->createMock(ITimeFactory::class); $this->time = 1313131; $this->timeFactory->expects($this->any()) ->method('getTime') @@ -118,7 +123,7 @@ class DefaultTokenProviderTest extends TestCase { } public function testGetTokenByUser() { - $user = $this->getMock('\OCP\IUser'); + $user = $this->createMock(IUser::class); $this->mapper->expects($this->once()) ->method('getTokenByUser') ->with($user) @@ -212,7 +217,7 @@ class DefaultTokenProviderTest extends TestCase { * @expectedException \OC\Authentication\Exceptions\InvalidTokenException */ public function testSetPasswordInvalidToken() { - $token = $this->getMock('\OC\Authentication\Token\IToken'); + $token = $this->createMock(IToken::class); $tokenId = 'token123'; $password = '123456'; @@ -229,7 +234,7 @@ class DefaultTokenProviderTest extends TestCase { public function testInvaildateTokenById() { $id = 123; - $user = $this->getMock('\OCP\IUser'); + $user = $this->createMock(IUser::class); $this->mapper->expects($this->once()) ->method('deleteById') diff --git a/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php b/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php index 83a74f2f25..b3fd28a30a 100644 --- a/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php +++ b/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php @@ -59,19 +59,19 @@ class ManagerTest extends TestCase { protected function setUp() { parent::setUp(); - $this->user = $this->getMockBuilder('\OCP\IUser')->getMock(); + $this->user = $this->createMock(IUser::class); $this->appManager = $this->getMockBuilder('\OC\App\AppManager') ->disableOriginalConstructor() ->getMock(); - $this->session = $this->getMockBuilder('\OCP\ISession')->getMock(); - $this->config = $this->getMockBuilder('\OCP\IConfig')->getMock(); + $this->session = $this->createMock(ISession::class); + $this->config = $this->createMock(IConfig::class); $this->manager = $this->getMockBuilder('\OC\Authentication\TwoFactorAuth\Manager') ->setConstructorArgs([$this->appManager, $this->session, $this->config]) ->setMethods(['loadTwoFactorApp']) // Do not actually load the apps ->getMock(); - $this->fakeProvider = $this->getMockBuilder('\OCP\Authentication\TwoFactorAuth\IProvider')->getMock(); + $this->fakeProvider = $this->createMock(IProvider::class); $this->fakeProvider->expects($this->any()) ->method('getId') ->will($this->returnValue('email')); @@ -268,7 +268,7 @@ class ManagerTest extends TestCase { } public function testNeedsSecondFactor() { - $user = $this->getMock('\OCP\IUser'); + $user = $this->createMock(IUser::class); $this->session->expects($this->once()) ->method('exists') ->with('two_factor_auth_uid')