Fix getMock Authentication
This commit is contained in:
parent
3a3a17b2e3
commit
4d3b92e687
|
@ -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')
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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')
|
||||
|
|
Loading…
Reference in New Issue