summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2016-09-13 10:24:40 +0200
committerGitHub <noreply@github.com>2016-09-13 10:24:40 +0200
commit021d0ae2714b280b4fe0b23e90306b0aa1152956 (patch)
tree4734c7f6c2ea42f6cb8db7c2becfa16c2efc8b5e
parentf8450e507b36601f546233121a13f0a46b263697 (diff)
parent368f407698bb71e7b06f20812e19288a618c64f6 (diff)
downloadnextcloud-server-021d0ae2714b280b4fe0b23e90306b0aa1152956.tar.gz
nextcloud-server-021d0ae2714b280b4fe0b23e90306b0aa1152956.zip
Merge pull request #1378 from nextcloud/phpunit_db_fix
Fix getMock phpunit warnings
-rw-r--r--tests/Settings/Controller/UsersControllerTest.php29
-rw-r--r--tests/lib/AppTest.php13
-rw-r--r--tests/lib/BackgroundJob/JobListTest.php6
-rw-r--r--tests/lib/Cache/FileCacheTest.php10
-rw-r--r--tests/lib/Comments/ManagerTest.php9
-rw-r--r--tests/lib/Encryption/DecryptAllTest.php3
-rw-r--r--tests/lib/Files/Cache/CacheTest.php6
-rw-r--r--tests/lib/Files/Config/UserMountCacheTest.php2
-rw-r--r--tests/lib/Files/Node/FolderTest.php200
-rw-r--r--tests/lib/Files/Storage/Wrapper/QuotaTest.php18
-rw-r--r--tests/lib/Files/Utils/ScannerTest.php3
-rw-r--r--tests/lib/Files/ViewTest.php13
-rw-r--r--tests/lib/HelperStorageTest.php11
-rw-r--r--tests/lib/Lock/DBLockingProviderTest.php3
-rw-r--r--tests/lib/Repair/RepairUnmergedSharesTest.php9
-rw-r--r--tests/lib/Security/CertificateManagerTest.php5
-rw-r--r--tests/lib/Share20/ManagerTest.php2
-rw-r--r--tests/lib/TagsTest.php7
-rw-r--r--tests/lib/UrlGeneratorTest.php22
-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
-rw-r--r--tests/lib/UtilTest.php9
24 files changed, 352 insertions, 310 deletions
diff --git a/tests/Settings/Controller/UsersControllerTest.php b/tests/Settings/Controller/UsersControllerTest.php
index 244d1f744d3..e036e299e00 100644
--- a/tests/Settings/Controller/UsersControllerTest.php
+++ b/tests/Settings/Controller/UsersControllerTest.php
@@ -13,6 +13,9 @@ namespace Tests\Settings\Controller;
use \OC\Settings\Application;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
+use OCP\IAvatar;
+use OCP\IAvatarManager;
+use OCP\IUser;
/**
* @group DB
@@ -60,11 +63,11 @@ class UsersControllerTest extends \Test\TestCase {
/*
* Set default avtar behaviour for whole testsuite
*/
- $this->container['OCP\\IAvatarManager'] = $this->getMock('OCP\IAvatarManager');
+ $this->container['OCP\\IAvatarManager'] = $this->createMock(IAvatarManager::class);
- $avatarExists = $this->getMock('OCP\IAvatar');
+ $avatarExists = $this->createMock(IAvatar::class);
$avatarExists->method('exists')->willReturn(true);
- $avatarNotExists = $this->getMock('OCP\IAvatar');
+ $avatarNotExists = $this->createMock(IAvatar::class);
$avatarNotExists->method('exists')->willReturn(false);
$this->container['OCP\\IAvatarManager']
->method('getAvatar')
@@ -1861,7 +1864,7 @@ class UsersControllerTest extends \Test\TestCase {
}
public function testSetDisplayNameNull() {
- $user = $this->getMock('\OCP\IUser');
+ $user = $this->createMock(IUser::class);
$user->method('getUID')->willReturn('userName');
$this->container['UserSession']
@@ -1885,33 +1888,33 @@ class UsersControllerTest extends \Test\TestCase {
public function dataSetDisplayName() {
$data = [];
- $user1 = $this->getMock('\OCP\IUser');
+ $user1 = $this->createMock(IUser::class);
$user1->method('getUID')->willReturn('user1');
$user1->method('canChangeDisplayName')->willReturn(true);
$data[] = [$user1, $user1, false, false, true];
- $user1 = $this->getMock('\OCP\IUser');
+ $user1 = $this->createMock(IUser::class);
$user1->method('getUID')->willReturn('user1');
$user1->method('canChangeDisplayName')->willReturn(false);
$data[] = [$user1, $user1, false, false, false];
- $user1 = $this->getMock('\OCP\IUser');
+ $user1 = $this->createMock(IUser::class);
$user1->method('getUID')->willReturn('user1');
- $user2 = $this->getMock('\OCP\IUser');
+ $user2 = $this->createMock(IUser::class);
$user2->method('getUID')->willReturn('user2');
$user2->method('canChangeDisplayName')->willReturn(true);
$data[] = [$user1, $user2, false, false, false];
- $user1 = $this->getMock('\OCP\IUser');
+ $user1 = $this->createMock(IUser::class);
$user1->method('getUID')->willReturn('user1');
- $user2 = $this->getMock('\OCP\IUser');
+ $user2 = $this->createMock(IUser::class);
$user2->method('getUID')->willReturn('user2');
$user2->method('canChangeDisplayName')->willReturn(true);
$data[] = [$user1, $user2, true, false, true];
- $user1 = $this->getMock('\OCP\IUser');
+ $user1 = $this->createMock(IUser::class);
$user1->method('getUID')->willReturn('user1');
- $user2 = $this->getMock('\OCP\IUser');
+ $user2 = $this->createMock(IUser::class);
$user2->method('getUID')->willReturn('user2');
$user2->method('canChangeDisplayName')->willReturn(true);
$data[] = [$user1, $user2, false, true, true];
@@ -1981,7 +1984,7 @@ class UsersControllerTest extends \Test\TestCase {
}
public function testSetDisplayNameFails() {
- $user = $this->getMock('\OCP\IUser');
+ $user = $this->createMock(IUser::class);
$user->method('canChangeDisplayname')->willReturn(true);
$user->method('getUID')->willReturn('user');
$user->expects($this->once())
diff --git a/tests/lib/AppTest.php b/tests/lib/AppTest.php
index 64311f6e4ae..ac4fb913beb 100644
--- a/tests/lib/AppTest.php
+++ b/tests/lib/AppTest.php
@@ -8,6 +8,7 @@
*/
namespace Test;
+use OC\AppConfig;
use OCP\IAppConfig;
/**
@@ -476,13 +477,11 @@ class AppTest extends \Test\TestCase {
private function setupAppConfigMock() {
- $appConfig = $this->getMock(
- '\OC\AppConfig',
- array('getValues'),
- array(\OC::$server->getDatabaseConnection()),
- '',
- false
- );
+ $appConfig = $this->getMockBuilder(AppConfig::class)
+ ->setMethods(['getValues'])
+ ->setConstructorArgs([\OC::$server->getDatabaseConnection()])
+ ->disableOriginalConstructor()
+ ->getMock();
$this->registerAppConfig($appConfig);
return $appConfig;
diff --git a/tests/lib/BackgroundJob/JobListTest.php b/tests/lib/BackgroundJob/JobListTest.php
index b8dcb735a26..78299e81546 100644
--- a/tests/lib/BackgroundJob/JobListTest.php
+++ b/tests/lib/BackgroundJob/JobListTest.php
@@ -8,8 +8,10 @@
namespace Test\BackgroundJob;
+use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\IJob;
use OCP\DB\QueryBuilder\IQueryBuilder;
+use OCP\IConfig;
use Test\TestCase;
/**
@@ -36,8 +38,8 @@ class JobListTest extends TestCase {
$this->connection = \OC::$server->getDatabaseConnection();
$this->clearJobsList();
- $this->config = $this->getMock('OCP\IConfig');
- $this->timeFactory = $this->getMock('OCP\AppFramework\Utility\ITimeFactory');
+ $this->config = $this->createMock(IConfig::class);
+ $this->timeFactory = $this->createMock(ITimeFactory::class);
$this->instance = new \OC\BackgroundJob\JobList(
$this->connection,
$this->config,
diff --git a/tests/lib/Cache/FileCacheTest.php b/tests/lib/Cache/FileCacheTest.php
index d2725bf9033..a90fc6678e9 100644
--- a/tests/lib/Cache/FileCacheTest.php
+++ b/tests/lib/Cache/FileCacheTest.php
@@ -21,6 +21,7 @@
*/
namespace Test\Cache;
+use OC\Files\Storage\Local;
/**
* Class FileCacheTest
@@ -102,11 +103,10 @@ class FileCacheTest extends TestCache {
}
private function setupMockStorage() {
- $mockStorage = $this->getMock(
- '\OC\Files\Storage\Local',
- ['filemtime', 'unlink'],
- [['datadir' => \OC::$server->getTempManager()->getTemporaryFolder()]]
- );
+ $mockStorage = $this->getMockBuilder(Local::class)
+ ->setMethods(['filemtime', 'unlink'])
+ ->setConstructorArgs([['datadir' => \OC::$server->getTempManager()->getTemporaryFolder()]])
+ ->getMock();
\OC\Files\Filesystem::mount($mockStorage, array(), '/test/cache');
diff --git a/tests/lib/Comments/ManagerTest.php b/tests/lib/Comments/ManagerTest.php
index 90a8399eb2b..730d82d9d0d 100644
--- a/tests/lib/Comments/ManagerTest.php
+++ b/tests/lib/Comments/ManagerTest.php
@@ -3,6 +3,7 @@
namespace Test\Comments;
use OCP\Comments\ICommentsManager;
+use OCP\IUser;
use Test\TestCase;
/**
@@ -561,7 +562,7 @@ class ManagerTest extends TestCase {
}
public function testSetMarkRead() {
- $user = $this->getMock('\OCP\IUser');
+ $user = $this->createMock(IUser::class);
$user->expects($this->any())
->method('getUID')
->will($this->returnValue('alice'));
@@ -577,7 +578,7 @@ class ManagerTest extends TestCase {
}
public function testSetMarkReadUpdate() {
- $user = $this->getMock('\OCP\IUser');
+ $user = $this->createMock(IUser::class);
$user->expects($this->any())
->method('getUID')
->will($this->returnValue('alice'));
@@ -596,7 +597,7 @@ class ManagerTest extends TestCase {
}
public function testReadMarkDeleteUser() {
- $user = $this->getMock('\OCP\IUser');
+ $user = $this->createMock(IUser::class);
$user->expects($this->any())
->method('getUID')
->will($this->returnValue('alice'));
@@ -613,7 +614,7 @@ class ManagerTest extends TestCase {
}
public function testReadMarkDeleteObject() {
- $user = $this->getMock('\OCP\IUser');
+ $user = $this->createMock(IUser::class);
$user->expects($this->any())
->method('getUID')
->will($this->returnValue('alice'));
diff --git a/tests/lib/Encryption/DecryptAllTest.php b/tests/lib/Encryption/DecryptAllTest.php
index ed86b743c3b..7859a65ff6d 100644
--- a/tests/lib/Encryption/DecryptAllTest.php
+++ b/tests/lib/Encryption/DecryptAllTest.php
@@ -29,6 +29,7 @@ use OC\Encryption\Manager;
use OC\Files\FileInfo;
use OC\Files\View;
use OCP\IUserManager;
+use Symfony\Component\Console\Formatter\OutputFormatterInterface;
use Test\TestCase;
/**
@@ -78,7 +79,7 @@ class DecryptAllTest extends TestCase {
->disableOriginalConstructor()->getMock();
$this->outputInterface->expects($this->any())->method('getFormatter')
- ->willReturn($this->getMock('\Symfony\Component\Console\Formatter\OutputFormatterInterface'));
+ ->willReturn($this->createMock(OutputFormatterInterface::class));
$this->instance = new DecryptAll($this->encryptionManager, $this->userManager, $this->view);
diff --git a/tests/lib/Files/Cache/CacheTest.php b/tests/lib/Files/Cache/CacheTest.php
index bfc3c1be7b8..4a2581fbc54 100644
--- a/tests/lib/Files/Cache/CacheTest.php
+++ b/tests/lib/Files/Cache/CacheTest.php
@@ -10,6 +10,7 @@ namespace Test\Files\Cache;
use Doctrine\DBAL\Platforms\MySqlPlatform;
+use OC\Files\Cache\Cache;
class LongId extends \OC\Files\Storage\Temporary {
public function getId() {
@@ -500,7 +501,10 @@ class CacheTest extends \Test\TestCase {
/**
* @var \OC\Files\Cache\Cache | \PHPUnit_Framework_MockObject_MockObject $cacheMock
*/
- $cacheMock = $this->getMock('\OC\Files\Cache\Cache', array('normalize'), array($this->storage), '', true);
+ $cacheMock = $this->getMockBuilder(Cache::class)
+ ->setMethods(['normalize'])
+ ->setConstructorArgs([$this->storage])
+ ->getMock();
$cacheMock->expects($this->any())
->method('normalize')
diff --git a/tests/lib/Files/Config/UserMountCacheTest.php b/tests/lib/Files/Config/UserMountCacheTest.php
index b9e09687c95..85bc4146a2d 100644
--- a/tests/lib/Files/Config/UserMountCacheTest.php
+++ b/tests/lib/Files/Config/UserMountCacheTest.php
@@ -47,7 +47,7 @@ class UserMountCacheTest extends TestCase {
$userBackend->createUser('u1', '');
$userBackend->createUser('u2', '');
$this->userManager->registerBackend($userBackend);
- $this->cache = new \OC\Files\Config\UserMountCache($this->connection, $this->userManager, $this->getMock('\OC\Log'));
+ $this->cache = new \OC\Files\Config\UserMountCache($this->connection, $this->userManager, $this->createMock(Log::class));
}
public function tearDown() {
diff --git a/tests/lib/Files/Node/FolderTest.php b/tests/lib/Files/Node/FolderTest.php
index 18acfcae1fa..17cb2f2caa2 100644
--- a/tests/lib/Files/Node/FolderTest.php
+++ b/tests/lib/Files/Node/FolderTest.php
@@ -10,13 +10,17 @@ namespace Test\Files\Node;
use OC\Files\Cache\Cache;
use OC\Files\FileInfo;
+use OC\Files\Mount\Manager;
use OC\Files\Mount\MountPoint;
use OC\Files\Node\Node;
+use OC\Files\Node\Root;
use OC\Files\Storage\Temporary;
use OC\Files\Storage\Wrapper\Jail;
+use OCP\Files\Mount\IMountPoint;
use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
use OC\Files\View;
+use OCP\Files\Storage;
/**
* Class FolderTest
@@ -34,7 +38,7 @@ class FolderTest extends \Test\TestCase {
}
protected function getMockStorage() {
- $storage = $this->getMock('\OCP\Files\Storage');
+ $storage = $this->createMock(Storage::class);
$storage->expects($this->any())
->method('getId')
->will($this->returnValue('home::someuser'));
@@ -46,12 +50,14 @@ class FolderTest extends \Test\TestCase {
}
public function testDelete() {
- $manager = $this->getMock('\OC\Files\Mount\Manager');
+ $manager = $this->createMock(Manager::class);
/**
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/
- $view = $this->getMock('\OC\Files\View');
- $root = $this->getMock('\OC\Files\Node\Root', array(), array($manager, $view, $this->user));
+ $view = $this->createMock(View::class);
+ $root = $this->getMockBuilder(Root::class)
+ ->setConstructorArgs([$manager, $view, $this->user])
+ ->getMock();
$root->expects($this->any())
->method('getUser')
->will($this->returnValue($this->user));
@@ -99,11 +105,11 @@ class FolderTest extends \Test\TestCase {
/**
* @var \OC\Files\Mount\Manager $manager
*/
- $manager = $this->getMock('\OC\Files\Mount\Manager');
+ $manager = $this->createMock(Manager::class);
/**
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/
- $view = $this->getMock('\OC\Files\View');
+ $view = $this->createMock(View::class);
$root = new \OC\Files\Node\Root($manager, $view, $this->user);
$root->listen('\OC\Files', 'preDelete', $preListener);
$root->listen('\OC\Files', 'postDelete', $postListener);
@@ -131,12 +137,12 @@ class FolderTest extends \Test\TestCase {
* @expectedException \OCP\Files\NotPermittedException
*/
public function testDeleteNotPermitted() {
- $manager = $this->getMock('\OC\Files\Mount\Manager');
+ $manager = $this->createMock(Manager::class);
/**
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/
- $view = $this->getMock('\OC\Files\View');
- $root = $this->getMock('\OC\Files\Node\Root', array(), array($manager, $view, $this->user));
+ $view = $this->createMock(View::class);
+ $root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user])->getMock();
$root->expects($this->any())
->method('getUser')
->will($this->returnValue($this->user));
@@ -151,12 +157,14 @@ class FolderTest extends \Test\TestCase {
}
public function testGetDirectoryContent() {
- $manager = $this->getMock('\OC\Files\Mount\Manager');
+ $manager = $this->createMock(Manager::class);
/**
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/
- $view = $this->getMock('\OC\Files\View');
- $root = $this->getMock('\OC\Files\Node\Root', array(), array($manager, $view, $this->user));
+ $view = $this->createMock(View::class);
+ $root = $this->getMockBuilder(Root::class)
+ ->setConstructorArgs([$manager, $view, $this->user])
+ ->getMock();
$root->expects($this->any())
->method('getUser')
->will($this->returnValue($this->user));
@@ -181,12 +189,12 @@ class FolderTest extends \Test\TestCase {
}
public function testGet() {
- $manager = $this->getMock('\OC\Files\Mount\Manager');
+ $manager = $this->createMock(Manager::class);
/**
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/
- $view = $this->getMock('\OC\Files\View');
- $root = $this->getMock('\OC\Files\Node\Root', array(), array($manager, $view, $this->user));
+ $view = $this->createMock(View::class);
+ $root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user])->getMock();
$root->expects($this->any())
->method('getUser')
->will($this->returnValue($this->user));
@@ -200,12 +208,12 @@ class FolderTest extends \Test\TestCase {
}
public function testNodeExists() {
- $manager = $this->getMock('\OC\Files\Mount\Manager');
+ $manager = $this->createMock(Manager::class);
/**
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/
- $view = $this->getMock('\OC\Files\View');
- $root = $this->getMock('\OC\Files\Node\Root', array(), array($manager, $view, $this->user));
+ $view = $this->createMock(View::class);
+ $root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user])->getMock();
$root->expects($this->any())
->method('getUser')
->will($this->returnValue($this->user));
@@ -222,12 +230,12 @@ class FolderTest extends \Test\TestCase {
}
public function testNodeExistsNotExists() {
- $manager = $this->getMock('\OC\Files\Mount\Manager');
+ $manager = $this->createMock(Manager::class);
/**
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/
- $view = $this->getMock('\OC\Files\View');
- $root = $this->getMock('\OC\Files\Node\Root', array(), array($manager, $view, $this->user));
+ $view = $this->createMock(View::class);
+ $root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user])->getMock();
$root->expects($this->any())
->method('getUser')
->will($this->returnValue($this->user));
@@ -242,12 +250,12 @@ class FolderTest extends \Test\TestCase {
}
public function testNewFolder() {
- $manager = $this->getMock('\OC\Files\Mount\Manager');
+ $manager = $this->createMock(Manager::class);
/**
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/
- $view = $this->getMock('\OC\Files\View');
- $root = $this->getMock('\OC\Files\Node\Root', array(), array($manager, $view, $this->user));
+ $view = $this->createMock(View::class);
+ $root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user])->getMock();
$root->expects($this->any())
->method('getUser')
->will($this->returnValue($this->user));
@@ -272,12 +280,12 @@ class FolderTest extends \Test\TestCase {
* @expectedException \OCP\Files\NotPermittedException
*/
public function testNewFolderNotPermitted() {
- $manager = $this->getMock('\OC\Files\Mount\Manager');
+ $manager = $this->createMock(Manager::class);
/**
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/
- $view = $this->getMock('\OC\Files\View');
- $root = $this->getMock('\OC\Files\Node\Root', array(), array($manager, $view, $this->user));
+ $view = $this->createMock(View::class);
+ $root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user])->getMock();
$root->expects($this->any())
->method('getUser')
->will($this->returnValue($this->user));
@@ -292,12 +300,12 @@ class FolderTest extends \Test\TestCase {
}
public function testNewFile() {
- $manager = $this->getMock('\OC\Files\Mount\Manager');
+ $manager = $this->createMock(Manager::class);
/**
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/
- $view = $this->getMock('\OC\Files\View');
- $root = $this->getMock('\OC\Files\Node\Root', array(), array($manager, $view, $this->user));
+ $view = $this->createMock(View::class);
+ $root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user])->getMock();
$root->expects($this->any())
->method('getUser')
->will($this->returnValue($this->user));
@@ -322,12 +330,12 @@ class FolderTest extends \Test\TestCase {
* @expectedException \OCP\Files\NotPermittedException
*/
public function testNewFileNotPermitted() {
- $manager = $this->getMock('\OC\Files\Mount\Manager');
+ $manager = $this->createMock(Manager::class);
/**
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/
- $view = $this->getMock('\OC\Files\View');
- $root = $this->getMock('\OC\Files\Node\Root', array(), array($manager, $view, $this->user));
+ $view = $this->createMock(View::class);
+ $root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user])->getMock();
$root->expects($this->any())
->method('getUser')
->will($this->returnValue($this->user));
@@ -342,12 +350,12 @@ class FolderTest extends \Test\TestCase {
}
public function testGetFreeSpace() {
- $manager = $this->getMock('\OC\Files\Mount\Manager');
+ $manager = $this->createMock(Manager::class);
/**
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/
- $view = $this->getMock('\OC\Files\View');
- $root = $this->getMock('\OC\Files\Node\Root', array(), array($manager, $view, $this->user));
+ $view = $this->createMock(View::class);
+ $root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user])->getMock();
$root->expects($this->any())
->method('getUser')
->will($this->returnValue($this->user));
@@ -362,23 +370,23 @@ class FolderTest extends \Test\TestCase {
}
public function testSearch() {
- $manager = $this->getMock('\OC\Files\Mount\Manager');
+ $manager = $this->createMock(Manager::class);
/**
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/
- $view = $this->getMock('\OC\Files\View');
- $root = $this->getMock('\OC\Files\Node\Root', array(), array($manager, $view, $this->user));
+ $view = $this->createMock(View::class);
+ $root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user])->getMock();
$root->expects($this->any())
->method('getUser')
->will($this->returnValue($this->user));
- $storage = $this->getMock('\OC\Files\Storage\Storage');
- $cache = $this->getMock('\OC\Files\Cache\Cache', array(), array(''));
+ $storage = $this->createMock(Storage::class);
+ $cache = $this->getMockBuilder(Cache::class)->setConstructorArgs([''])->getMock();
$storage->expects($this->once())
->method('getCache')
->will($this->returnValue($cache));
- $mount = $this->getMock('\OCP\Files\Mount\IMountPoint');
+ $mount = $this->createMock(IMountPoint::class);
$mount->expects($this->once())
->method('getStorage')
->will($this->returnValue($storage));
@@ -410,19 +418,19 @@ class FolderTest extends \Test\TestCase {
}
public function testSearchInRoot() {
- $manager = $this->getMock('\OC\Files\Mount\Manager');
+ $manager = $this->createMock(Manager::class);
/**
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/
- $view = $this->getMock('\OC\Files\View');
- $root = $this->getMock('\OC\Files\Node\Root', array('getUser', 'getMountsIn', 'getMount'), array($manager, $view, $this->user));
+ $view = $this->createMock(View::class);
+ $root = $this->getMockBuilder(Root::class)->setMethods(['getUser', 'getMountsIn', 'getMount'])->setConstructorArgs([$manager, $view, $this->user])->getMock();
$root->expects($this->any())
->method('getUser')
->will($this->returnValue($this->user));
- $storage = $this->getMock('\OC\Files\Storage\Storage');
- $cache = $this->getMock('\OC\Files\Cache\Cache', array(), array(''));
+ $storage = $this->createMock(Storage::class);
+ $cache = $this->getMockBuilder(Cache::class)->setConstructorArgs([''])->getMock();
- $mount = $this->getMock('\OCP\Files\Mount\IMountPoint');
+ $mount = $this->createMock(IMountPoint::class);
$mount->expects($this->once())
->method('getStorage')
->will($this->returnValue($storage));
@@ -458,19 +466,19 @@ class FolderTest extends \Test\TestCase {
}
public function testSearchInStorageRoot() {
- $manager = $this->getMock('\OC\Files\Mount\Manager');
+ $manager = $this->createMock(Manager::class);
/**
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/
- $view = $this->getMock('\OC\Files\View');
- $root = $this->getMock('\OC\Files\Node\Root', array(), array($manager, $view, $this->user));
+ $view = $this->createMock(View::class);
+ $root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user])->getMock();
$root->expects($this->any())
->method('getUser')
->will($this->returnValue($this->user));
- $storage = $this->getMock('\OC\Files\Storage\Storage');
- $cache = $this->getMock('\OC\Files\Cache\Cache', array(), array(''));
+ $storage = $this->createMock(Storage::class);
+ $cache = $this->getMockBuilder(Cache::class)->setConstructorArgs([''])->getMock();
- $mount = $this->getMock('\OCP\Files\Mount\IMountPoint');
+ $mount = $this->createMock(IMountPoint::class);
$mount->expects($this->once())
->method('getStorage')
->will($this->returnValue($storage));
@@ -506,19 +514,19 @@ class FolderTest extends \Test\TestCase {
}
public function testSearchByTag() {
- $manager = $this->getMock('\OC\Files\Mount\Manager');
+ $manager = $this->createMock(Manager::class);
/**
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/
- $view = $this->getMock('\OC\Files\View');
- $root = $this->getMock('\OC\Files\Node\Root', array(), array($manager, $view, $this->user));
+ $view = $this->createMock(View::class);
+ $root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user])->getMock();
$root->expects($this->any())
->method('getUser')
->will($this->returnValue($this->user));
- $storage = $this->getMock('\OC\Files\Storage\Storage');
- $cache = $this->getMock('\OC\Files\Cache\Cache', array(), array(''));
+ $storage = $this->createMock(Storage::class);
+ $cache = $this->getMockBuilder(Cache::class)->setConstructorArgs([''])->getMock();
- $mount = $this->getMock('\OCP\Files\Mount\IMountPoint');
+ $mount = $this->createMock(IMountPoint::class);
$mount->expects($this->once())
->method('getStorage')
->will($this->returnValue($storage));
@@ -554,22 +562,22 @@ class FolderTest extends \Test\TestCase {
}
public function testSearchSubStorages() {
- $manager = $this->getMock('\OC\Files\Mount\Manager');
+ $manager = $this->createMock(Manager::class);
/**
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/
- $view = $this->getMock('\OC\Files\View');
- $root = $this->getMock('\OC\Files\Node\Root', array(), array($manager, $view, $this->user));
+ $view = $this->createMock(View::class);
+ $root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user])->getMock();
$root->expects($this->any())
->method('getUser')
->will($this->returnValue($this->user));
- $storage = $this->getMock('\OC\Files\Storage\Storage');
- $cache = $this->getMock('\OC\Files\Cache\Cache', array(), array(''));
- $subCache = $this->getMock('\OC\Files\Cache\Cache', array(), array(''));
- $subStorage = $this->getMock('\OC\Files\Storage\Storage');
- $subMount = $this->getMock('\OC\Files\Mount\MountPoint', array(), array(null, ''));
+ $storage = $this->createMock(Storage::class);
+ $cache = $this->getMockBuilder(Cache::class)->setConstructorArgs([''])->getMock();
+ $subCache = $this->getMockBuilder(Cache::class)->setConstructorArgs([''])->getMock();
+ $subStorage = $this->createMock(Storage::class);
+ $subMount = $this->getMockBuilder(MountPoint::class)->setConstructorArgs([null, ''])->getMock();
- $mount = $this->getMock('\OCP\Files\Mount\IMountPoint');
+ $mount = $this->createMock(IMountPoint::class);
$mount->expects($this->once())
->method('getStorage')
->will($this->returnValue($storage));
@@ -634,18 +642,18 @@ class FolderTest extends \Test\TestCase {
}
public function testGetById() {
- $manager = $this->getMock('\OC\Files\Mount\Manager');
+ $manager = $this->createMock(Manager::class);
/**
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/
- $view = $this->getMock('\OC\Files\View');
- $root = $this->getMock('\OC\Files\Node\Root', array('getUser', 'getMountsIn', 'getMount'), array($manager, $view, $this->user));
+ $view = $this->createMock(View::class);
+ $root = $this->getMockBuilder(Root::class)->setMethods(['getUser', 'getMountsIn', 'getMount'])->setConstructorArgs([$manager, $view, $this->user])->getMock();
$root->expects($this->any())
->method('getUser')
->will($this->returnValue($this->user));
- $storage = $this->getMock('\OC\Files\Storage\Storage');
+ $storage = $this->createMock(\OC\Files\Storage\Storage::class);
$mount = new MountPoint($storage, '/bar');
- $cache = $this->getMock('\OC\Files\Cache\Cache', array(), array(''));
+ $cache = $this->getMockBuilder(Cache::class)->setConstructorArgs([''])->getMock();
$view->expects($this->once())
->method('getFileInfo')
@@ -677,18 +685,18 @@ class FolderTest extends \Test\TestCase {
}
public function testGetByIdOutsideFolder() {
- $manager = $this->getMock('\OC\Files\Mount\Manager');
+ $manager = $this->createMock(Manager::class);
/**
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/
- $view = $this->getMock('\OC\Files\View');
- $root = $this->getMock('\OC\Files\Node\Root', array('getUser', 'getMountsIn', 'getMount'), array($manager, $view, $this->user));
+ $view = $this->createMock(View::class);
+ $root = $this->getMockBuilder(Root::class)->setMethods(['getUser', 'getMountsIn', 'getMount'])->setConstructorArgs([$manager, $view, $this->user])->getMock();
$root->expects($this->any())
->method('getUser')
->will($this->returnValue($this->user));
- $storage = $this->getMock('\OC\Files\Storage\Storage');
+ $storage = $this->createMock(\OC\Files\Storage\Storage::class);
$mount = new MountPoint($storage, '/bar');
- $cache = $this->getMock('\OC\Files\Cache\Cache', array(), array(''));
+ $cache = $this->getMockBuilder(Cache::class)->setConstructorArgs([''])->getMock();
$storage->expects($this->once())
->method('getCache')
@@ -715,19 +723,19 @@ class FolderTest extends \Test\TestCase {
}
public function testGetByIdMultipleStorages() {
- $manager = $this->getMock('\OC\Files\Mount\Manager');
+ $manager = $this->createMock(Manager::class);
/**
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/
- $view = $this->getMock('\OC\Files\View');
- $root = $this->getMock('\OC\Files\Node\Root', array('getUser', 'getMountsIn', 'getMount'), array($manager, $view, $this->user));
+ $view = $this->createMock(View::class);
+ $root = $this->getMockBuilder(Root::class)->setMethods(['getUser', 'getMountsIn', 'getMount'])->setConstructorArgs([$manager, $view, $this->user])->getMock();
$root->expects($this->any())
->method('getUser')
->will($this->returnValue($this->user));
- $storage = $this->getMock('\OC\Files\Storage\Storage');
+ $storage = $this->createMock(\OC\Files\Storage\Storage::class);
$mount1 = new MountPoint($storage, '/bar');
$mount2 = new MountPoint($storage, '/bar/foo/asd');
- $cache = $this->getMock('\OC\Files\Cache\Cache', array(), array(''));
+ $cache = $this->getMockBuilder(Cache::class)->setConstructorArgs([''])->getMock();
$view->expects($this->any())
->method('getFileInfo')
@@ -772,13 +780,13 @@ class FolderTest extends \Test\TestCase {
* @dataProvider uniqueNameProvider
*/
public function testGetUniqueName($name, $existingFiles, $expected) {
- $manager = $this->getMock('\OC\Files\Mount\Manager');
+ $manager = $this->createMock(Manager::class);
$folderPath = '/bar/foo';
/**
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/
- $view = $this->getMock('\OC\Files\View');
- $root = $this->getMock('\OC\Files\Node\Root', array('getUser', 'getMountsIn', 'getMount'), array($manager, $view, $this->user));
+ $view = $this->createMock(View::class);
+ $root = $this->getMockBuilder(Root::class)->setMethods(['getUser', 'getMountsIn', 'getMount'])->setConstructorArgs([$manager, $view, $this->user])->getMock();
$view->expects($this->any())
->method('file_exists')
@@ -796,14 +804,14 @@ class FolderTest extends \Test\TestCase {
}
public function testRecent() {
- $manager = $this->getMock('\OC\Files\Mount\Manager');
+ $manager = $this->createMock(Manager::class);
$folderPath = '/bar/foo';
/**
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/
- $view = $this->getMock('\OC\Files\View');
+ $view = $this->createMock(View::class);
/** @var \PHPUnit_Framework_MockObject_MockObject|\OC\Files\Node\Root $root */
- $root = $this->getMock('\OC\Files\Node\Root', array('getUser', 'getMountsIn', 'getMount'), array($manager, $view, $this->user));
+ $root = $this->getMockBuilder(Root::class)->setMethods(['getUser', 'getMountsIn', 'getMount'])->setConstructorArgs([$manager, $view, $this->user])->getMock();
/** @var \PHPUnit_Framework_MockObject_MockObject|\OC\Files\FileInfo $folderInfo */
$folderInfo = $this->getMockBuilder('\OC\Files\FileInfo')
->disableOriginalConstructor()->getMock();
@@ -854,14 +862,14 @@ class FolderTest extends \Test\TestCase {
}
public function testRecentFolder() {
- $manager = $this->getMock('\OC\Files\Mount\Manager');
+ $manager = $this->createMock(Manager::class);
$folderPath = '/bar/foo';
/**
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/
- $view = $this->getMock('\OC\Files\View');
+ $view = $this->createMock(View::class);
/** @var \PHPUnit_Framework_MockObject_MockObject|\OC\Files\Node\Root $root */
- $root = $this->getMock('\OC\Files\Node\Root', array('getUser', 'getMountsIn', 'getMount'), array($manager, $view, $this->user));
+ $root = $this->getMockBuilder(Root::class)->setMethods(['getUser', 'getMountsIn', 'getMount'])->setConstructorArgs([$manager, $view, $this->user])->getMock();
/** @var \PHPUnit_Framework_MockObject_MockObject|\OC\Files\FileInfo $folderInfo */
$folderInfo = $this->getMockBuilder('\OC\Files\FileInfo')
->disableOriginalConstructor()->getMock();
@@ -910,14 +918,14 @@ class FolderTest extends \Test\TestCase {
}
public function testRecentJail() {
- $manager = $this->getMock('\OC\Files\Mount\Manager');
+ $manager = $this->createMock(Manager::class);
$folderPath = '/bar/foo';
/**
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/
- $view = $this->getMock('\OC\Files\View');
+ $view = $this->createMock(View::class);
/** @var \PHPUnit_Framework_MockObject_MockObject|\OC\Files\Node\Root $root */
- $root = $this->getMock('\OC\Files\Node\Root', array('getUser', 'getMountsIn', 'getMount'), array($manager, $view, $this->user));
+ $root = $this->getMockBuilder(Root::class)->setMethods(['getUser', 'getMountsIn', 'getMount'])->setConstructorArgs([$manager, $view, $this->user])->getMock();
/** @var \PHPUnit_Framework_MockObject_MockObject|\OC\Files\FileInfo $folderInfo */
$folderInfo = $this->getMockBuilder('\OC\Files\FileInfo')
->disableOriginalConstructor()->getMock();
diff --git a/tests/lib/Files/Storage/Wrapper/QuotaTest.php b/tests/lib/Files/Storage/Wrapper/QuotaTest.php
index 2e9f68b3c56..ee01d0c3f26 100644
--- a/tests/lib/Files/Storage/Wrapper/QuotaTest.php
+++ b/tests/lib/Files/Storage/Wrapper/QuotaTest.php
@@ -10,6 +10,7 @@ namespace Test\Files\Storage\Wrapper;
//ensure the constants are loaded
use OC\Files\Cache\CacheEntry;
+use OC\Files\Storage\Local;
\OC::$loader->load('\OC\Files\Filesystem');
@@ -75,11 +76,10 @@ class QuotaTest extends \Test\Files\Storage\Storage {
}
public function testFreeSpaceWithUnknownDiskSpace() {
- $storage = $this->getMock(
- '\OC\Files\Storage\Local',
- array('free_space'),
- array(array('datadir' => $this->tmpDir))
- );
+ $storage = $this->getMockBuilder(Local::class)
+ ->setMethods(['free_space'])
+ ->setConstructorArgs([['datadir' => $this->tmpDir]])
+ ->getMock();
$storage->expects($this->any())
->method('free_space')
->will($this->returnValue(-2));
@@ -132,10 +132,10 @@ class QuotaTest extends \Test\Files\Storage\Storage {
}
public function testReturnFalseWhenFopenFailed() {
- $failStorage = $this->getMock(
- '\OC\Files\Storage\Local',
- array('fopen'),
- array(array('datadir' => $this->tmpDir)));
+ $failStorage = $this->getMockBuilder(Local::class)
+ ->setMethods(['fopen'])
+ ->setConstructorArgs([['datadir' => $this->tmpDir]])
+ ->getMock();
$failStorage->expects($this->any())
->method('fopen')
->will($this->returnValue(false));
diff --git a/tests/lib/Files/Utils/ScannerTest.php b/tests/lib/Files/Utils/ScannerTest.php
index 0c8e41c24c7..7895331d615 100644
--- a/tests/lib/Files/Utils/ScannerTest.php
+++ b/tests/lib/Files/Utils/ScannerTest.php
@@ -11,6 +11,7 @@ namespace Test\Files\Utils;
use OC\Files\Filesystem;
use OC\Files\Mount\MountPoint;
use OC\Files\Storage\Temporary;
+use OCP\Files\Config\IMountProvider;
use OCP\Files\Storage\IStorageFactory;
use OCP\IUser;
@@ -107,7 +108,7 @@ class ScannerTest extends \Test\TestCase {
$uid = $this->getUniqueID();
$this->userBackend->createUser($uid, 'test');
- $mountProvider = $this->getMock('\OCP\Files\Config\IMountProvider');
+ $mountProvider = $this->createMock(IMountProvider::class);
$storage = new Temporary(array());
$mount = new MountPoint($storage, '/' . $uid . '/files/foo');
diff --git a/tests/lib/Files/ViewTest.php b/tests/lib/Files/ViewTest.php
index 72a91614100..b0233116ed5 100644
--- a/tests/lib/Files/ViewTest.php
+++ b/tests/lib/Files/ViewTest.php
@@ -12,8 +12,10 @@ use OC\Files\Cache\Watcher;
use OC\Files\Storage\Common;
use OC\Files\Mount\MountPoint;
use OC\Files\Storage\Temporary;
+use OCP\Files\Config\IMountProvider;
use OCP\Files\FileInfo;
use OCP\Lock\ILockingProvider;
+use Test\TestMoveableMountPoint;
class TemporaryNoTouch extends \OC\Files\Storage\Temporary {
public function touch($path, $mtime = null) {
@@ -1529,14 +1531,13 @@ class ViewTest extends \Test\TestCase {
->setMethods([])
->getMock();
- $mounts[] = $this->getMock(
- '\Test\TestMoveableMountPoint',
- ['moveMount'],
- [$storage, $mountPoint]
- );
+ $mounts[] = $this->getMockBuilder(TestMoveableMountPoint::class)
+ ->setMethods(['moveMount'])
+ ->setConstructorArgs([$storage, $mountPoint])
+ ->getMock();
}
- $mountProvider = $this->getMock('\OCP\Files\Config\IMountProvider');
+ $mountProvider = $this->createMock(IMountProvider::class);
$mountProvider->expects($this->any())
->method('getMountsForUser')
->will($this->returnValue($mounts));
diff --git a/tests/lib/HelperStorageTest.php b/tests/lib/HelperStorageTest.php
index e841dbfce18..e27d5eca21d 100644
--- a/tests/lib/HelperStorageTest.php
+++ b/tests/lib/HelperStorageTest.php
@@ -7,6 +7,7 @@
*/
namespace Test;
+use OC\Files\Storage\Temporary;
/**
* Test the storage functions of OC_Helper
@@ -62,12 +63,10 @@ class HelperStorageTest extends \Test\TestCase {
* @return \OC\Files\Storage\Storage
*/
private function getStorageMock($freeSpace = 12) {
- $this->storageMock = $this->getMock(
- '\OC\Files\Storage\Temporary',
- array('free_space'),
- array('')
- );
-
+ $this->storageMock = $this->getMockBuilder(Temporary::class)
+ ->setMethods(['free_space'])
+ ->setConstructorArgs([''])
+ ->getMock();
$this->storageMock->expects($this->once())
->method('free_space')
diff --git a/tests/lib/Lock/DBLockingProviderTest.php b/tests/lib/Lock/DBLockingProviderTest.php
index a7c3f463155..fb27f9957af 100644
--- a/tests/lib/Lock/DBLockingProviderTest.php
+++ b/tests/lib/Lock/DBLockingProviderTest.php
@@ -21,6 +21,7 @@
namespace Test\Lock;
+use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Lock\ILockingProvider;
/**
@@ -50,7 +51,7 @@ class DBLockingProviderTest extends LockingProvider {
public function setUp() {
$this->currentTime = time();
- $this->timeFactory = $this->getMock('\OCP\AppFramework\Utility\ITimeFactory');
+ $this->timeFactory = $this->createMock(ITimeFactory::class);
$this->timeFactory->expects($this->any())
->method('getTime')
->will($this->returnCallback(function () {
diff --git a/tests/lib/Repair/RepairUnmergedSharesTest.php b/tests/lib/Repair/RepairUnmergedSharesTest.php
index 7b9d2579389..2834cfe94b8 100644
--- a/tests/lib/Repair/RepairUnmergedSharesTest.php
+++ b/tests/lib/Repair/RepairUnmergedSharesTest.php
@@ -24,6 +24,7 @@ namespace Test\Repair;
use OC\Repair\RepairUnmergedShares;
use OC\Share\Constants;
+use OCP\IUser;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
use Test\TestCase;
@@ -69,8 +70,8 @@ class RepairUnmergedSharesTest extends TestCase {
$this->connection = \OC::$server->getDatabaseConnection();
$this->deleteAllShares();
- $this->userManager = $this->getMock('\OCP\IUserManager');
- $this->groupManager = $this->getMock('\OCP\IGroupManager');
+ $this->userManager = $this->createMock(IUserManager::class);
+ $this->groupManager = $this->createMock(IGroupManager::class);
// used to generate incremental stimes
$this->lastShareTime = time();
@@ -487,12 +488,12 @@ class RepairUnmergedSharesTest extends TestCase {
* @dataProvider sharesDataProvider
*/
public function testMergeGroupShares($shares, $expectedShares) {
- $user1 = $this->getMock('\OCP\IUser');
+ $user1 = $this->createMock(IUser::class);
$user1->expects($this->any())
->method('getUID')
->will($this->returnValue('user1'));
- $user2 = $this->getMock('\OCP\IUser');
+ $user2 = $this->createMock(IUser::class);
$user2->expects($this->any())
->method('getUID')
->will($this->returnValue('user2'));
diff --git a/tests/lib/Security/CertificateManagerTest.php b/tests/lib/Security/CertificateManagerTest.php
index 3abd3392e6c..92a063d47c7 100644
--- a/tests/lib/Security/CertificateManagerTest.php
+++ b/tests/lib/Security/CertificateManagerTest.php
@@ -9,6 +9,7 @@
namespace Test\Security;
use \OC\Security\CertificateManager;
+use OCP\IConfig;
/**
* Class CertificateManagerTest
@@ -38,7 +39,7 @@ class CertificateManagerTest extends \Test\TestCase {
\OC\Files\Filesystem::tearDown();
\OC_Util::setupFS($this->username);
- $config = $this->getMock('OCP\IConfig');
+ $config = $this->createMock(IConfig::class);
$config->expects($this->any())->method('getSystemValue')
->with('installed', false)->willReturn(true);
@@ -138,7 +139,7 @@ class CertificateManagerTest extends \Test\TestCase {
$view = $this->getMockBuilder('OC\Files\View')
->disableOriginalConstructor()->getMock();
- $config = $this->getMock('OCP\IConfig');
+ $config = $this->createMock(IConfig::class);
/** @var CertificateManager | \PHPUnit_Framework_MockObject_MockObject $certificateManager */
$certificateManager = $this->getMockBuilder('OC\Security\CertificateManager')
diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php
index 16ad1b07f89..72ba4da6e5d 100644
--- a/tests/lib/Share20/ManagerTest.php
+++ b/tests/lib/Share20/ManagerTest.php
@@ -2413,7 +2413,7 @@ class ManagerTest extends \Test\TestCase {
$tomorrow->setTime(0,0,0);
$tomorrow->add(new \DateInterval('P1D'));
- $file = $this->getMock('OCP\Files\File', [], [], 'File');
+ $file = $this->createMock(File::class);
$file->method('getId')->willReturn(100);
$share = $this->manager->newShare();
diff --git a/tests/lib/TagsTest.php b/tests/lib/TagsTest.php
index 2662c209d2c..add28a19061 100644
--- a/tests/lib/TagsTest.php
+++ b/tests/lib/TagsTest.php
@@ -21,6 +21,7 @@
*/
namespace Test;
+use OCP\IUserSession;
/**
* Class TagsTest
@@ -49,7 +50,7 @@ class TagsTest extends \Test\TestCase {
\OC::$server->getUserManager()->createUser($userId, 'pass');
\OC_User::setUserId($userId);
$this->user = new \OC\User\User($userId, null);
- $this->userSession = $this->getMock('\OCP\IUserSession');
+ $this->userSession = $this->createMock(IUserSession::class);
$this->userSession
->expects($this->any())
->method('getUser')
@@ -70,7 +71,7 @@ class TagsTest extends \Test\TestCase {
}
public function testTagManagerWithoutUserReturnsNull() {
- $this->userSession = $this->getMock('\OCP\IUserSession');
+ $this->userSession = $this->createMock(IUserSession::class);
$this->userSession
->expects($this->any())
->method('getUser')
@@ -294,7 +295,7 @@ class TagsTest extends \Test\TestCase {
$otherUserId = $this->getUniqueID('user2_');
\OC::$server->getUserManager()->createUser($otherUserId, 'pass');
\OC_User::setUserId($otherUserId);
- $otherUserSession = $this->getMock('\OCP\IUserSession');
+ $otherUserSession = $this->createMock(IUserSession::class);
$otherUserSession
->expects($this->any())
->method('getUser')
diff --git a/tests/lib/UrlGeneratorTest.php b/tests/lib/UrlGeneratorTest.php
index 7186c8fad80..c8d5b8ece2c 100644
--- a/tests/lib/UrlGeneratorTest.php
+++ b/tests/lib/UrlGeneratorTest.php
@@ -7,6 +7,8 @@
*/
namespace Test;
+use OCP\ICacheFactory;
+use OCP\IConfig;
/**
* Class UrlGeneratorTest
@@ -22,8 +24,8 @@ class UrlGeneratorTest extends \Test\TestCase {
*/
public function testLinkToDocRoot($app, $file, $args, $expectedResult) {
\OC::$WEBROOT = '';
- $config = $this->getMock('\OCP\IConfig');
- $cacheFactory = $this->getMock('\OCP\ICacheFactory');
+ $config = $this->createMock(IConfig::class);
+ $cacheFactory = $this->createMock(ICacheFactory::class);
$urlGenerator = new \OC\URLGenerator($config, $cacheFactory);
$result = $urlGenerator->linkTo($app, $file, $args);
@@ -37,8 +39,8 @@ class UrlGeneratorTest extends \Test\TestCase {
*/
public function testLinkToSubDir($app, $file, $args, $expectedResult) {
\OC::$WEBROOT = '/owncloud';
- $config = $this->getMock('\OCP\IConfig');
- $cacheFactory = $this->getMock('\OCP\ICacheFactory');
+ $config = $this->createMock(IConfig::class);
+ $cacheFactory = $this->createMock(ICacheFactory::class);
$urlGenerator = new \OC\URLGenerator($config, $cacheFactory);
$result = $urlGenerator->linkTo($app, $file, $args);
@@ -50,8 +52,8 @@ class UrlGeneratorTest extends \Test\TestCase {
*/
public function testLinkToRouteAbsolute($route, $expected) {
\OC::$WEBROOT = '/owncloud';
- $config = $this->getMock('\OCP\IConfig');
- $cacheFactory = $this->getMock('\OCP\ICacheFactory');
+ $config = $this->createMock(IConfig::class);
+ $cacheFactory = $this->createMock(ICacheFactory::class);
$urlGenerator = new \OC\URLGenerator($config, $cacheFactory);
$result = $urlGenerator->linkToRouteAbsolute($route);
$this->assertEquals($expected, $result);
@@ -89,8 +91,8 @@ class UrlGeneratorTest extends \Test\TestCase {
function testGetAbsoluteURLDocRoot($url, $expectedResult) {
\OC::$WEBROOT = '';
- $config = $this->getMock('\OCP\IConfig');
- $cacheFactory = $this->getMock('\OCP\ICacheFactory');
+ $config = $this->createMock(IConfig::class);
+ $cacheFactory = $this->createMock(ICacheFactory::class);
$urlGenerator = new \OC\URLGenerator($config, $cacheFactory);
$result = $urlGenerator->getAbsoluteURL($url);
@@ -105,8 +107,8 @@ class UrlGeneratorTest extends \Test\TestCase {
function testGetAbsoluteURLSubDir($url, $expectedResult) {
\OC::$WEBROOT = '/owncloud';
- $config = $this->getMock('\OCP\IConfig');
- $cacheFactory = $this->getMock('\OCP\ICacheFactory');
+ $config = $this->createMock(IConfig::class);
+ $cacheFactory = $this->createMock(ICacheFactory::class);
$urlGenerator = new \OC\URLGenerator($config, $cacheFactory);
$result = $urlGenerator->getAbsoluteURL($url);
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();
diff --git a/tests/lib/UtilTest.php b/tests/lib/UtilTest.php
index 33c15565b92..619963a2abf 100644
--- a/tests/lib/UtilTest.php
+++ b/tests/lib/UtilTest.php
@@ -9,7 +9,14 @@
namespace Test;
use OC_Util;
+use OCP\App\IAppManager;
+/**
+ * Class UtilTest
+ *
+ * @package Test
+ * @group DB
+ */
class UtilTest extends \Test\TestCase {
public function testGetVersion() {
$version = \OCP\Util::getVersion();
@@ -300,7 +307,7 @@ class UtilTest extends \Test\TestCase {
$oldWebRoot = \OC::$WEBROOT;
\OC::$WEBROOT = '';
- $appManager = $this->getMock('\OCP\App\IAppManager');
+ $appManager = $this->createMock(IAppManager::class);
$appManager->expects($this->any())
->method('isEnabledForUser')
->will($this->returnCallback(function($appId) use ($enabledApps){