Fix getMock Encryption

pull/1314/head
Roeland Jago Douma 10 years ago
parent 9ea2153e9b
commit 4da1ee99d6
No known key found for this signature in database
GPG Key ID: 1E152838F164D13B
  1. 11
      tests/lib/Encryption/EncryptionWrapperTest.php
  2. 23
      tests/lib/Encryption/ManagerTest.php
  3. 5
      tests/lib/Encryption/UtilTest.php

@ -24,6 +24,9 @@ namespace Test\Encryption;
use OC\Encryption\EncryptionWrapper; use OC\Encryption\EncryptionWrapper;
use OC\Encryption\Manager;
use OC\Memcache\ArrayCache;
use OCP\ILogger;
use Test\TestCase; use Test\TestCase;
class EncryptionWrapperTest extends TestCase { class EncryptionWrapperTest extends TestCase {
@ -43,10 +46,10 @@ class EncryptionWrapperTest extends TestCase {
public function setUp() { public function setUp() {
parent::setUp(); parent::setUp();
$this->arrayCache = $this->getMock('OC\Memcache\ArrayCache'); $this->arrayCache = $this->createMock(ArrayCache::class);
$this->manager = $this->getMockBuilder('OC\Encryption\Manager') $this->manager = $this->createMock(Manager::class);
->disableOriginalConstructor()->getMock(); $this->logger = $this->createMock(ILogger::class);
$this->logger = $this->getMock('OCP\ILogger'); $this->logger = $this->createMock(ILogger::class);
$this->instance = new EncryptionWrapper($this->arrayCache, $this->manager, $this->logger); $this->instance = new EncryptionWrapper($this->arrayCache, $this->manager, $this->logger);
} }

@ -3,6 +3,13 @@
namespace Test\Encryption; namespace Test\Encryption;
use OC\Encryption\Manager; use OC\Encryption\Manager;
use OC\Encryption\Util;
use OC\Files\View;
use OC\Memcache\ArrayCache;
use OCP\Encryption\IEncryptionModule;
use OCP\IConfig;
use OCP\IL10N;
use OCP\ILogger;
use Test\TestCase; use Test\TestCase;
class ManagerTest extends TestCase { class ManagerTest extends TestCase {
@ -30,12 +37,12 @@ class ManagerTest extends TestCase {
public function setUp() { public function setUp() {
parent::setUp(); parent::setUp();
$this->config = $this->getMock('\OCP\IConfig'); $this->config = $this->createMock(IConfig::class);
$this->logger = $this->getMock('\OCP\ILogger'); $this->logger = $this->createMock(ILogger::class);
$this->l10n = $this->getMock('\OCP\Il10n'); $this->l10n = $this->createMock(IL10N::class);
$this->view = $this->getMock('\OC\Files\View'); $this->view = $this->createMock(View::class);
$this->util = $this->getMockBuilder('\OC\Encryption\Util')->disableOriginalConstructor()->getMock(); $this->util = $this->createMock(Util::class);
$this->arrayCache = $this->getMock('OC\Memcache\ArrayCache'); $this->arrayCache = $this->createMock(ArrayCache::class);
$this->manager = new Manager($this->config, $this->logger, $this->l10n, $this->view, $this->util, $this->arrayCache); $this->manager = new Manager($this->config, $this->logger, $this->l10n, $this->view, $this->util, $this->arrayCache);
} }
@ -50,7 +57,7 @@ class ManagerTest extends TestCase {
public function testManagerIsDisabledIfDisabledButModules() { public function testManagerIsDisabledIfDisabledButModules() {
$this->config->expects($this->any())->method('getAppValue')->willReturn(false); $this->config->expects($this->any())->method('getAppValue')->willReturn(false);
$em = $this->getMock('\OCP\Encryption\IEncryptionModule'); $em = $this->createMock(IEncryptionModule::class);
$em->expects($this->any())->method('getId')->willReturn('id'); $em->expects($this->any())->method('getId')->willReturn('id');
$em->expects($this->any())->method('getDisplayName')->willReturn('TestDummyModule0'); $em->expects($this->any())->method('getDisplayName')->willReturn('TestDummyModule0');
$this->manager->registerEncryptionModule('id', 'TestDummyModule0', function() use ($em) {return $em;}); $this->manager->registerEncryptionModule('id', 'TestDummyModule0', function() use ($em) {return $em;});
@ -235,7 +242,7 @@ class ManagerTest extends TestCase {
// } // }
protected function addNewEncryptionModule(Manager $manager, $id) { protected function addNewEncryptionModule(Manager $manager, $id) {
$encryptionModule = $this->getMock('\OCP\Encryption\IEncryptionModule'); $encryptionModule = $this->createMock(IEncryptionModule::class);
$encryptionModule->expects($this->any()) $encryptionModule->expects($this->any())
->method('getId') ->method('getId')
->willReturn('ID' . $id); ->willReturn('ID' . $id);

@ -3,6 +3,7 @@
namespace Test\Encryption; namespace Test\Encryption;
use OC\Encryption\Util; use OC\Encryption\Util;
use OCP\Encryption\IEncryptionModule;
use Test\TestCase; use Test\TestCase;
class UtilTest extends TestCase { class UtilTest extends TestCase {
@ -77,7 +78,7 @@ class UtilTest extends TestCase {
*/ */
public function testCreateHeader($expected, $header, $moduleId) { public function testCreateHeader($expected, $header, $moduleId) {
$em = $this->getMock('\OCP\Encryption\IEncryptionModule'); $em = $this->createMock(IEncryptionModule::class);
$em->expects($this->any())->method('getId')->willReturn($moduleId); $em->expects($this->any())->method('getId')->willReturn($moduleId);
$result = $this->util->createHeader($header, $em); $result = $this->util->createHeader($header, $em);
@ -100,7 +101,7 @@ class UtilTest extends TestCase {
$header = array('header1' => 1, 'header2' => 2, 'oc_encryption_module' => 'foo'); $header = array('header1' => 1, 'header2' => 2, 'oc_encryption_module' => 'foo');
$em = $this->getMock('\OCP\Encryption\IEncryptionModule'); $em = $this->createMock(IEncryptionModule::class);
$em->expects($this->any())->method('getId')->willReturn('moduleId'); $em->expects($this->any())->method('getId')->willReturn('moduleId');
$this->util->createHeader($header, $em); $this->util->createHeader($header, $em);

Loading…
Cancel
Save