summaryrefslogtreecommitdiffstats
path: root/tests/lib
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib')
-rw-r--r--tests/lib/AllConfigTest.php4
-rw-r--r--tests/lib/Authentication/Token/DefaultTokenProviderTest.php8
-rw-r--r--tests/lib/Encryption/ManagerTest.php28
-rw-r--r--tests/lib/Files/Storage/Wrapper/EncryptionTest.php23
-rw-r--r--tests/lib/Log/FileTest.php2
-rw-r--r--tests/lib/Memcache/RedisTest.php13
-rw-r--r--tests/lib/RepairStepTest.php2
-rw-r--r--tests/lib/Share/MailNotificationsTest.php125
-rw-r--r--tests/lib/User/UserTest.php4
9 files changed, 51 insertions, 158 deletions
diff --git a/tests/lib/AllConfigTest.php b/tests/lib/AllConfigTest.php
index 3d0a9cb0827..f3d43ff4396 100644
--- a/tests/lib/AllConfigTest.php
+++ b/tests/lib/AllConfigTest.php
@@ -15,6 +15,8 @@ namespace Test;
*
* @package Test
*/
+use OCP\IDBConnection;
+
class AllConfigTest extends \Test\TestCase {
/** @var \OCP\IDBConnection */
@@ -189,7 +191,7 @@ class AllConfigTest extends \Test\TestCase {
->method('fetchColumn')
->will($this->returnValue('valueSetUnchanged'));
- $connectionMock = $this->getMock('\OCP\IDBConnection');
+ $connectionMock = $this->createMock(IDBConnection::class);
$connectionMock->expects($this->once())
->method('executeQuery')
->with($this->equalTo('SELECT `configvalue` FROM `*PREFIX*preferences` '.
diff --git a/tests/lib/Authentication/Token/DefaultTokenProviderTest.php b/tests/lib/Authentication/Token/DefaultTokenProviderTest.php
index bbfcd93913b..2c8c2d7e196 100644
--- a/tests/lib/Authentication/Token/DefaultTokenProviderTest.php
+++ b/tests/lib/Authentication/Token/DefaultTokenProviderTest.php
@@ -274,7 +274,7 @@ class DefaultTokenProviderTest extends TestCase {
public function testRenewSessionTokenWithoutPassword() {
$token = $this->getMockBuilder(DefaultToken::class)
->disableOriginalConstructor()
- ->setMethods(['getUID', 'getLoginName', 'getPassword', 'getName'])
+ ->setMethods(['getUID', 'getLoginName', 'getPassword', 'getName', 'getRemember'])
->getMock();
$token
->expects($this->at(0))
@@ -293,7 +293,7 @@ class DefaultTokenProviderTest extends TestCase {
->method('getName')
->willReturn('MyTokenName');
$token
- ->expects($this->at(3))
+ ->expects($this->at(4))
->method('getRemember')
->willReturn(IToken::DO_NOT_REMEMBER);
$this->config
@@ -325,7 +325,7 @@ class DefaultTokenProviderTest extends TestCase {
public function testRenewSessionTokenWithPassword() {
$token = $this->getMockBuilder(DefaultToken::class)
->disableOriginalConstructor()
- ->setMethods(['getUID', 'getLoginName', 'getPassword', 'getName'])
+ ->setMethods(['getUID', 'getLoginName', 'getPassword', 'getName', 'getRemember'])
->getMock();
$token
->expects($this->at(0))
@@ -348,7 +348,7 @@ class DefaultTokenProviderTest extends TestCase {
->method('getName')
->willReturn('MyTokenName');
$token
- ->expects($this->at(3))
+ ->expects($this->at(5))
->method('getRemember')
->willReturn(IToken::REMEMBER);
$this->crypto
diff --git a/tests/lib/Encryption/ManagerTest.php b/tests/lib/Encryption/ManagerTest.php
index ac26d4cb528..65234074955 100644
--- a/tests/lib/Encryption/ManagerTest.php
+++ b/tests/lib/Encryption/ManagerTest.php
@@ -17,22 +17,22 @@ class ManagerTest extends TestCase {
/** @var Manager */
private $manager;
- /** @var \PHPUnit_Framework_MockObject_MockObject */
+ /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
private $config;
- /** @var \PHPUnit_Framework_MockObject_MockObject */
+ /** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */
private $logger;
- /** @var \PHPUnit_Framework_MockObject_MockObject */
+ /** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */
private $l10n;
- /** @var \PHPUnit_Framework_MockObject_MockObject */
+ /** @var View|\PHPUnit_Framework_MockObject_MockObject */
private $view;
- /** @var \PHPUnit_Framework_MockObject_MockObject */
+ /** @var Util|\PHPUnit_Framework_MockObject_MockObject */
private $util;
- /** @var \PHPUnit_Framework_MockObject_MockObject | \OC\Memcache\ArrayCache */
+ /** @var ArrayCache|\PHPUnit_Framework_MockObject_MockObject */
private $arrayCache;
public function setUp() {
@@ -188,9 +188,9 @@ class ManagerTest extends TestCase {
// * @expectedExceptionMessage Id "0" already used by encryption module "TestDummyModule0"
// */
// public function testModuleRegistration() {
-// $config = $this->getMock('\OCP\IConfig');
+// $config = $this->createMock(IConfig::class);
// $config->expects($this->any())->method('getSystemValue')->willReturn(true);
-// $em = $this->getMock('\OCP\Encryption\IEncryptionModule');
+// $em = $this->createMock(IEncryptionModule::class);
// $em->expects($this->any())->method('getId')->willReturn(0);
// $em->expects($this->any())->method('getDisplayName')->willReturn('TestDummyModule0');
// $m = new Manager($config);
@@ -200,9 +200,9 @@ class ManagerTest extends TestCase {
// }
//
// public function testModuleUnRegistration() {
-// $config = $this->getMock('\OCP\IConfig');
+// $config = $this->createMock(IConfig::class);
// $config->expects($this->any())->method('getSystemValue')->willReturn(true);
-// $em = $this->getMock('\OCP\Encryption\IEncryptionModule');
+// $em = $this->createMock(IEncryptionModule::class);
// $em->expects($this->any())->method('getId')->willReturn(0);
// $em->expects($this->any())->method('getDisplayName')->willReturn('TestDummyModule0');
// $m = new Manager($config);
@@ -217,9 +217,9 @@ class ManagerTest extends TestCase {
// * @expectedExceptionMessage Module with ID: unknown does not exist.
// */
// public function testGetEncryptionModuleUnknown() {
-// $config = $this->getMock('\OCP\IConfig');
+// $config = $this->createMock(IConfig::class);
// $config->expects($this->any())->method('getSystemValue')->willReturn(true);
-// $em = $this->getMock('\OCP\Encryption\IEncryptionModule');
+// $em = $this->createMock(IEncryptionModule::class);
// $em->expects($this->any())->method('getId')->willReturn(0);
// $em->expects($this->any())->method('getDisplayName')->willReturn('TestDummyModule0');
// $m = new Manager($config);
@@ -229,9 +229,9 @@ class ManagerTest extends TestCase {
// }
//
// public function testGetEncryptionModule() {
-// $config = $this->getMock('\OCP\IConfig');
+// $config = $this->createMock(IConfig::class);
// $config->expects($this->any())->method('getSystemValue')->willReturn(true);
-// $em = $this->getMock('\OCP\Encryption\IEncryptionModule');
+// $em = $this->createMock(IEncryptionModule::class);
// $em->expects($this->any())->method('getId')->willReturn(0);
// $em->expects($this->any())->method('getDisplayName')->willReturn('TestDummyModule0');
// $m = new Manager($config);
diff --git a/tests/lib/Files/Storage/Wrapper/EncryptionTest.php b/tests/lib/Files/Storage/Wrapper/EncryptionTest.php
index eb665af8dda..d310f110b94 100644
--- a/tests/lib/Files/Storage/Wrapper/EncryptionTest.php
+++ b/tests/lib/Files/Storage/Wrapper/EncryptionTest.php
@@ -943,7 +943,7 @@ class EncryptionTest extends Storage {
* @dataProvider dataTestShouldEncrypt
*
* @param bool $encryptMountPoint
- * @param \PHPUnit_Framework_MockObject_MockObject | IEncryptionModule $encryptionModule
+ * @param mixed $encryptionModule
* @param bool $encryptionModuleShouldEncrypt
* @param bool $expected
*/
@@ -985,8 +985,15 @@ class EncryptionTest extends Storage {
->setMethods(['getFullPath', 'getEncryptionModule'])
->getMock();
+ if ($encryptionModule === true) {
+ /** @var IEncryptionModule|\PHPUnit_Framework_MockObject_MockObject $encryptionModule */
+ $encryptionModule = $this->createMock(IEncryptionModule::class);
+ }
+
$wrapper->method('getFullPath')->with($path)->willReturn($fullPath);
- $wrapper->method('getEncryptionModule')->with($fullPath)
+ $wrapper->expects($encryptMountPoint ? $this->once() : $this->never())
+ ->method('getEncryptionModule')
+ ->with($fullPath)
->willReturnCallback(
function() use ($encryptionModule) {
if ($encryptionModule === false) {
@@ -999,12 +1006,15 @@ class EncryptionTest extends Storage {
->willReturn($encryptMountPoint);
if ($encryptionModule !== null && $encryptionModule !== false) {
- $encryptionModule->method('shouldEncrypt')->with($fullPath)
+ $encryptionModule
+ ->method('shouldEncrypt')
+ ->with($fullPath)
->willReturn($encryptionModuleShouldEncrypt);
}
if ($encryptionModule === null) {
- $encryptionManager->expects($this->once())->method('getEncryptionModule')
+ $encryptionManager->expects($this->once())
+ ->method('getEncryptionModule')
->willReturn($defaultEncryptionModule);
}
$defaultEncryptionModule->method('shouldEncrypt')->willReturn(true);
@@ -1015,12 +1025,11 @@ class EncryptionTest extends Storage {
}
public function dataTestShouldEncrypt() {
- $encryptionModule = $this->createMock(IEncryptionModule::class);
return [
[false, false, false, false],
[true, false, false, false],
- [true, $encryptionModule, false, false],
- [true, $encryptionModule, true, true],
+ [true, true, false, false],
+ [true, true, true, true],
[true, null, false, true],
];
}
diff --git a/tests/lib/Log/FileTest.php b/tests/lib/Log/FileTest.php
index 4bd5b6f21ab..f71d536d61e 100644
--- a/tests/lib/Log/FileTest.php
+++ b/tests/lib/Log/FileTest.php
@@ -49,7 +49,7 @@ class FileTest extends TestCase
if (isset($this->restore_logdateformat)) {
$config->getSystemValue("logdateformat", $this->restore_logdateformat);
} else {
- $config->deleteSystemValue("restore_logdateformat");
+ $config->deleteSystemValue("logdateformat");
}
File::init();
parent::tearDown();
diff --git a/tests/lib/Memcache/RedisTest.php b/tests/lib/Memcache/RedisTest.php
index 094954d4a1a..e707f30fb5b 100644
--- a/tests/lib/Memcache/RedisTest.php
+++ b/tests/lib/Memcache/RedisTest.php
@@ -17,15 +17,22 @@ class RedisTest extends Cache {
self::markTestSkipped('The redis extension is not available.');
}
+ $errorOccurred = false;
set_error_handler(
function($errno, $errstr) {
- restore_error_handler();
- self::markTestSkipped($errstr);
+ throw new \RuntimeException($errstr, 123456789);
},
E_WARNING
);
- $instance = new \OC\Memcache\Redis(self::getUniqueID());
+ try {
+ $instance = new \OC\Memcache\Redis(self::getUniqueID());
+ } catch (\RuntimeException $e) {
+ $errorOccurred = $e->getCode() === 123456789 ? $e->getMessage() : false;
+ }
restore_error_handler();
+ if ($errorOccurred !== false) {
+ self::markTestSkipped($errorOccurred);
+ }
if ($instance->set(self::getUniqueID(), self::getUniqueID()) === false) {
self::markTestSkipped('redis server seems to be down.');
diff --git a/tests/lib/RepairStepTest.php b/tests/lib/RepairStepTest.php
index 3f7a0ce064b..1ec28de8768 100644
--- a/tests/lib/RepairStepTest.php
+++ b/tests/lib/RepairStepTest.php
@@ -87,7 +87,7 @@ class RepairTest extends TestCase {
}
public function testRunRepairStepsWithException() {
- $mock = $this->getMock('\Test\TestRepairStep');
+ $mock = $this->createMock(TestRepairStep::class);
$mock->expects($this->any())
->method('run')
->will($this->throwException(new \Exception()));
diff --git a/tests/lib/Share/MailNotificationsTest.php b/tests/lib/Share/MailNotificationsTest.php
deleted file mode 100644
index 2759ee04946..00000000000
--- a/tests/lib/Share/MailNotificationsTest.php
+++ /dev/null
@@ -1,125 +0,0 @@
-<?php
-/**
- * @author Lukas Reschke <lukas@owncloud.com>
- *
- * @copyright Copyright (c) 2015, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-
-namespace Test\Share;
-
-use OC\Share\MailNotifications;
-use OCP\IL10N;
-use OCP\IUser;
-use OCP\Mail\IMailer;
-use OCP\ILogger;
-use OCP\Defaults;
-use OCP\IURLGenerator;
-
-/**
- * Class MailNotificationsTest
- */
-class MailNotificationsTest extends \Test\TestCase {
- /** @var IL10N */
- private $l10n;
- /** @var IMailer | \PHPUnit_Framework_MockObject_MockObject */
- private $mailer;
- /** @var ILogger */
- private $logger;
- /** @var Defaults | \PHPUnit_Framework_MockObject_MockObject */
- private $defaults;
- /** @var IUser | \PHPUnit_Framework_MockObject_MockObject */
- private $user;
- /** @var IURLGenerator | \PHPUnit_Framework_MockObject_MockObject */
- private $urlGenerator;
-
-
- public function setUp() {
- parent::setUp();
-
- $this->l10n = $this->getMockBuilder('\OCP\IL10N')
- ->disableOriginalConstructor()->getMock();
- $this->mailer = $this->getMockBuilder('\OCP\Mail\IMailer')
- ->disableOriginalConstructor()->getMock();
- $this->logger = $this->getMockBuilder('\OCP\ILogger')
- ->disableOriginalConstructor()->getMock();
- $this->defaults = $this->getMockBuilder('\OCP\Defaults')
- ->disableOriginalConstructor()->getMock();
- $this->user = $this->getMockBuilder('\OCP\IUser')
- ->disableOriginalConstructor()->getMock();
- $this->urlGenerator = $this->createMock(IURLGenerator::class);
-
- $this->l10n->expects($this->any())
- ->method('t')
- ->will($this->returnCallback(function($text, $parameters = array()) {
- return vsprintf($text, $parameters);
- }));
-
- $this->defaults
- ->expects($this->once())
- ->method('getName')
- ->will($this->returnValue('UnitTestCloud'));
-
- $this->user
- ->expects($this->once())
- ->method('getEMailAddress')
- ->willReturn('sharer@owncloud.com');
- $this->user
- ->expects($this->once())
- ->method('getDisplayName')
- ->willReturn('TestUser');
-
- }
-
- /**
- * @param string $subject
- */
- protected function setupMailerMock($subject, $to, $exceptionOnSend = true) {
- $message = $this->getMockBuilder('\OC\Mail\Message')
- ->disableOriginalConstructor()->getMock();
-
- $message
- ->expects($this->once())
- ->method('setSubject')
- ->with($subject);
- $message
- ->expects($this->once())
- ->method('setTo')
- ->with($to);
- $message
- ->expects($this->once())
- ->method('setHtmlBody');
- $message
- ->expects($this->once())
- ->method('setPlainBody');
- $message
- ->expects($this->once())
- ->method('setFrom')
- ->with([\OCP\Util::getDefaultEmailAddress('sharing-noreply') => 'TestUser via UnitTestCloud']);
-
- $this->mailer
- ->expects($this->once())
- ->method('createMessage')
- ->will($this->returnValue($message));
- if ($exceptionOnSend) {
- $this->mailer
- ->expects($this->once())
- ->method('send')
- ->with($message)
- ->will($this->throwException(new \Exception('Some Exception Message')));
- }
- }
-}
diff --git a/tests/lib/User/UserTest.php b/tests/lib/User/UserTest.php
index edb8ac4224e..5fc07b692f7 100644
--- a/tests/lib/User/UserTest.php
+++ b/tests/lib/User/UserTest.php
@@ -204,12 +204,12 @@ class UserTest extends TestCase {
/**
* @var Backend | \PHPUnit_Framework_MockObject_MockObject $backend
*/
- $backend = $this->createMock(Dummy::class);
+ $backend = $this->createMock(\Test\Util\User\Dummy::class);
$backend->expects($this->at(0))
->method('implementsActions')
->will($this->returnCallback(function ($actions) {
- if ($actions === Backend::GET_HOME) {
+ if ($actions === \OC\User\Backend::GET_HOME) {
return true;
} else {
return false;