summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Settings/Controller/CheckSetupControllerTest.php8
-rw-r--r--tests/Settings/Controller/UsersControllerTest.php133
-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
11 files changed, 108 insertions, 242 deletions
diff --git a/tests/Settings/Controller/CheckSetupControllerTest.php b/tests/Settings/Controller/CheckSetupControllerTest.php
index d9ba7d43672..49931994f02 100644
--- a/tests/Settings/Controller/CheckSetupControllerTest.php
+++ b/tests/Settings/Controller/CheckSetupControllerTest.php
@@ -68,8 +68,6 @@ class CheckSetupControllerTest extends TestCase {
->disableOriginalConstructor()->getMock();
$this->config = $this->getMockBuilder('\OCP\IConfig')
->disableOriginalConstructor()->getMock();
- $this->config = $this->getMockBuilder('\OCP\IConfig')
- ->disableOriginalConstructor()->getMock();
$this->clientService = $this->getMockBuilder('\OCP\Http\Client\IClientService')
->disableOriginalConstructor()->getMock();
$this->util = $this->getMockBuilder('\OC_Util')
@@ -98,7 +96,7 @@ class CheckSetupControllerTest extends TestCase {
$this->checker,
$this->logger
])
- ->setMethods(['getCurlVersion', 'isPhpOutdated'])->getMock();
+ ->setMethods(['getCurlVersion', 'isPhpOutdated', 'isOpcacheProperlySetup'])->getMock();
}
public function testIsInternetConnectionWorkingDisabledViaConfig() {
@@ -307,6 +305,10 @@ class CheckSetupControllerTest extends TestCase {
->expects($this->once())
->method('isPhpOutdated')
->willReturn(true);
+ $this->checkSetupController
+ ->expects($this->once())
+ ->method('isOpcacheProperlySetup')
+ ->willReturn(false);
$this->urlGenerator->expects($this->at(2))
->method('linkToDocs')
->with('admin-reverse-proxy')
diff --git a/tests/Settings/Controller/UsersControllerTest.php b/tests/Settings/Controller/UsersControllerTest.php
index 79e6dd61813..d659d812b0d 100644
--- a/tests/Settings/Controller/UsersControllerTest.php
+++ b/tests/Settings/Controller/UsersControllerTest.php
@@ -12,7 +12,6 @@ namespace Tests\Settings\Controller;
use OC\Accounts\AccountManager;
use OC\Group\Manager;
-use OC\Mail\IEMailTemplate;
use OC\Settings\Controller\UsersController;
use OC\Settings\Mailer\NewUserMailHelper;
use OCP\App\IAppManager;
@@ -31,9 +30,12 @@ use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserManager;
use OCP\IUserSession;
+use OCP\Mail\IEMailTemplate;
use OCP\Mail\IMailer;
use OCP\Security\ICrypto;
use OCP\Security\ISecureRandom;
+use OC\User\User;
+use Test\Util\User\Dummy;
/**
* @group DB
@@ -164,8 +166,7 @@ class UsersControllerTest extends \Test\TestCase {
public function testIndexAdmin() {
$controller = $this->getController(true);
- $foo = $this->getMockBuilder('\OC\User\User')
- ->disableOriginalConstructor()->getMock();
+ $foo = $this->createMock(User::class);
$foo
->expects($this->exactly(2))
->method('getUID')
@@ -192,8 +193,7 @@ class UsersControllerTest extends \Test\TestCase {
->expects($this->once())
->method('getBackendClassName')
->will($this->returnValue('OC_User_Database'));
- $admin = $this->getMockBuilder('\OC\User\User')
- ->disableOriginalConstructor()->getMock();
+ $admin = $this->createMock(User::class);
$admin
->expects($this->exactly(2))
->method('getUID')
@@ -221,9 +221,8 @@ class UsersControllerTest extends \Test\TestCase {
$admin
->expects($this->once())
->method('getBackendClassName')
- ->will($this->returnValue('\Test\Util\User\Dummy'));
- $bar = $this->getMockBuilder('\OC\User\User')
- ->disableOriginalConstructor()->getMock();
+ ->willReturn(Dummy::class);
+ $bar = $this->createMock(User::class);
$bar
->expects($this->exactly(2))
->method('getUID')
@@ -249,7 +248,7 @@ class UsersControllerTest extends \Test\TestCase {
$bar
->expects($this->once())
->method('getBackendClassName')
- ->will($this->returnValue('\Test\Util\User\Dummy'));
+ ->willReturn(Dummy::class);
$this->groupManager
->expects($this->once())
@@ -322,7 +321,7 @@ class UsersControllerTest extends \Test\TestCase {
'quota' => 404,
'storageLocation' => '/home/admin',
'lastLogin' => 12000,
- 'backend' => '\Test\Util\User\Dummy',
+ 'backend' => Dummy::class,
'email' => 'admin@bar.com',
'isRestoreDisabled' => false,
'isAvatarAvailable' => false,
@@ -335,7 +334,7 @@ class UsersControllerTest extends \Test\TestCase {
'quota' => 2323,
'storageLocation' => '/home/bar',
'lastLogin' => 3999000,
- 'backend' => '\Test\Util\User\Dummy',
+ 'backend' => Dummy::class,
'email' => 'bar@dummy.com',
'isRestoreDisabled' => false,
'isAvatarAvailable' => true,
@@ -349,15 +348,13 @@ class UsersControllerTest extends \Test\TestCase {
public function testIndexSubAdmin() {
$controller = $this->getController(false);
- $user = $this->getMockBuilder('\OC\User\User')
- ->disableOriginalConstructor()->getMock();
+ $user = $this->createMock(User::class);
$this->userSession
->expects($this->once())
->method('getUser')
->will($this->returnValue($user));
- $foo = $this->getMockBuilder('\OC\User\User')
- ->disableOriginalConstructor()->getMock();
+ $foo = $this->createMock(User::class);
$foo
->expects($this->exactly(2))
->method('getUID')
@@ -384,8 +381,7 @@ class UsersControllerTest extends \Test\TestCase {
->expects($this->once())
->method('getBackendClassName')
->will($this->returnValue('OC_User_Database'));
- $admin = $this->getMockBuilder('\OC\User\User')
- ->disableOriginalConstructor()->getMock();
+ $admin = $this->createMock(User::class);
$admin
->expects($this->exactly(2))
->method('getUID')
@@ -413,9 +409,8 @@ class UsersControllerTest extends \Test\TestCase {
$admin
->expects($this->once())
->method('getBackendClassName')
- ->will($this->returnValue('\Test\Util\User\Dummy'));
- $bar = $this->getMockBuilder('\OC\User\User')
- ->disableOriginalConstructor()->getMock();
+ ->willReturn(Dummy::class);
+ $bar = $this->createMock(User::class);
$bar
->expects($this->exactly(2))
->method('getUID')
@@ -441,7 +436,7 @@ class UsersControllerTest extends \Test\TestCase {
$bar
->expects($this->once())
->method('getBackendClassName')
- ->will($this->returnValue('\Test\Util\User\Dummy'));
+ ->willReturn(Dummy::class);
$this->groupManager
->expects($this->at(2))
@@ -515,7 +510,7 @@ class UsersControllerTest extends \Test\TestCase {
'quota' => 2323,
'storageLocation' => '/home/bar',
'lastLogin' => 3999000,
- 'backend' => '\Test\Util\User\Dummy',
+ 'backend' => Dummy::class,
'email' => 'bar@dummy.com',
'isRestoreDisabled' => false,
'isAvatarAvailable' => true,
@@ -541,7 +536,7 @@ class UsersControllerTest extends \Test\TestCase {
'quota' => 404,
'storageLocation' => '/home/admin',
'lastLogin' => 12000,
- 'backend' => '\Test\Util\User\Dummy',
+ 'backend' => Dummy::class,
'email' => 'admin@bar.com',
'isRestoreDisabled' => false,
'isAvatarAvailable' => false,
@@ -560,8 +555,7 @@ class UsersControllerTest extends \Test\TestCase {
public function testIndexWithSearch() {
$controller = $this->getController(true);
- $foo = $this->getMockBuilder('\OC\User\User')
- ->disableOriginalConstructor()->getMock();
+ $foo = $this->createMock(User::class);
$foo
->expects($this->exactly(2))
->method('getUID')
@@ -588,8 +582,7 @@ class UsersControllerTest extends \Test\TestCase {
->expects($this->once())
->method('getBackendClassName')
->will($this->returnValue('OC_User_Database'));
- $admin = $this->getMockBuilder('\OC\User\User')
- ->disableOriginalConstructor()->getMock();
+ $admin = $this->createMock(User::class);
$admin
->expects($this->exactly(2))
->method('getUID')
@@ -617,9 +610,8 @@ class UsersControllerTest extends \Test\TestCase {
$admin
->expects($this->once())
->method('getBackendClassName')
- ->will($this->returnValue('\Test\Util\User\Dummy'));
- $bar = $this->getMockBuilder('\OC\User\User')
- ->disableOriginalConstructor()->getMock();
+ ->willReturn(Dummy::class);
+ $bar = $this->createMock(User::class);
$bar
->expects($this->exactly(2))
->method('getUID')
@@ -645,7 +637,7 @@ class UsersControllerTest extends \Test\TestCase {
$bar
->expects($this->once())
->method('getBackendClassName')
- ->will($this->returnValue('\Test\Util\User\Dummy'));
+ ->willReturn(Dummy::class);
$this->userManager
->expects($this->once())
@@ -691,7 +683,7 @@ class UsersControllerTest extends \Test\TestCase {
'quota' => 404,
'storageLocation' => '/home/admin',
'lastLogin' => 12000,
- 'backend' => '\Test\Util\User\Dummy',
+ 'backend' => Dummy::class,
'email' => 'admin@bar.com',
'isRestoreDisabled' => false,
'isAvatarAvailable' => false,
@@ -704,7 +696,7 @@ class UsersControllerTest extends \Test\TestCase {
'quota' => 2323,
'storageLocation' => '/home/bar',
'lastLogin' => 3999000,
- 'backend' => '\Test\Util\User\Dummy',
+ 'backend' => Dummy::class,
'email' => 'bar@dummy.com',
'isRestoreDisabled' => false,
'isAvatarAvailable' => true,
@@ -718,8 +710,7 @@ class UsersControllerTest extends \Test\TestCase {
public function testIndexWithBackend() {
$controller = $this->getController(true);
- $user = $this->getMockBuilder('\OC\User\User')
- ->disableOriginalConstructor()->getMock();
+ $user = $this->createMock(User::class);
$user
->expects($this->exactly(2))
->method('getUID')
@@ -749,7 +740,7 @@ class UsersControllerTest extends \Test\TestCase {
$this->userManager
->expects($this->once())
->method('getBackends')
- ->will($this->returnValue([new \Test\Util\User\Dummy(), new \OC\User\Database()]));
+ ->will($this->returnValue([new Dummy(), new \OC\User\Database()]));
$this->userManager
->expects($this->once())
->method('clearBackends');
@@ -787,7 +778,7 @@ class UsersControllerTest extends \Test\TestCase {
)
)
);
- $response = $controller->index(0, 10, '','', '\Test\Util\User\Dummy');
+ $response = $controller->index(0, 10, '','', Dummy::class);
$this->assertEquals($expectedResponse, $response);
}
@@ -797,7 +788,7 @@ class UsersControllerTest extends \Test\TestCase {
$this->userManager
->expects($this->once())
->method('getBackends')
- ->will($this->returnValue([new \Test\Util\User\Dummy(), new \OC\User\Database()]));
+ ->will($this->returnValue([new Dummy(), new \OC\User\Database()]));
$this->userManager
->expects($this->once())
->method('search')
@@ -805,15 +796,14 @@ class UsersControllerTest extends \Test\TestCase {
->will($this->returnValue([]));
$expectedResponse = new DataResponse([]);
- $response = $controller->index(0, 10, '','', '\Test\Util\User\Dummy');
+ $response = $controller->index(0, 10, '','', Dummy::class);
$this->assertEquals($expectedResponse, $response);
}
public function testCreateSuccessfulWithoutGroupAdmin() {
$controller = $this->getController(true);
- $user = $this->getMockBuilder('\OC\User\User')
- ->disableOriginalConstructor()->getMock();
+ $user = $this->createMock(User::class);
$user
->method('getHome')
->will($this->returnValue('/home/user'));
@@ -866,8 +856,7 @@ class UsersControllerTest extends \Test\TestCase {
public function testCreateSuccessfulWithGroupAdmin() {
$controller = $this->getController(true);
- $user = $this->getMockBuilder('\OC\User\User')
- ->disableOriginalConstructor()->getMock();
+ $user = $this->createMock(User::class);
$user
->method('getHome')
->will($this->returnValue('/home/user'));
@@ -1120,8 +1109,7 @@ class UsersControllerTest extends \Test\TestCase {
public function testDestroySelfAdmin() {
$controller = $this->getController(true);
- $user = $this->getMockBuilder('\OC\User\User')
- ->disableOriginalConstructor()->getMock();
+ $user = $this->createMock(User::class);
$user
->expects($this->once())
->method('getUID')
@@ -1146,8 +1134,7 @@ class UsersControllerTest extends \Test\TestCase {
public function testDestroySelfSubadmin() {
$controller = $this->getController(false);
- $user = $this->getMockBuilder('\OC\User\User')
- ->disableOriginalConstructor()->getMock();
+ $user = $this->createMock(User::class);
$user
->expects($this->once())
->method('getUID')
@@ -1172,14 +1159,12 @@ class UsersControllerTest extends \Test\TestCase {
public function testDestroyAdmin() {
$controller = $this->getController(true);
- $user = $this->getMockBuilder('\OC\User\User')
- ->disableOriginalConstructor()->getMock();
+ $user = $this->createMock(User::class);
$user
->expects($this->once())
->method('getUID')
->will($this->returnValue('Admin'));
- $toDeleteUser = $this->getMockBuilder('\OC\User\User')
- ->disableOriginalConstructor()->getMock();
+ $toDeleteUser = $this->createMock(User::class);
$toDeleteUser
->expects($this->once())
->method('delete')
@@ -1207,8 +1192,7 @@ class UsersControllerTest extends \Test\TestCase {
public function testDestroySubAdmin() {
$controller = $this->getController(false);
- $user = $this->getMockBuilder('\OC\User\User')
- ->disableOriginalConstructor()->getMock();
+ $user = $this->createMock(User::class);
$user
->expects($this->once())
->method('getUID')
@@ -1217,10 +1201,8 @@ class UsersControllerTest extends \Test\TestCase {
->method('getUser')
->will($this->returnValue($user));
- $user = $this->getMockBuilder('\OC\User\User')
- ->disableOriginalConstructor()->getMock();
- $toDeleteUser = $this->getMockBuilder('\OC\User\User')
- ->disableOriginalConstructor()->getMock();
+ $user = $this->createMock(User::class);
+ $toDeleteUser = $this->createMock(User::class);
$toDeleteUser
->expects($this->once())
->method('delete')
@@ -1261,14 +1243,12 @@ class UsersControllerTest extends \Test\TestCase {
public function testDestroyUnsuccessfulAdmin() {
$controller = $this->getController(true);
- $user = $this->getMockBuilder('\OC\User\User')
- ->disableOriginalConstructor()->getMock();
+ $user = $this->createMock(User::class);
$user
->expects($this->once())
->method('getUID')
->will($this->returnValue('Admin'));
- $toDeleteUser = $this->getMockBuilder('\OC\User\User')
- ->disableOriginalConstructor()->getMock();
+ $toDeleteUser = $this->createMock(User::class);
$toDeleteUser
->expects($this->once())
->method('delete')
@@ -1296,8 +1276,7 @@ class UsersControllerTest extends \Test\TestCase {
public function testDestroyUnsuccessfulSubAdmin() {
$controller = $this->getController(false);
- $user = $this->getMockBuilder('\OC\User\User')
- ->disableOriginalConstructor()->getMock();
+ $user = $this->createMock(User::class);
$user
->expects($this->once())
->method('getUID')
@@ -1306,8 +1285,7 @@ class UsersControllerTest extends \Test\TestCase {
->method('getUser')
->will($this->returnValue($user));
- $toDeleteUser = $this->getMockBuilder('\OC\User\User')
- ->disableOriginalConstructor()->getMock();
+ $toDeleteUser = $this->createMock(User::class);
$toDeleteUser
->expects($this->once())
->method('delete')
@@ -1348,8 +1326,7 @@ class UsersControllerTest extends \Test\TestCase {
public function testDestroyNotAccessibleToSubAdmin() {
$controller = $this->getController(false);
- $user = $this->getMockBuilder('\OC\User\User')
- ->disableOriginalConstructor()->getMock();
+ $user = $this->createMock(User::class);
$user
->expects($this->once())
->method('getUID')
@@ -1358,8 +1335,7 @@ class UsersControllerTest extends \Test\TestCase {
->method('getUser')
->will($this->returnValue($user));
- $toDeleteUser = $this->getMockBuilder('\OC\User\User')
- ->disableOriginalConstructor()->getMock();
+ $toDeleteUser = $this->createMock(User::class);
$this->userSession
->method('getUser')
->will($this->returnValue($user));
@@ -1419,8 +1395,7 @@ class UsersControllerTest extends \Test\TestCase {
->with('validMail@Adre.ss')
->will($this->returnValue(true));
- $user = $this->getMockBuilder('\OC\User\User')
- ->disableOriginalConstructor()->getMock();
+ $user = $this->createMock(User::class);
$user
->method('getHome')
->will($this->returnValue('/home/user'));
@@ -1471,8 +1446,7 @@ class UsersControllerTest extends \Test\TestCase {
private function mockUser($userId = 'foo', $displayName = 'M. Foo',
$lastLogin = 500, $home = '/home/foo', $backend = 'OC_User_Database') {
- $user = $this->getMockBuilder('\OC\User\User')
- ->disableOriginalConstructor()->getMock();
+ $user = $this->createMock(User::class);
$user
->expects($this->any())
->method('getUID')
@@ -1707,8 +1681,7 @@ class UsersControllerTest extends \Test\TestCase {
public function testStatsSubAdmin() {
$controller = $this->getController(false);
- $user = $this->getMockBuilder('\OC\User\User')
- ->disableOriginalConstructor()->getMock();
+ $user = $this->createMock(User::class);
$this->userSession
->expects($this->once())
@@ -2002,7 +1975,7 @@ class UsersControllerTest extends \Test\TestCase {
$user->method('canChangeDisplayName')->willReturn(true);
if ($data[AccountManager::PROPERTY_EMAIL]['value'] === $oldEmailAddress ||
- $oldEmailAddress === null && $data[AccountManager::PROPERTY_EMAIL]['value'] === '') {
+ ($oldEmailAddress === null && $data[AccountManager::PROPERTY_EMAIL]['value'] === '')) {
$user->expects($this->never())->method('setEMailAddress');
} else {
$user->expects($this->once())->method('setEMailAddress')
@@ -2011,7 +1984,7 @@ class UsersControllerTest extends \Test\TestCase {
}
if ($data[AccountManager::PROPERTY_DISPLAYNAME]['value'] === $oldDisplayName ||
- $oldDisplayName === null && $data[AccountManager::PROPERTY_DISPLAYNAME]['value'] === '') {
+ ($oldDisplayName === null && $data[AccountManager::PROPERTY_DISPLAYNAME]['value'] === '')) {
$user->expects($this->never())->method('setDisplayName');
} else {
$user->expects($this->once())->method('setDisplayName')
@@ -2170,8 +2143,7 @@ class UsersControllerTest extends \Test\TestCase {
*
*/
public function testSetEMailAddress($mailAddress, $isValid, $expectsUpdate, $canChangeDisplayName, $responseCode) {
- $user = $this->getMockBuilder('\OC\User\User')
- ->disableOriginalConstructor()->getMock();
+ $user = $this->createMock(User::class);
$user
->expects($this->any())
->method('getUID')
@@ -2223,8 +2195,7 @@ class UsersControllerTest extends \Test\TestCase {
public function testCreateSuccessfulWithoutPasswordAndWithEmail() {
- $user = $this->getMockBuilder('\OC\User\User')
- ->disableOriginalConstructor()->getMock();
+ $user = $this->createMock(User::class);
$user
->method('getHome')
->willReturn('/home/user');
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;