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\StorageConfig;
use OCP\IL10N;
use OCP\Security\ICredentialsManager;
use Test\TestCase;
class GlobalAuthTest extends TestCase {
@ -44,14 +46,14 @@ class GlobalAuthTest extends TestCase {
protected function setUp() {
parent::setUp();
$this->l10n = $this->getMock('\OCP\IL10N');
$this->credentialsManager = $this->getMock('\OCP\Security\ICredentialsManager');
$this->l10n = $this->createMock(IL10N::class);
$this->credentialsManager = $this->createMock(ICredentialsManager::class);
$this->instance = new GlobalAuth($this->l10n, $this->credentialsManager);
}
private function getStorageConfig($type, $config = []) {
/** @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())
->method('getType')
->will($this->returnValue($type));

View File

@ -23,13 +23,15 @@
namespace OCA\Files_External\Tests\Command;
use OCA\Files_External\Command\Applicable;
use OCP\IGroupManager;
use OCP\IUserManager;
class ApplicableTest extends CommandTest {
private function getInstance($storageService) {
/** @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 */
$groupManager = $this->getMock('\OCP\IGroupManager');
$groupManager = $this->createMock(IGroupManager::class);
$userManager->expects($this->any())
->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\Backend\Local;
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;
class ListCommandTest extends CommandTest {
@ -41,17 +45,17 @@ class ListCommandTest extends CommandTest {
/** @var \OCA\Files_External\Service\UserStoragesService|\PHPUnit_Framework_MockObject_MockObject $userService */
$userService = $this->getMock('\OCA\Files_External\Service\UserStoragesService', null, [], '', false);
/** @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 */
$userSession = $this->getMock('\OCP\IUserSession');
$userSession = $this->createMock(IUserSession::class);
return new ListCommand($globalService, $userService, $userSession, $userManager);
}
public function testListAuthIdentifier() {
$l10n = $this->getMock('\OC_L10N', null, [], '', false);
$session = $this->getMock('\OCP\ISession');
$crypto = $this->getMock('\OCP\Security\ICrypto');
$session = $this->createMock(ISession::class);
$crypto = $this->createMock(ICrypto::class);
$instance = $this->getInstance();
$mount1 = new StorageConfig();
$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\IGroupManager;
use OCP\IRequest;
use OCP\IUser;
use OCP\IUserSession;
use Test\TestCase;
@ -46,15 +47,15 @@ class AjaxControllerTest extends TestCase {
private $ajaxController;
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')
->disableOriginalConstructor()
->getMock();
$this->globalAuth = $this->getMockBuilder('\\OCA\\Files_External\\Lib\\Auth\\Password\GlobalAuth')
->disableOriginalConstructor()
->getMock();
$this->userSession = $this->getMock('\\OCP\\IUserSession');
$this->groupManager = $this->getMock('\\OCP\\IGroupManager');
$this->userSession = $this->createMock(IUserSession::class);
$this->groupManager = $this->createMock(IGroupManager::class);
$this->ajaxController = new AjaxController(
'files_external',
@ -90,7 +91,7 @@ class AjaxControllerTest extends TestCase {
}
public function testSaveGlobalCredentialsAsAdminForAnotherUser() {
$user = $this->getMock('\\OCP\\IUser');
$user = $this->createMock(IUser::class);
$user
->expects($this->once())
->method('getUID')
@ -113,7 +114,7 @@ class AjaxControllerTest extends TestCase {
}
public function testSaveGlobalCredentialsAsAdminForSelf() {
$user = $this->getMock('\\OCP\\IUser');
$user = $this->createMock(IUser::class);
$user
->expects($this->once())
->method('getUID')
@ -136,7 +137,7 @@ class AjaxControllerTest extends TestCase {
}
public function testSaveGlobalCredentialsAsNormalUserForSelf() {
$user = $this->getMock('\\OCP\\IUser');
$user = $this->createMock(IUser::class);
$user
->expects($this->exactly(2))
->method('getUID')
@ -159,7 +160,7 @@ class AjaxControllerTest extends TestCase {
}
public function testSaveGlobalCredentialsAsNormalUserForAnotherUser() {
$user = $this->getMock('\\OCP\\IUser');
$user = $this->createMock(IUser::class);
$user
->expects($this->exactly(2))
->method('getUID')

View File

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

View File

@ -21,7 +21,11 @@
*/
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 OCP\IConfig;
use OCP\IL10N;
class BackendServiceTest extends \Test\TestCase {
@ -32,8 +36,8 @@ class BackendServiceTest extends \Test\TestCase {
protected $l10n;
protected function setUp() {
$this->config = $this->getMock('\OCP\IConfig');
$this->l10n = $this->getMock('\OCP\IL10N');
$this->config = $this->createMock(IConfig::class);
$this->l10n = $this->createMock(IL10N::class);
}
/**
@ -97,7 +101,7 @@ class BackendServiceTest extends \Test\TestCase {
$backend1 = $this->getBackendMock('\Foo\Bar');
$backend2 = $this->getBackendMock('\Bar\Foo');
$providerMock = $this->getMock('\OCA\Files_External\Lib\Config\IBackendProvider');
$providerMock = $this->createMock(IBackendProvider::class);
$providerMock->expects($this->once())
->method('getBackends')
->willReturn([$backend1, $backend2]);
@ -115,7 +119,7 @@ class BackendServiceTest extends \Test\TestCase {
$backend1 = $this->getAuthMechanismMock('\Foo\Bar');
$backend2 = $this->getAuthMechanismMock('\Bar\Foo');
$providerMock = $this->getMock('\OCA\Files_External\Lib\Config\IAuthMechanismProvider');
$providerMock = $this->createMock(IAuthMechanismProvider::class);
$providerMock->expects($this->once())
->method('getAuthMechanisms')
->willReturn([$backend1, $backend2]);
@ -135,12 +139,12 @@ class BackendServiceTest extends \Test\TestCase {
$backend2 = $this->getBackendMock('\Dead\Beef');
$provider1Mock = $this->getMock('\OCA\Files_External\Lib\Config\IBackendProvider');
$provider1Mock = $this->createMock(IBackendProvider::class);
$provider1Mock->expects($this->once())
->method('getBackends')
->willReturn([$backend1a, $backend1b]);
$service->registerBackendProvider($provider1Mock);
$provider2Mock = $this->getMock('\OCA\Files_External\Lib\Config\IBackendProvider');
$provider2Mock = $this->createMock(IBackendProvider::class);
$provider2Mock->expects($this->once())
->method('getBackends')
->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\DBConfigService;
use OCA\Files_External\Service\StoragesService;
use OCP\AppFramework\IAppContainer;
use OCP\Files\Config\IUserMountCache;
class CleaningDBConfig extends DBConfigService {
private $mountIds = [];
@ -94,7 +96,7 @@ abstract class StoragesServiceTest extends \Test\TestCase {
);
\OC_Mount_Config::$skipTest = true;
$this->mountCache = $this->getMock('OCP\Files\Config\IUserMountCache');
$this->mountCache = $this->createMock(IUserMountCache::class);
// prepare BackendService mock
$this->backendService =
@ -150,7 +152,7 @@ abstract class StoragesServiceTest extends \Test\TestCase {
Filesystem::signal_delete_mount,
get_class($this), 'deleteHookCallback');
$containerMock = $this->getMock('\OCP\AppFramework\IAppContainer');
$containerMock = $this->createMock(IAppContainer::class);
$containerMock->method('query')
->will($this->returnCallback(function ($name) {
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\Service\StoragesService;
use OCA\Files_External\Service\UserGlobalStoragesService;
use OCP\IGroupManager;
use OCP\IUser;
use OCP\IUserSession;
use Test\Traits\UserTrait;
/**
@ -63,13 +65,13 @@ class UserGlobalStoragesServiceTest extends GlobalStoragesServiceTest {
$this->user = new \OC\User\User(self::USER_ID, null);
/** @var \OCP\IUserSession|\PHPUnit_Framework_MockObject_MockObject $userSession */
$userSession = $this->getMock('\OCP\IUserSession');
$userSession = $this->createMock(IUserSession::class);
$userSession
->expects($this->any())
->method('getUser')
->will($this->returnValue($this->user));
$this->groupManager = $this->getMock('\OCP\IGroupManager');
$this->groupManager = $this->createMock(IGroupManager::class);
$this->groupManager->method('isInGroup')
->will($this->returnCallback(function ($userId, $groupId) {
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\UserStoragesService;
use OCA\Files_External\Lib\StorageConfig;
use OCP\IUserSession;
use Test\Traits\UserTrait;
/**
@ -57,7 +58,7 @@ class UserStoragesServiceTest extends StoragesServiceTest {
$this->user = \OC::$server->getUserManager()->get($this->userId);
/** @var \OCP\IUserSession|\PHPUnit_Framework_MockObject_MockObject $userSession */
$userSession = $this->getMock('\OCP\IUserSession');
$userSession = $this->createMock(IUserSession::class);
$userSession
->expects($this->any())
->method('getUser')