Fix getMock files_external

This commit is contained in:
Roeland Jago Douma 2016-09-02 10:37:20 +02:00 committed by Morris Jobke
parent 0c154c1ed7
commit d13ac20bca
No known key found for this signature in database
GPG Key ID: 9CE5ED29E7FCD38A
10 changed files with 59 additions and 34 deletions

View File

@ -24,6 +24,8 @@ namespace OCA\Files_External\Tests\Auth\Password;
use OCA\Files_External\Lib\Auth\Password\GlobalAuth; use OCA\Files_External\Lib\Auth\Password\GlobalAuth;
use OCA\Files_external\Lib\StorageConfig; use OCA\Files_external\Lib\StorageConfig;
use OCP\IL10N;
use OCP\Security\ICredentialsManager;
use Test\TestCase; use Test\TestCase;
class GlobalAuthTest extends TestCase { class GlobalAuthTest extends TestCase {
@ -44,14 +46,14 @@ class GlobalAuthTest extends TestCase {
protected function setUp() { protected function setUp() {
parent::setUp(); parent::setUp();
$this->l10n = $this->getMock('\OCP\IL10N'); $this->l10n = $this->createMock(IL10N::class);
$this->credentialsManager = $this->getMock('\OCP\Security\ICredentialsManager'); $this->credentialsManager = $this->createMock(ICredentialsManager::class);
$this->instance = new GlobalAuth($this->l10n, $this->credentialsManager); $this->instance = new GlobalAuth($this->l10n, $this->credentialsManager);
} }
private function getStorageConfig($type, $config = []) { private function getStorageConfig($type, $config = []) {
/** @var \OCA\Files_External\Lib\StorageConfig|\PHPUnit_Framework_MockObject_MockObject $storageConfig */ /** @var \OCA\Files_External\Lib\StorageConfig|\PHPUnit_Framework_MockObject_MockObject $storageConfig */
$storageConfig = $this->getMock('\OCA\Files_External\Lib\StorageConfig'); $storageConfig = $this->createMock(StorageConfig::class);
$storageConfig->expects($this->any()) $storageConfig->expects($this->any())
->method('getType') ->method('getType')
->will($this->returnValue($type)); ->will($this->returnValue($type));

View File

@ -23,13 +23,15 @@
namespace OCA\Files_External\Tests\Command; namespace OCA\Files_External\Tests\Command;
use OCA\Files_External\Command\Applicable; use OCA\Files_External\Command\Applicable;
use OCP\IGroupManager;
use OCP\IUserManager;
class ApplicableTest extends CommandTest { class ApplicableTest extends CommandTest {
private function getInstance($storageService) { private function getInstance($storageService) {
/** @var \OCP\IUserManager|\PHPUnit_Framework_MockObject_MockObject $userManager */ /** @var \OCP\IUserManager|\PHPUnit_Framework_MockObject_MockObject $userManager */
$userManager = $this->getMock('\OCP\IUserManager'); $userManager = $this->createMock(IUserManager::class);
/** @var \OCP\IGroupManager|\PHPUnit_Framework_MockObject_MockObject $groupManager */ /** @var \OCP\IGroupManager|\PHPUnit_Framework_MockObject_MockObject $groupManager */
$groupManager = $this->getMock('\OCP\IGroupManager'); $groupManager = $this->createMock(IGroupManager::class);
$userManager->expects($this->any()) $userManager->expects($this->any())
->method('userExists') ->method('userExists')

View File

@ -29,6 +29,10 @@ use OCA\Files_External\Lib\Auth\Password\Password;
use OCA\Files_External\Lib\Auth\Password\SessionCredentials; use OCA\Files_External\Lib\Auth\Password\SessionCredentials;
use OCA\Files_External\Lib\Backend\Local; use OCA\Files_External\Lib\Backend\Local;
use OCA\Files_External\Lib\StorageConfig; use OCA\Files_External\Lib\StorageConfig;
use OCP\ISession;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\Security\ICrypto;
use Symfony\Component\Console\Output\BufferedOutput; use Symfony\Component\Console\Output\BufferedOutput;
class ListCommandTest extends CommandTest { class ListCommandTest extends CommandTest {
@ -41,17 +45,17 @@ class ListCommandTest extends CommandTest {
/** @var \OCA\Files_External\Service\UserStoragesService|\PHPUnit_Framework_MockObject_MockObject $userService */ /** @var \OCA\Files_External\Service\UserStoragesService|\PHPUnit_Framework_MockObject_MockObject $userService */
$userService = $this->getMock('\OCA\Files_External\Service\UserStoragesService', null, [], '', false); $userService = $this->getMock('\OCA\Files_External\Service\UserStoragesService', null, [], '', false);
/** @var \OCP\IUserManager|\PHPUnit_Framework_MockObject_MockObject $userManager */ /** @var \OCP\IUserManager|\PHPUnit_Framework_MockObject_MockObject $userManager */
$userManager = $this->getMock('\OCP\IUserManager'); $userManager = $this->createMock(IUserManager::class);
/** @var \OCP\IUserSession|\PHPUnit_Framework_MockObject_MockObject $userSession */ /** @var \OCP\IUserSession|\PHPUnit_Framework_MockObject_MockObject $userSession */
$userSession = $this->getMock('\OCP\IUserSession'); $userSession = $this->createMock(IUserSession::class);
return new ListCommand($globalService, $userService, $userSession, $userManager); return new ListCommand($globalService, $userService, $userSession, $userManager);
} }
public function testListAuthIdentifier() { public function testListAuthIdentifier() {
$l10n = $this->getMock('\OC_L10N', null, [], '', false); $l10n = $this->getMock('\OC_L10N', null, [], '', false);
$session = $this->getMock('\OCP\ISession'); $session = $this->createMock(ISession::class);
$crypto = $this->getMock('\OCP\Security\ICrypto'); $crypto = $this->createMock(ICrypto::class);
$instance = $this->getInstance(); $instance = $this->getInstance();
$mount1 = new StorageConfig(); $mount1 = new StorageConfig();
$mount1->setAuthMechanism(new Password($l10n)); $mount1->setAuthMechanism(new Password($l10n));

View File

@ -28,6 +28,7 @@ use OCA\Files_External\Lib\Auth\PublicKey\RSA;
use OCP\AppFramework\Http\JSONResponse; use OCP\AppFramework\Http\JSONResponse;
use OCP\IGroupManager; use OCP\IGroupManager;
use OCP\IRequest; use OCP\IRequest;
use OCP\IUser;
use OCP\IUserSession; use OCP\IUserSession;
use Test\TestCase; use Test\TestCase;
@ -46,15 +47,15 @@ class AjaxControllerTest extends TestCase {
private $ajaxController; private $ajaxController;
public function setUp() { public function setUp() {
$this->request = $this->getMock('\\OCP\\IRequest'); $this->request = $this->createMock(IRequest::class);
$this->rsa = $this->getMockBuilder('\\OCA\\Files_External\\Lib\\Auth\\PublicKey\\RSA') $this->rsa = $this->getMockBuilder('\\OCA\\Files_External\\Lib\\Auth\\PublicKey\\RSA')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$this->globalAuth = $this->getMockBuilder('\\OCA\\Files_External\\Lib\\Auth\\Password\GlobalAuth') $this->globalAuth = $this->getMockBuilder('\\OCA\\Files_External\\Lib\\Auth\\Password\GlobalAuth')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$this->userSession = $this->getMock('\\OCP\\IUserSession'); $this->userSession = $this->createMock(IUserSession::class);
$this->groupManager = $this->getMock('\\OCP\\IGroupManager'); $this->groupManager = $this->createMock(IGroupManager::class);
$this->ajaxController = new AjaxController( $this->ajaxController = new AjaxController(
'files_external', 'files_external',
@ -90,7 +91,7 @@ class AjaxControllerTest extends TestCase {
} }
public function testSaveGlobalCredentialsAsAdminForAnotherUser() { public function testSaveGlobalCredentialsAsAdminForAnotherUser() {
$user = $this->getMock('\\OCP\\IUser'); $user = $this->createMock(IUser::class);
$user $user
->expects($this->once()) ->expects($this->once())
->method('getUID') ->method('getUID')
@ -113,7 +114,7 @@ class AjaxControllerTest extends TestCase {
} }
public function testSaveGlobalCredentialsAsAdminForSelf() { public function testSaveGlobalCredentialsAsAdminForSelf() {
$user = $this->getMock('\\OCP\\IUser'); $user = $this->createMock(IUser::class);
$user $user
->expects($this->once()) ->expects($this->once())
->method('getUID') ->method('getUID')
@ -136,7 +137,7 @@ class AjaxControllerTest extends TestCase {
} }
public function testSaveGlobalCredentialsAsNormalUserForSelf() { public function testSaveGlobalCredentialsAsNormalUserForSelf() {
$user = $this->getMock('\\OCP\\IUser'); $user = $this->createMock(IUser::class);
$user $user
->expects($this->exactly(2)) ->expects($this->exactly(2))
->method('getUID') ->method('getUID')
@ -159,7 +160,7 @@ class AjaxControllerTest extends TestCase {
} }
public function testSaveGlobalCredentialsAsNormalUserForAnotherUser() { public function testSaveGlobalCredentialsAsNormalUserForAnotherUser() {
$user = $this->getMock('\\OCP\\IUser'); $user = $this->createMock(IUser::class);
$user $user
->expects($this->exactly(2)) ->expects($this->exactly(2))
->method('getUID') ->method('getUID')

View File

@ -27,6 +27,9 @@ namespace OCA\Files_External\Tests\Controller;
use OCA\Files_External\Controller\GlobalStoragesController; use OCA\Files_External\Controller\GlobalStoragesController;
use \OCP\AppFramework\Http; use \OCP\AppFramework\Http;
use \OCA\Files_External\Service\BackendService; use \OCA\Files_External\Service\BackendService;
use OCP\IL10N;
use OCP\ILogger;
use OCP\IRequest;
class GlobalStoragesControllerTest extends StoragesControllerTest { class GlobalStoragesControllerTest extends StoragesControllerTest {
public function setUp() { public function setUp() {
@ -40,10 +43,10 @@ class GlobalStoragesControllerTest extends StoragesControllerTest {
$this->controller = new GlobalStoragesController( $this->controller = new GlobalStoragesController(
'files_external', 'files_external',
$this->getMock('\OCP\IRequest'), $this->createMock(IRequest::class),
$this->getMock('\OCP\IL10N'), $this->createMock(IL10N::class),
$this->service, $this->service,
$this->getMock('\OCP\ILogger') $this->createMock(ILogger::class)
); );
} }
} }

View File

@ -28,6 +28,10 @@ use \OCA\Files_External\Controller\UserStoragesController;
use OCA\Files_External\Lib\StorageConfig; use OCA\Files_External\Lib\StorageConfig;
use \OCP\AppFramework\Http; use \OCP\AppFramework\Http;
use \OCA\Files_External\Service\BackendService; use \OCA\Files_External\Service\BackendService;
use OCP\IL10N;
use OCP\ILogger;
use OCP\IRequest;
use OCP\IUserSession;
class UserStoragesControllerTest extends StoragesControllerTest { class UserStoragesControllerTest extends StoragesControllerTest {
@ -47,11 +51,11 @@ class UserStoragesControllerTest extends StoragesControllerTest {
$this->controller = new UserStoragesController( $this->controller = new UserStoragesController(
'files_external', 'files_external',
$this->getMock('\OCP\IRequest'), $this->createMock(IRequest::class),
$this->getMock('\OCP\IL10N'), $this->createMock(IL10N::class),
$this->service, $this->service,
$this->getMock('\OCP\IUserSession'), $this->createMock(IUserSession::class),
$this->getMock('\OCP\ILogger') $this->createMock(ILogger::class)
); );
} }

View File

@ -21,7 +21,11 @@
*/ */
namespace OCA\Files_External\Tests\Service; namespace OCA\Files_External\Tests\Service;
use OCA\Files_External\Lib\Config\IAuthMechanismProvider;
use OCA\Files_External\Lib\Config\IBackendProvider;
use \OCA\Files_External\Service\BackendService; use \OCA\Files_External\Service\BackendService;
use OCP\IConfig;
use OCP\IL10N;
class BackendServiceTest extends \Test\TestCase { class BackendServiceTest extends \Test\TestCase {
@ -32,8 +36,8 @@ class BackendServiceTest extends \Test\TestCase {
protected $l10n; protected $l10n;
protected function setUp() { protected function setUp() {
$this->config = $this->getMock('\OCP\IConfig'); $this->config = $this->createMock(IConfig::class);
$this->l10n = $this->getMock('\OCP\IL10N'); $this->l10n = $this->createMock(IL10N::class);
} }
/** /**
@ -97,7 +101,7 @@ class BackendServiceTest extends \Test\TestCase {
$backend1 = $this->getBackendMock('\Foo\Bar'); $backend1 = $this->getBackendMock('\Foo\Bar');
$backend2 = $this->getBackendMock('\Bar\Foo'); $backend2 = $this->getBackendMock('\Bar\Foo');
$providerMock = $this->getMock('\OCA\Files_External\Lib\Config\IBackendProvider'); $providerMock = $this->createMock(IBackendProvider::class);
$providerMock->expects($this->once()) $providerMock->expects($this->once())
->method('getBackends') ->method('getBackends')
->willReturn([$backend1, $backend2]); ->willReturn([$backend1, $backend2]);
@ -115,7 +119,7 @@ class BackendServiceTest extends \Test\TestCase {
$backend1 = $this->getAuthMechanismMock('\Foo\Bar'); $backend1 = $this->getAuthMechanismMock('\Foo\Bar');
$backend2 = $this->getAuthMechanismMock('\Bar\Foo'); $backend2 = $this->getAuthMechanismMock('\Bar\Foo');
$providerMock = $this->getMock('\OCA\Files_External\Lib\Config\IAuthMechanismProvider'); $providerMock = $this->createMock(IAuthMechanismProvider::class);
$providerMock->expects($this->once()) $providerMock->expects($this->once())
->method('getAuthMechanisms') ->method('getAuthMechanisms')
->willReturn([$backend1, $backend2]); ->willReturn([$backend1, $backend2]);
@ -135,12 +139,12 @@ class BackendServiceTest extends \Test\TestCase {
$backend2 = $this->getBackendMock('\Dead\Beef'); $backend2 = $this->getBackendMock('\Dead\Beef');
$provider1Mock = $this->getMock('\OCA\Files_External\Lib\Config\IBackendProvider'); $provider1Mock = $this->createMock(IBackendProvider::class);
$provider1Mock->expects($this->once()) $provider1Mock->expects($this->once())
->method('getBackends') ->method('getBackends')
->willReturn([$backend1a, $backend1b]); ->willReturn([$backend1a, $backend1b]);
$service->registerBackendProvider($provider1Mock); $service->registerBackendProvider($provider1Mock);
$provider2Mock = $this->getMock('\OCA\Files_External\Lib\Config\IBackendProvider'); $provider2Mock = $this->createMock(IBackendProvider::class);
$provider2Mock->expects($this->once()) $provider2Mock->expects($this->once())
->method('getBackends') ->method('getBackends')
->willReturn([$backend2]); ->willReturn([$backend2]);

View File

@ -31,6 +31,8 @@ use OCA\Files_External\Lib\StorageConfig;
use OCA\Files_External\Service\BackendService; use OCA\Files_External\Service\BackendService;
use OCA\Files_External\Service\DBConfigService; use OCA\Files_External\Service\DBConfigService;
use OCA\Files_External\Service\StoragesService; use OCA\Files_External\Service\StoragesService;
use OCP\AppFramework\IAppContainer;
use OCP\Files\Config\IUserMountCache;
class CleaningDBConfig extends DBConfigService { class CleaningDBConfig extends DBConfigService {
private $mountIds = []; private $mountIds = [];
@ -94,7 +96,7 @@ abstract class StoragesServiceTest extends \Test\TestCase {
); );
\OC_Mount_Config::$skipTest = true; \OC_Mount_Config::$skipTest = true;
$this->mountCache = $this->getMock('OCP\Files\Config\IUserMountCache'); $this->mountCache = $this->createMock(IUserMountCache::class);
// prepare BackendService mock // prepare BackendService mock
$this->backendService = $this->backendService =
@ -150,7 +152,7 @@ abstract class StoragesServiceTest extends \Test\TestCase {
Filesystem::signal_delete_mount, Filesystem::signal_delete_mount,
get_class($this), 'deleteHookCallback'); get_class($this), 'deleteHookCallback');
$containerMock = $this->getMock('\OCP\AppFramework\IAppContainer'); $containerMock = $this->createMock(IAppContainer::class);
$containerMock->method('query') $containerMock->method('query')
->will($this->returnCallback(function ($name) { ->will($this->returnCallback(function ($name) {
if ($name === 'OCA\Files_External\Service\BackendService') { if ($name === 'OCA\Files_External\Service\BackendService') {

View File

@ -28,7 +28,9 @@ use OCA\Files_External\Lib\StorageConfig;
use OCA\Files_External\NotFoundException; use OCA\Files_External\NotFoundException;
use OCA\Files_External\Service\StoragesService; use OCA\Files_External\Service\StoragesService;
use OCA\Files_External\Service\UserGlobalStoragesService; use OCA\Files_External\Service\UserGlobalStoragesService;
use OCP\IGroupManager;
use OCP\IUser; use OCP\IUser;
use OCP\IUserSession;
use Test\Traits\UserTrait; use Test\Traits\UserTrait;
/** /**
@ -63,13 +65,13 @@ class UserGlobalStoragesServiceTest extends GlobalStoragesServiceTest {
$this->user = new \OC\User\User(self::USER_ID, null); $this->user = new \OC\User\User(self::USER_ID, null);
/** @var \OCP\IUserSession|\PHPUnit_Framework_MockObject_MockObject $userSession */ /** @var \OCP\IUserSession|\PHPUnit_Framework_MockObject_MockObject $userSession */
$userSession = $this->getMock('\OCP\IUserSession'); $userSession = $this->createMock(IUserSession::class);
$userSession $userSession
->expects($this->any()) ->expects($this->any())
->method('getUser') ->method('getUser')
->will($this->returnValue($this->user)); ->will($this->returnValue($this->user));
$this->groupManager = $this->getMock('\OCP\IGroupManager'); $this->groupManager = $this->createMock(IGroupManager::class);
$this->groupManager->method('isInGroup') $this->groupManager->method('isInGroup')
->will($this->returnCallback(function ($userId, $groupId) { ->will($this->returnCallback(function ($userId, $groupId) {
if ($userId === self::USER_ID) { if ($userId === self::USER_ID) {

View File

@ -30,6 +30,7 @@ use OCA\Files_External\Service\GlobalStoragesService;
use OCA\Files_External\Service\StoragesService; use OCA\Files_External\Service\StoragesService;
use OCA\Files_External\Service\UserStoragesService; use OCA\Files_External\Service\UserStoragesService;
use OCA\Files_External\Lib\StorageConfig; use OCA\Files_External\Lib\StorageConfig;
use OCP\IUserSession;
use Test\Traits\UserTrait; use Test\Traits\UserTrait;
/** /**
@ -57,7 +58,7 @@ class UserStoragesServiceTest extends StoragesServiceTest {
$this->user = \OC::$server->getUserManager()->get($this->userId); $this->user = \OC::$server->getUserManager()->get($this->userId);
/** @var \OCP\IUserSession|\PHPUnit_Framework_MockObject_MockObject $userSession */ /** @var \OCP\IUserSession|\PHPUnit_Framework_MockObject_MockObject $userSession */
$userSession = $this->getMock('\OCP\IUserSession'); $userSession = $this->createMock(IUserSession::class);
$userSession $userSession
->expects($this->any()) ->expects($this->any())
->method('getUser') ->method('getUser')