aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2016-09-12 21:53:21 +0200
committerRoeland Jago Douma <roeland@famdouma.nl>2016-09-13 09:09:53 +0200
commitd616984879d7fcf683f19eb40a842a583c7528e3 (patch)
tree43ad7d8ea9e9f2f2d8990098b389b79e6b9dc501
parent478b86e5e586975f96d57f6ebb6a3b5dbcbdaaea (diff)
downloadnextcloud-server-d616984879d7fcf683f19eb40a842a583c7528e3.tar.gz
nextcloud-server-d616984879d7fcf683f19eb40a842a583c7528e3.zip
Fix getMock User
-rw-r--r--tests/lib/User/DatabaseTest.php2
-rw-r--r--tests/lib/User/ManagerTest.php47
-rw-r--r--tests/lib/User/SessionTest.php190
-rw-r--r--tests/lib/User/UserTest.php43
4 files changed, 146 insertions, 136 deletions
diff --git a/tests/lib/User/DatabaseTest.php b/tests/lib/User/DatabaseTest.php
index 16275f3b6c5..d7e4b9256cb 100644
--- a/tests/lib/User/DatabaseTest.php
+++ b/tests/lib/User/DatabaseTest.php
@@ -45,7 +45,7 @@ class DatabaseTest extends Backend {
protected function setUp() {
parent::setUp();
- $this->eventDispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcher');
+ $this->eventDispatcher = $this->createMock(EventDispatcher::class);
$this->backend=new \OC\User\Database($this->eventDispatcher);
}
diff --git a/tests/lib/User/ManagerTest.php b/tests/lib/User/ManagerTest.php
index f1b520ee0cf..f6318ff353b 100644
--- a/tests/lib/User/ManagerTest.php
+++ b/tests/lib/User/ManagerTest.php
@@ -8,6 +8,7 @@
*/
namespace Test\User;
+use OC\User\Database;
/**
* Class ManagerTest
@@ -18,11 +19,11 @@ namespace Test\User;
*/
class ManagerTest extends \Test\TestCase {
public function testGetBackends() {
- $userDummyBackend = $this->getMock('\Test\Util\User\Dummy');
+ $userDummyBackend = $this->createMock(\Test\Util\User\Dummy::class);
$manager = new \OC\User\Manager();
$manager->registerBackend($userDummyBackend);
$this->assertEquals([$userDummyBackend], $manager->getBackends());
- $dummyDatabaseBackend = $this->getMock('\OC_User_Database');
+ $dummyDatabaseBackend = $this->createMock(Database::class);
$manager->registerBackend($dummyDatabaseBackend);
$this->assertEquals([$userDummyBackend, $dummyDatabaseBackend], $manager->getBackends());
}
@@ -32,7 +33,7 @@ class ManagerTest extends \Test\TestCase {
/**
* @var \Test\Util\User\Dummy | \PHPUnit_Framework_MockObject_MockObject $backend
*/
- $backend = $this->getMock('\Test\Util\User\Dummy');
+ $backend = $this->createMock(\Test\Util\User\Dummy::class);
$backend->expects($this->once())
->method('userExists')
->with($this->equalTo('foo'))
@@ -48,7 +49,7 @@ class ManagerTest extends \Test\TestCase {
/**
* @var \Test\Util\User\Dummy | \PHPUnit_Framework_MockObject_MockObject $backend
*/
- $backend = $this->getMock('\Test\Util\User\Dummy');
+ $backend = $this->createMock(\Test\Util\User\Dummy::class);
$backend->expects($this->once())
->method('userExists')
->with($this->equalTo('foo'))
@@ -70,7 +71,7 @@ class ManagerTest extends \Test\TestCase {
/**
* @var \Test\Util\User\Dummy | \PHPUnit_Framework_MockObject_MockObject $backend1
*/
- $backend1 = $this->getMock('\Test\Util\User\Dummy');
+ $backend1 = $this->createMock(\Test\Util\User\Dummy::class);
$backend1->expects($this->once())
->method('userExists')
->with($this->equalTo('foo'))
@@ -79,7 +80,7 @@ class ManagerTest extends \Test\TestCase {
/**
* @var \Test\Util\User\Dummy | \PHPUnit_Framework_MockObject_MockObject $backend2
*/
- $backend2 = $this->getMock('\Test\Util\User\Dummy');
+ $backend2 = $this->createMock(\Test\Util\User\Dummy::class);
$backend2->expects($this->once())
->method('userExists')
->with($this->equalTo('foo'))
@@ -96,7 +97,7 @@ class ManagerTest extends \Test\TestCase {
/**
* @var \Test\Util\User\Dummy | \PHPUnit_Framework_MockObject_MockObject $backend1
*/
- $backend1 = $this->getMock('\Test\Util\User\Dummy');
+ $backend1 = $this->createMock(\Test\Util\User\Dummy::class);
$backend1->expects($this->once())
->method('userExists')
->with($this->equalTo('foo'))
@@ -105,7 +106,7 @@ class ManagerTest extends \Test\TestCase {
/**
* @var \Test\Util\User\Dummy | \PHPUnit_Framework_MockObject_MockObject $backend2
*/
- $backend2 = $this->getMock('\Test\Util\User\Dummy');
+ $backend2 = $this->createMock(\Test\Util\User\Dummy::class);
$backend2->expects($this->never())
->method('userExists');
@@ -120,7 +121,7 @@ class ManagerTest extends \Test\TestCase {
/**
* @var \OC\User\Backend | \PHPUnit_Framework_MockObject_MockObject $backend
*/
- $backend = $this->getMock('\Test\Util\User\Dummy');
+ $backend = $this->createMock(\Test\Util\User\Dummy::class);
$backend->expects($this->once())
->method('checkPassword')
->with($this->equalTo('foo'), $this->equalTo('bar'))
@@ -147,7 +148,7 @@ class ManagerTest extends \Test\TestCase {
/**
* @var \OC\User\Backend | \PHPUnit_Framework_MockObject_MockObject $backend
*/
- $backend = $this->getMock('\Test\Util\User\Dummy');
+ $backend = $this->createMock(\Test\Util\User\Dummy::class);
$backend->expects($this->never())
->method('checkPassword');
@@ -165,7 +166,7 @@ class ManagerTest extends \Test\TestCase {
/**
* @var \Test\Util\User\Dummy | \PHPUnit_Framework_MockObject_MockObject $backend
*/
- $backend = $this->getMock('\Test\Util\User\Dummy');
+ $backend = $this->createMock(\Test\Util\User\Dummy::class);
$backend->expects($this->once())
->method('userExists')
->with($this->equalTo('foo'))
@@ -181,7 +182,7 @@ class ManagerTest extends \Test\TestCase {
/**
* @var \Test\Util\User\Dummy | \PHPUnit_Framework_MockObject_MockObject $backend
*/
- $backend = $this->getMock('\Test\Util\User\Dummy');
+ $backend = $this->createMock(\Test\Util\User\Dummy::class);
$backend->expects($this->once())
->method('userExists')
->with($this->equalTo('foo'))
@@ -197,7 +198,7 @@ class ManagerTest extends \Test\TestCase {
/**
* @var \Test\Util\User\Dummy | \PHPUnit_Framework_MockObject_MockObject $backend
*/
- $backend = $this->getMock('\Test\Util\User\Dummy');
+ $backend = $this->createMock(\Test\Util\User\Dummy::class);
$backend->expects($this->once())
->method('getUsers')
->with($this->equalTo('fo'))
@@ -216,7 +217,7 @@ class ManagerTest extends \Test\TestCase {
/**
* @var \Test\Util\User\Dummy | \PHPUnit_Framework_MockObject_MockObject $backend1
*/
- $backend1 = $this->getMock('\Test\Util\User\Dummy');
+ $backend1 = $this->createMock(\Test\Util\User\Dummy::class);
$backend1->expects($this->once())
->method('getUsers')
->with($this->equalTo('fo'), $this->equalTo(3), $this->equalTo(1))
@@ -225,7 +226,7 @@ class ManagerTest extends \Test\TestCase {
/**
* @var \Test\Util\User\Dummy | \PHPUnit_Framework_MockObject_MockObject $backend2
*/
- $backend2 = $this->getMock('\Test\Util\User\Dummy');
+ $backend2 = $this->createMock(\Test\Util\User\Dummy::class);
$backend2->expects($this->once())
->method('getUsers')
->with($this->equalTo('fo'), $this->equalTo(3), $this->equalTo(1))
@@ -246,7 +247,7 @@ class ManagerTest extends \Test\TestCase {
/**
* @var \Test\Util\User\Dummy | \PHPUnit_Framework_MockObject_MockObject $backend
*/
- $backend = $this->getMock('\Test\Util\User\Dummy');
+ $backend = $this->createMock(\Test\Util\User\Dummy::class);
$backend->expects($this->any())
->method('implementsActions')
->will($this->returnValue(true));
@@ -274,7 +275,7 @@ class ManagerTest extends \Test\TestCase {
/**
* @var \Test\Util\User\Dummy | \PHPUnit_Framework_MockObject_MockObject $backend
*/
- $backend = $this->getMock('\Test\Util\User\Dummy');
+ $backend = $this->createMock(\Test\Util\User\Dummy::class);
$backend->expects($this->any())
->method('implementsActions')
->will($this->returnValue(true));
@@ -297,7 +298,7 @@ class ManagerTest extends \Test\TestCase {
/**
* @var \Test\Util\User\Dummy | \PHPUnit_Framework_MockObject_MockObject $backend
*/
- $backend = $this->getMock('\Test\Util\User\Dummy');
+ $backend = $this->createMock(\Test\Util\User\Dummy::class);
$backend->expects($this->any())
->method('implementsActions')
->will($this->returnValue(false));
@@ -329,7 +330,7 @@ class ManagerTest extends \Test\TestCase {
/**
* @var \Test\Util\User\Dummy | \PHPUnit_Framework_MockObject_MockObject $backend1
*/
- $backend1 = $this->getMock('\Test\Util\User\Dummy');
+ $backend1 = $this->createMock(\Test\Util\User\Dummy::class);
$backend1->expects($this->any())
->method('implementsActions')
->will($this->returnValue(true));
@@ -345,7 +346,7 @@ class ManagerTest extends \Test\TestCase {
/**
* @var \Test\Util\User\Dummy | \PHPUnit_Framework_MockObject_MockObject $backend2
*/
- $backend2 = $this->getMock('\Test\Util\User\Dummy');
+ $backend2 = $this->createMock(\Test\Util\User\Dummy::class);
$backend2->expects($this->any())
->method('implementsActions')
->will($this->returnValue(true));
@@ -377,7 +378,7 @@ class ManagerTest extends \Test\TestCase {
/**
* @var \Test\Util\User\Dummy | \PHPUnit_Framework_MockObject_MockObject $backend
*/
- $backend = $this->getMock('\Test\Util\User\Dummy');
+ $backend = $this->createMock(\Test\Util\User\Dummy::class);
$backend->expects($this->once())
->method('countUsers')
->will($this->returnValue(7));
@@ -406,7 +407,7 @@ class ManagerTest extends \Test\TestCase {
/**
* @var \Test\Util\User\Dummy | \PHPUnit_Framework_MockObject_MockObject $backend
*/
- $backend1 = $this->getMock('\Test\Util\User\Dummy');
+ $backend1 = $this->createMock(\Test\Util\User\Dummy::class);
$backend1->expects($this->once())
->method('countUsers')
->will($this->returnValue(7));
@@ -419,7 +420,7 @@ class ManagerTest extends \Test\TestCase {
->method('getBackendName')
->will($this->returnValue('Mock_Test_Util_User_Dummy'));
- $backend2 = $this->getMock('\Test\Util\User\Dummy');
+ $backend2 = $this->createMock(\Test\Util\User\Dummy::class);
$backend2->expects($this->once())
->method('countUsers')
->will($this->returnValue(16));
diff --git a/tests/lib/User/SessionTest.php b/tests/lib/User/SessionTest.php
index 4b8067117b1..2cd6b9b3bed 100644
--- a/tests/lib/User/SessionTest.php
+++ b/tests/lib/User/SessionTest.php
@@ -9,9 +9,20 @@
namespace Test\User;
+use OC\Authentication\Token\IProvider;
+use OC\Authentication\Token\IToken;
use OC\Security\Bruteforce\Throttler;
use OC\Session\Memory;
+use OC\User\Manager;
+use OC\User\Session;
use OC\User\User;
+use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\IConfig;
+use OCP\IRequest;
+use OCP\ISession;
+use OCP\IUser;
+use OCP\IUserManager;
+use OCP\Security\ISecureRandom;
/**
* @group DB
@@ -30,14 +41,13 @@ class SessionTest extends \Test\TestCase {
protected function setUp() {
parent::setUp();
- $this->timeFactory = $this->getMock('\OCP\AppFramework\Utility\ITimeFactory');
+ $this->timeFactory = $this->createMock(ITimeFactory::class);
$this->timeFactory->expects($this->any())
->method('getTime')
->will($this->returnValue(10000));
- $this->tokenProvider = $this->getMock('\OC\Authentication\Token\IProvider');
- $this->config = $this->getMock('\OCP\IConfig');
- $this->throttler = $this->getMockBuilder('\OC\Security\Bruteforce\Throttler')
- ->disableOriginalConstructor()->getMock();
+ $this->tokenProvider = $this->createMock(IProvider::class);
+ $this->config = $this->createMock(IConfig::class);
+ $this->throttler = $this->createMock(Throttler::class);
}
public function testGetUser() {
@@ -45,11 +55,11 @@ class SessionTest extends \Test\TestCase {
$token->setLoginName('User123');
$token->setLastCheck(200);
- $expectedUser = $this->getMock('\OCP\IUser');
+ $expectedUser = $this->createMock(IUser::class);
$expectedUser->expects($this->any())
->method('getUID')
->will($this->returnValue('user123'));
- $session = $this->getMock('\OC\Session\Memory', array(), array(''));
+ $session = $this->getMockBuilder(Memory::class)->setConstructorArgs([''])->getMock();
$session->expects($this->at(0))
->method('get')
->with('user_id')
@@ -108,7 +118,7 @@ class SessionTest extends \Test\TestCase {
* @dataProvider isLoggedInData
*/
public function testIsLoggedIn($isLoggedIn) {
- $session = $this->getMock('\OC\Session\Memory', array(), array(''));
+ $session = $this->getMockBuilder(Memory::class)->setConstructorArgs([''])->getMock();
$manager = $this->getMockBuilder('\OC\User\Manager')
->disableOriginalConstructor()
@@ -128,16 +138,16 @@ class SessionTest extends \Test\TestCase {
}
public function testSetUser() {
- $session = $this->getMock('\OC\Session\Memory', array(), array(''));
+ $session = $this->getMockBuilder(Memory::class)->setConstructorArgs([''])->getMock();
$session->expects($this->once())
->method('set')
->with('user_id', 'foo');
- $manager = $this->getMock('\OC\User\Manager');
+ $manager = $this->createMock(Manager::class);
- $backend = $this->getMock('\Test\Util\User\Dummy');
+ $backend = $this->createMock(\Test\Util\User\Dummy::class);
- $user = $this->getMock('\OC\User\User', array(), array('foo', $backend));
+ $user = $this->getMockBuilder(User::class)->setConstructorArgs(['foo', $backend])->getMock();
$user->expects($this->once())
->method('getUID')
->will($this->returnValue('foo'));
@@ -147,7 +157,7 @@ class SessionTest extends \Test\TestCase {
}
public function testLoginValidPasswordEnabled() {
- $session = $this->getMock('\OC\Session\Memory', array(), array(''));
+ $session = $this->getMockBuilder(Memory::class)->setConstructorArgs([''])->getMock();
$session->expects($this->once())
->method('regenerateId');
$this->tokenProvider->expects($this->once())
@@ -178,11 +188,11 @@ class SessionTest extends \Test\TestCase {
unset($managerMethods[$i]);
}
}
- $manager = $this->getMock('\OC\User\Manager', $managerMethods, array());
+ $manager = $this->getMockBuilder(Manager::class)->setMethods($managerMethods)->getMock();
- $backend = $this->getMock('\Test\Util\User\Dummy');
+ $backend = $this->createMock(\Test\Util\User\Dummy::class);
- $user = $this->getMock('\OC\User\User', array(), array('foo', $backend));
+ $user = $this->getMockBuilder(User::class)->setConstructorArgs(['foo', $backend])->getMock();
$user->expects($this->any())
->method('isEnabled')
->will($this->returnValue(true));
@@ -213,7 +223,7 @@ class SessionTest extends \Test\TestCase {
* @expectedException \OC\User\LoginException
*/
public function testLoginValidPasswordDisabled() {
- $session = $this->getMock('\OC\Session\Memory', array(), array(''));
+ $session = $this->getMockBuilder(Memory::class)->setConstructorArgs([''])->getMock();
$session->expects($this->never())
->method('set');
$session->expects($this->once())
@@ -233,11 +243,11 @@ class SessionTest extends \Test\TestCase {
unset($managerMethods[$i]);
}
}
- $manager = $this->getMock('\OC\User\Manager', $managerMethods, array());
+ $manager = $this->getMockBuilder(Manager::class)->setMethods($managerMethods)->getMock();
- $backend = $this->getMock('\Test\Util\User\Dummy');
+ $backend = $this->createMock(\Test\Util\User\Dummy::class);
- $user = $this->getMock('\OC\User\User', array(), array('foo', $backend));
+ $user = $this->getMockBuilder(User::class)->setConstructorArgs(['foo', $backend])->getMock();
$user->expects($this->any())
->method('isEnabled')
->will($this->returnValue(false));
@@ -254,7 +264,7 @@ class SessionTest extends \Test\TestCase {
}
public function testLoginInvalidPassword() {
- $session = $this->getMock('\OC\Session\Memory', array(), array(''));
+ $session = $this->getMockBuilder(Memory::class)->setConstructorArgs([''])->getMock();
$managerMethods = get_class_methods('\OC\User\Manager');
//keep following methods intact in order to ensure hooks are
//working
@@ -265,11 +275,11 @@ class SessionTest extends \Test\TestCase {
unset($managerMethods[$i]);
}
}
- $manager = $this->getMock('\OC\User\Manager', $managerMethods, array());
- $backend = $this->getMock('\Test\Util\User\Dummy');
+ $manager = $this->getMockBuilder(Manager::class)->setMethods($managerMethods)->getMock();
+ $backend = $this->createMock(\Test\Util\User\Dummy::class);
$userSession = new \OC\User\Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config);
- $user = $this->getMock('\OC\User\User', array(), array('foo', $backend));
+ $user = $this->getMockBuilder(User::class)->setConstructorArgs(['foo', $backend])->getMock();
$session->expects($this->never())
->method('set');
@@ -294,9 +304,9 @@ class SessionTest extends \Test\TestCase {
}
public function testLoginNonExisting() {
- $session = $this->getMock('\OC\Session\Memory', array(), array(''));
- $manager = $this->getMock('\OC\User\Manager');
- $backend = $this->getMock('\Test\Util\User\Dummy');
+ $session = $this->getMockBuilder(Memory::class)->setConstructorArgs([''])->getMock();
+ $manager = $this->createMock(Manager::class);
+ $backend = $this->createMock(\Test\Util\User\Dummy::class);
$userSession = new \OC\User\Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config);
$session->expects($this->never())
@@ -321,9 +331,9 @@ class SessionTest extends \Test\TestCase {
* when generating the token on the browser.
*/
public function testLoginWithDifferentTokenLoginName() {
- $session = $this->getMock('\OC\Session\Memory', array(), array(''));
- $manager = $this->getMock('\OC\User\Manager');
- $backend = $this->getMock('\Test\Util\User\Dummy');
+ $session = $this->getMockBuilder(Memory::class)->setConstructorArgs([''])->getMock();
+ $manager = $this->createMock(Manager::class);
+ $backend = $this->createMock(\Test\Util\User\Dummy::class);
$userSession = new \OC\User\Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config);
$username = 'user123';
$token = new \OC\Authentication\Token\DefaultToken();
@@ -353,8 +363,8 @@ class SessionTest extends \Test\TestCase {
$manager = $this->getMockBuilder('\OC\User\Manager')
->disableOriginalConstructor()
->getMock();
- $session = $this->getMock('\OCP\ISession');
- $request = $this->getMock('\OCP\IRequest');
+ $session = $this->createMock(ISession::class);
+ $request = $this->createMock(IRequest::class);
/** @var \OC\User\Session $userSession */
$userSession = $this->getMockBuilder('\OC\User\Session')
@@ -391,8 +401,8 @@ class SessionTest extends \Test\TestCase {
$manager = $this->getMockBuilder('\OC\User\Manager')
->disableOriginalConstructor()
->getMock();
- $session = $this->getMock('\OCP\ISession');
- $request = $this->getMock('\OCP\IRequest');
+ $session = $this->createMock(ISession::class);
+ $request = $this->createMock(IRequest::class);
/** @var \OC\User\Session $userSession */
$userSession = $this->getMockBuilder('\OC\User\Session')
@@ -435,8 +445,8 @@ class SessionTest extends \Test\TestCase {
$manager = $this->getMockBuilder('\OC\User\Manager')
->disableOriginalConstructor()
->getMock();
- $session = $this->getMock('\OCP\ISession');
- $request = $this->getMock('\OCP\IRequest');
+ $session = $this->createMock(ISession::class);
+ $request = $this->createMock(IRequest::class);
/** @var \OC\User\Session $userSession */
$userSession = $this->getMockBuilder('\OC\User\Session')
@@ -476,7 +486,7 @@ class SessionTest extends \Test\TestCase {
}
public function testRememberLoginValidToken() {
- $session = $this->getMock('\OC\Session\Memory', array(), array(''));
+ $session = $this->getMockBuilder(Memory::class)->setConstructorArgs([''])->getMock();
$session->expects($this->exactly(1))
->method('set')
->with($this->callback(function ($key) {
@@ -500,11 +510,11 @@ class SessionTest extends \Test\TestCase {
unset($managerMethods[$i]);
}
}
- $manager = $this->getMock('\OC\User\Manager', $managerMethods, array());
+ $manager = $this->getMockBuilder(Manager::class)->setMethods($managerMethods)->getMock();
- $backend = $this->getMock('\Test\Util\User\Dummy');
+ $backend = $this->createMock(\Test\Util\User\Dummy::class);
- $user = $this->getMock('\OC\User\User', array(), array('foo', $backend));
+ $user = $this->getMockBuilder(User::class)->setConstructorArgs(['foo', $backend])->getMock();
$user->expects($this->any())
->method('getUID')
@@ -521,12 +531,12 @@ class SessionTest extends \Test\TestCase {
$token = 'goodToken';
\OC::$server->getConfig()->setUserValue('foo', 'login_token', $token, time());
- $userSession = $this->getMock(
- '\OC\User\Session',
+ $userSession = $this->getMockBuilder(Session::class)
//override, otherwise tests will fail because of setcookie()
- array('setMagicInCookie'),
+ ->setMethods(['setMagicInCookie'])
//there are passed as parameters to the constructor
- array($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config));
+ ->setConstructorArgs([$manager, $session, $this->timeFactory, $this->tokenProvider, $this->config])
+ ->getMock();
$granted = $userSession->loginWithCookie('foo', $token);
@@ -534,7 +544,7 @@ class SessionTest extends \Test\TestCase {
}
public function testRememberLoginInvalidToken() {
- $session = $this->getMock('\OC\Session\Memory', array(), array(''));
+ $session = $this->getMockBuilder(Memory::class)->setConstructorArgs([''])->getMock();
$session->expects($this->never())
->method('set');
$session->expects($this->once())
@@ -550,11 +560,11 @@ class SessionTest extends \Test\TestCase {
unset($managerMethods[$i]);
}
}
- $manager = $this->getMock('\OC\User\Manager', $managerMethods, array());
+ $manager = $this->getMockBuilder(Manager::class)->setMethods($managerMethods)->getMock();
- $backend = $this->getMock('\Test\Util\User\Dummy');
+ $backend = $this->createMock(\Test\Util\User\Dummy::class);
- $user = $this->getMock('\OC\User\User', array(), array('foo', $backend));
+ $user = $this->getMockBuilder(User::class)->setConstructorArgs(['foo', $backend])->getMock();
$user->expects($this->any())
->method('getUID')
@@ -578,7 +588,7 @@ class SessionTest extends \Test\TestCase {
}
public function testRememberLoginInvalidUser() {
- $session = $this->getMock('\OC\Session\Memory', array(), array(''));
+ $session = $this->getMockBuilder(Memory::class)->setConstructorArgs([''])->getMock();
$session->expects($this->never())
->method('set');
$session->expects($this->once())
@@ -594,11 +604,11 @@ class SessionTest extends \Test\TestCase {
unset($managerMethods[$i]);
}
}
- $manager = $this->getMock('\OC\User\Manager', $managerMethods, array());
+ $manager = $this->getMockBuilder(Manager::class)->setMethods($managerMethods)->getMock();
- $backend = $this->getMock('\Test\Util\User\Dummy');
+ $backend = $this->createMock(\Test\Util\User\Dummy::class);
- $user = $this->getMock('\OC\User\User', array(), array('foo', $backend));
+ $user = $this->getMockBuilder(User::class)->setConstructorArgs(['foo', $backend])->getMock();
$user->expects($this->never())
->method('getUID');
@@ -656,16 +666,14 @@ class SessionTest extends \Test\TestCase {
}
public function testCreateSessionToken() {
- $manager = $this->getMockBuilder('\OC\User\Manager')
- ->disableOriginalConstructor()
- ->getMock();
- $session = $this->getMock('\OCP\ISession');
- $token = $this->getMock('\OC\Authentication\Token\IToken');
- $user = $this->getMock('\OCP\IUser');
+ $manager = $this->createMock(Manager::class);
+ $session = $this->createMock(ISession::class);
+ $token = $this->createMock(IToken::class);
+ $user = $this->createMock(IUser::class);
$userSession = new \OC\User\Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config);
- $random = $this->getMock('\OCP\Security\ISecureRandom');
- $config = $this->getMock('\OCP\IConfig');
+ $random = $this->createMock(ISecureRandom::class);
+ $config = $this->createMock(IConfig::class);
$csrf = $this->getMockBuilder('\OC\Security\CSRF\CsrfTokenManager')
->disableOriginalConstructor()
->getMock();
@@ -703,13 +711,13 @@ class SessionTest extends \Test\TestCase {
$manager = $this->getMockBuilder('\OC\User\Manager')
->disableOriginalConstructor()
->getMock();
- $session = $this->getMock('\OCP\ISession');
- $token = $this->getMock('\OC\Authentication\Token\IToken');
- $user = $this->getMock('\OCP\IUser');
+ $session = $this->createMock(ISession::class);
+ $token = $this->createMock(IToken::class);
+ $user = $this->createMock(IUser::class);
$userSession = new \OC\User\Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config);
- $random = $this->getMock('\OCP\Security\ISecureRandom');
- $config = $this->getMock('\OCP\IConfig');
+ $random = $this->createMock(ISecureRandom::class);
+ $config = $this->createMock(IConfig::class);
$csrf = $this->getMockBuilder('\OC\Security\CSRF\CsrfTokenManager')
->disableOriginalConstructor()
->getMock();
@@ -752,9 +760,9 @@ class SessionTest extends \Test\TestCase {
$manager = $this->getMockBuilder('\OC\User\Manager')
->disableOriginalConstructor()
->getMock();
- $session = $this->getMock('\OCP\ISession');
+ $session = $this->createMock(ISession::class);
$userSession = new \OC\User\Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config);
- $request = $this->getMock('\OCP\IRequest');
+ $request = $this->createMock(IRequest::class);
$uid = 'user123';
$loginName = 'User123';
@@ -780,12 +788,12 @@ class SessionTest extends \Test\TestCase {
$token->setLoginName('fritz');
$token->setUid('fritz0');
$token->setLastCheck(100); // Needs check
- $user = $this->getMock('\OCP\IUser');
+ $user = $this->createMock(IUser::class);
$userSession = $this->getMockBuilder('\OC\User\Session')
->setMethods(['logout'])
->setConstructorArgs([$manager, $session, $this->timeFactory, $this->tokenProvider, $this->config])
->getMock();
- $request = $this->getMock('\OCP\IRequest');
+ $request = $this->createMock(IRequest::class);
$request->expects($this->once())
->method('getHeader')
@@ -807,16 +815,16 @@ class SessionTest extends \Test\TestCase {
}
public function testValidateSessionDisabledUser() {
- $userManager = $this->getMock('\OCP\IUserManager');
- $session = $this->getMock('\OCP\ISession');
- $timeFactory = $this->getMock('\OCP\AppFramework\Utility\ITimeFactory');
- $tokenProvider = $this->getMock('\OC\Authentication\Token\IProvider');
+ $userManager = $this->createMock(IUserManager::class);
+ $session = $this->createMock(ISession::class);
+ $timeFactory = $this->createMock(ITimeFactory::class);
+ $tokenProvider = $this->createMock(IProvider::class);
$userSession = $this->getMockBuilder('\OC\User\Session')
->setConstructorArgs([$userManager, $session, $timeFactory, $tokenProvider, $this->config])
->setMethods(['logout'])
->getMock();
- $user = $this->getMock('\OCP\IUser');
+ $user = $this->createMock(IUser::class);
$token = new \OC\Authentication\Token\DefaultToken();
$token->setLoginName('susan');
$token->setLastCheck(20);
@@ -854,16 +862,16 @@ class SessionTest extends \Test\TestCase {
}
public function testValidateSessionNoPassword() {
- $userManager = $this->getMock('\OCP\IUserManager');
- $session = $this->getMock('\OCP\ISession');
- $timeFactory = $this->getMock('\OCP\AppFramework\Utility\ITimeFactory');
- $tokenProvider = $this->getMock('\OC\Authentication\Token\IProvider');
+ $userManager = $this->createMock(IUserManager::class);
+ $session = $this->createMock(ISession::class);
+ $timeFactory = $this->createMock(ITimeFactory::class);
+ $tokenProvider = $this->createMock(IProvider::class);
$userSession = $this->getMockBuilder('\OC\User\Session')
->setConstructorArgs([$userManager, $session, $timeFactory, $tokenProvider, $this->config])
->setMethods(['logout'])
->getMock();
- $user = $this->getMock('\OCP\IUser');
+ $user = $this->createMock(IUser::class);
$token = new \OC\Authentication\Token\DefaultToken();
$token->setLastCheck(20);
@@ -892,10 +900,10 @@ class SessionTest extends \Test\TestCase {
}
public function testUpdateSessionTokenPassword() {
- $userManager = $this->getMock('\OCP\IUserManager');
- $session = $this->getMock('\OCP\ISession');
- $timeFactory = $this->getMock('\OCP\AppFramework\Utility\ITimeFactory');
- $tokenProvider = $this->getMock('\OC\Authentication\Token\IProvider');
+ $userManager = $this->createMock(IUserManager::class);
+ $session = $this->createMock(ISession::class);
+ $timeFactory = $this->createMock(ITimeFactory::class);
+ $tokenProvider = $this->createMock(IProvider::class);
$userSession = new \OC\User\Session($userManager, $session, $timeFactory, $tokenProvider, $this->config);
$password = '123456';
@@ -917,10 +925,10 @@ class SessionTest extends \Test\TestCase {
}
public function testUpdateSessionTokenPasswordNoSessionAvailable() {
- $userManager = $this->getMock('\OCP\IUserManager');
- $session = $this->getMock('\OCP\ISession');
- $timeFactory = $this->getMock('\OCP\AppFramework\Utility\ITimeFactory');
- $tokenProvider = $this->getMock('\OC\Authentication\Token\IProvider');
+ $userManager = $this->createMock(IUserManager::class);
+ $session = $this->createMock(ISession::class);
+ $timeFactory = $this->createMock(ITimeFactory::class);
+ $tokenProvider = $this->createMock(IProvider::class);
$userSession = new \OC\User\Session($userManager, $session, $timeFactory, $tokenProvider, $this->config);
$session->expects($this->once())
@@ -931,10 +939,10 @@ class SessionTest extends \Test\TestCase {
}
public function testUpdateSessionTokenPasswordInvalidTokenException() {
- $userManager = $this->getMock('\OCP\IUserManager');
- $session = $this->getMock('\OCP\ISession');
- $timeFactory = $this->getMock('\OCP\AppFramework\Utility\ITimeFactory');
- $tokenProvider = $this->getMock('\OC\Authentication\Token\IProvider');
+ $userManager = $this->createMock(IUserManager::class);
+ $session = $this->createMock(ISession::class);
+ $timeFactory = $this->createMock(ITimeFactory::class);
+ $tokenProvider = $this->createMock(IProvider::class);
$userSession = new \OC\User\Session($userManager, $session, $timeFactory, $tokenProvider, $this->config);
$password = '123456';
diff --git a/tests/lib/User/UserTest.php b/tests/lib/User/UserTest.php
index a49bddde9eb..69f75d07762 100644
--- a/tests/lib/User/UserTest.php
+++ b/tests/lib/User/UserTest.php
@@ -10,6 +10,7 @@
namespace Test\User;
use OC\Hooks\PublicEmitter;
+use OC\User\Database;
/**
* Class UserTest
@@ -23,7 +24,7 @@ class UserTest extends \Test\TestCase {
/**
* @var \OC\User\Backend | \PHPUnit_Framework_MockObject_MockObject $backend
*/
- $backend = $this->getMock('\OC\User\Backend');
+ $backend = $this->createMock(\OC\User\Backend::class);
$backend->expects($this->once())
->method('getDisplayName')
->with($this->equalTo('foo'))
@@ -45,7 +46,7 @@ class UserTest extends \Test\TestCase {
/**
* @var \OC\User\Backend | \PHPUnit_Framework_MockObject_MockObject $backend
*/
- $backend = $this->getMock('\OC\User\Backend');
+ $backend = $this->createMock(\OC\User\Backend::class);
$backend->expects($this->once())
->method('getDisplayName')
->with($this->equalTo('foo'))
@@ -64,7 +65,7 @@ class UserTest extends \Test\TestCase {
/**
* @var \OC\User\Backend | \PHPUnit_Framework_MockObject_MockObject $backend
*/
- $backend = $this->getMock('\OC\User\Backend');
+ $backend = $this->createMock(\OC\User\Backend::class);
$backend->expects($this->never())
->method('getDisplayName');
@@ -81,7 +82,7 @@ class UserTest extends \Test\TestCase {
/**
* @var \OC\User\Backend | \PHPUnit_Framework_MockObject_MockObject $backend
*/
- $backend = $this->getMock('\Test\Util\User\Dummy');
+ $backend = $this->createMock(\Test\Util\User\Dummy::class);
$backend->expects($this->once())
->method('setPassword')
->with($this->equalTo('foo'), $this->equalTo('bar'));
@@ -104,7 +105,7 @@ class UserTest extends \Test\TestCase {
/**
* @var \OC\User\Backend | \PHPUnit_Framework_MockObject_MockObject $backend
*/
- $backend = $this->getMock('\Test\Util\User\Dummy');
+ $backend = $this->createMock(\Test\Util\User\Dummy::class);
$backend->expects($this->never())
->method('setPassword');
@@ -120,7 +121,7 @@ class UserTest extends \Test\TestCase {
/**
* @var \OC\User\Backend | \PHPUnit_Framework_MockObject_MockObject $backend
*/
- $backend = $this->getMock('Test\User\AvatarUserDummy');
+ $backend = $this->createMock(AvatarUserDummy::class);
$backend->expects($this->once())
->method('canChangeAvatar')
->with($this->equalTo('foo'))
@@ -144,7 +145,7 @@ class UserTest extends \Test\TestCase {
/**
* @var \OC\User\Backend | \PHPUnit_Framework_MockObject_MockObject $backend
*/
- $backend = $this->getMock('Test\User\AvatarUserDummy');
+ $backend = $this->createMock(AvatarUserDummy::class);
$backend->expects($this->once())
->method('canChangeAvatar')
->with($this->equalTo('foo'))
@@ -168,7 +169,7 @@ class UserTest extends \Test\TestCase {
/**
* @var \OC\User\Backend | \PHPUnit_Framework_MockObject_MockObject $backend
*/
- $backend = $this->getMock('Test\User\AvatarUserDummy');
+ $backend = $this->createMock(AvatarUserDummy::class);
$backend->expects($this->never())
->method('canChangeAvatar');
@@ -186,7 +187,7 @@ class UserTest extends \Test\TestCase {
/**
* @var \OC\User\Backend | \PHPUnit_Framework_MockObject_MockObject $backend
*/
- $backend = $this->getMock('\Test\Util\User\Dummy');
+ $backend = $this->createMock(\Test\Util\User\Dummy::class);
$backend->expects($this->once())
->method('deleteUser')
->with($this->equalTo('foo'));
@@ -199,7 +200,7 @@ class UserTest extends \Test\TestCase {
/**
* @var \OC\User\Backend | \PHPUnit_Framework_MockObject_MockObject $backend
*/
- $backend = $this->getMock('\Test\Util\User\Dummy');
+ $backend = $this->createMock(\Test\Util\User\Dummy::class);
$backend->expects($this->once())
->method('getHome')
->with($this->equalTo('foo'))
@@ -230,7 +231,7 @@ class UserTest extends \Test\TestCase {
/**
* @var \OC\User\Backend | \PHPUnit_Framework_MockObject_MockObject $backend
*/
- $backend = $this->getMock('\Test\Util\User\Dummy');
+ $backend = $this->createMock(\Test\Util\User\Dummy::class);
$backend->expects($this->never())
->method('getHome');
@@ -257,7 +258,7 @@ class UserTest extends \Test\TestCase {
/**
* @var \OC\User\Backend | \PHPUnit_Framework_MockObject_MockObject $backend
*/
- $backend = $this->getMock('\Test\Util\User\Dummy');
+ $backend = $this->createMock(\Test\Util\User\Dummy::class);
$backend->expects($this->any())
->method('implementsActions')
@@ -277,7 +278,7 @@ class UserTest extends \Test\TestCase {
/**
* @var \OC\User\Backend | \PHPUnit_Framework_MockObject_MockObject $backend
*/
- $backend = $this->getMock('\Test\Util\User\Dummy');
+ $backend = $this->createMock(\Test\Util\User\Dummy::class);
$backend->expects($this->any())
->method('implementsActions')
@@ -291,7 +292,7 @@ class UserTest extends \Test\TestCase {
/**
* @var \OC\User\Backend | \PHPUnit_Framework_MockObject_MockObject $backend
*/
- $backend = $this->getMock('\Test\Util\User\Dummy');
+ $backend = $this->createMock(\Test\Util\User\Dummy::class);
$backend->expects($this->any())
->method('implementsActions')
@@ -311,7 +312,7 @@ class UserTest extends \Test\TestCase {
/**
* @var \OC\User\Backend | \PHPUnit_Framework_MockObject_MockObject $backend
*/
- $backend = $this->getMock('\Test\Util\User\Dummy');
+ $backend = $this->createMock(\Test\Util\User\Dummy::class);
$backend->expects($this->any())
->method('implementsActions')
@@ -325,7 +326,7 @@ class UserTest extends \Test\TestCase {
/**
* @var \OC\User\Backend | \PHPUnit_Framework_MockObject_MockObject $backend
*/
- $backend = $this->getMock('\OC\User\Database');
+ $backend = $this->createMock(Database::class);
$backend->expects($this->any())
->method('implementsActions')
@@ -354,7 +355,7 @@ class UserTest extends \Test\TestCase {
/**
* @var \OC\User\Backend | \PHPUnit_Framework_MockObject_MockObject $backend
*/
- $backend = $this->getMock('\OC\User\Database');
+ $backend = $this->createMock(Database::class);
$backend->expects($this->any())
->method('implementsActions')
@@ -375,7 +376,7 @@ class UserTest extends \Test\TestCase {
/**
* @var \OC\User\Backend | \PHPUnit_Framework_MockObject_MockObject $backend
*/
- $backend = $this->getMock('\OC\User\Database');
+ $backend = $this->createMock(Database::class);
$backend->expects($this->any())
->method('implementsActions')
@@ -398,7 +399,7 @@ class UserTest extends \Test\TestCase {
/**
* @var \OC\User\Backend | \PHPUnit_Framework_MockObject_MockObject $backend
*/
- $backend = $this->getMock('\Test\Util\User\Dummy');
+ $backend = $this->createMock(\Test\Util\User\Dummy::class);
$backend->expects($this->once())
->method('setPassword');
@@ -439,7 +440,7 @@ class UserTest extends \Test\TestCase {
/**
* @var \OC\User\Backend | \PHPUnit_Framework_MockObject_MockObject $backend
*/
- $backend = $this->getMock('\Test\Util\User\Dummy');
+ $backend = $this->createMock(\Test\Util\User\Dummy::class);
$backend->expects($this->once())
->method('deleteUser');
@@ -464,7 +465,7 @@ class UserTest extends \Test\TestCase {
/**
* @var \OC\User\Backend | \PHPUnit_Framework_MockObject_MockObject $backend
*/
- $backend = $this->getMock('\Test\Util\User\Dummy');
+ $backend = $this->createMock(\Test\Util\User\Dummy::class);
$urlGenerator = $this->getMockBuilder('\OC\URLGenerator')
->setMethods(['getAbsoluteURL'])
->disableOriginalConstructor()->getMock();