From 166a7667d39e5876d1a3bba8cec7a34de9ef42f6 Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Mon, 15 Aug 2016 17:00:35 +0200 Subject: [PATCH 01/10] Use proper casing --- tests/phpunit-autotest.xml | 5 ++--- tests/phpunit.xml.dist | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/phpunit-autotest.xml b/tests/phpunit-autotest.xml index 07de887c8c..301f63a375 100644 --- a/tests/phpunit-autotest.xml +++ b/tests/phpunit-autotest.xml @@ -8,9 +8,8 @@ > lib/ - settings/ - core/ - ocs-provider/ + Settings/ + Core/ apps.php diff --git a/tests/phpunit.xml.dist b/tests/phpunit.xml.dist index 19fa38209a..d3a5897dfa 100644 --- a/tests/phpunit.xml.dist +++ b/tests/phpunit.xml.dist @@ -2,9 +2,8 @@ lib/ - settings/ - core/ - ocs-provider/ + Settings/ + Core/ apps.php From 65d147200574645a1179c9ea2228aa8106b0ef9c Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Mon, 15 Aug 2016 17:08:27 +0200 Subject: [PATCH 02/10] Don't use create mock Not compatible with this PHPunit version --- tests/Core/Controller/LoginControllerTest.php | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/Core/Controller/LoginControllerTest.php b/tests/Core/Controller/LoginControllerTest.php index a322289d20..bef0952638 100644 --- a/tests/Core/Controller/LoginControllerTest.php +++ b/tests/Core/Controller/LoginControllerTest.php @@ -57,14 +57,14 @@ class LoginControllerTest extends TestCase { public function setUp() { parent::setUp(); - $this->request = $this->createMock('\\OCP\\IRequest'); - $this->userManager = $this->createMock('\\OCP\\IUserManager'); - $this->config = $this->createMock('\\OCP\\IConfig'); - $this->session = $this->createMock('\\OCP\\ISession'); + $this->request = $this->getMockBuilder('\\OCP\\IRequest')->getMock(); + $this->userManager = $this->getMockBuilder('\\OCP\\IUserManager')->getMock(); + $this->config = $this->getMockBuilder('\\OCP\\IConfig')->getMock(); + $this->session = $this->getMockBuilder('\\OCP\\ISession')->getMock(); $this->userSession = $this->getMockBuilder('\\OC\\User\\Session') ->disableOriginalConstructor() ->getMock(); - $this->urlGenerator = $this->createMock('\\OCP\\IURLGenerator'); + $this->urlGenerator = $this->getMockBuilder('\\OCP\\IURLGenerator')->getMock(); $this->twoFactorManager = $this->getMockBuilder('\OC\Authentication\TwoFactorAuth\Manager') ->disableOriginalConstructor() ->getMock(); @@ -110,7 +110,7 @@ class LoginControllerTest extends TestCase { ->method('getCookie') ->with('oc_token') ->willReturn('MyLoginToken'); - $user = $this->createMock('\\OCP\\IUser'); + $user = $this->getMockBuilder('\\OCP\\IUser')->getMock(); $user ->expects($this->once()) ->method('getUID') @@ -217,7 +217,7 @@ class LoginControllerTest extends TestCase { ->method('getSystemValue') ->with('lost_password_link') ->willReturn(false); - $user = $this->createMock('\\OCP\\IUser'); + $user = $this->getMockBuilder('\\OCP\\IUser')->getMock(); $user ->expects($this->once()) ->method('canChangePassword') @@ -255,7 +255,7 @@ class LoginControllerTest extends TestCase { ->method('getSystemValue') ->with('lost_password_link') ->willReturn(false); - $user = $this->createMock('\\OCP\\IUser'); + $user = $this->getMockBuilder('\\OCP\\IUser')->getMock(); $user ->expects($this->once()) ->method('canChangePassword') @@ -326,7 +326,7 @@ class LoginControllerTest extends TestCase { public function testLoginWithValidCredentials() { /** @var IUser | \PHPUnit_Framework_MockObject_MockObject $user */ - $user = $this->createMock('\OCP\IUser'); + $user = $this->getMockBuilder('\OCP\IUser')->getMock(); $password = 'secret'; $indexPageUrl = 'some url'; @@ -371,7 +371,7 @@ class LoginControllerTest extends TestCase { public function testLoginWithoutPassedCsrfCheckAndNotLoggedIn() { /** @var IUser | \PHPUnit_Framework_MockObject_MockObject $user */ - $user = $this->createMock('\OCP\IUser'); + $user = $this->getMockBuilder('\OCP\IUser')->getMock(); $user->expects($this->any()) ->method('getUID') ->will($this->returnValue('jane')); @@ -406,7 +406,7 @@ class LoginControllerTest extends TestCase { public function testLoginWithoutPassedCsrfCheckAndLoggedIn() { /** @var IUser | \PHPUnit_Framework_MockObject_MockObject $user */ - $user = $this->createMock('\OCP\IUser'); + $user = $this->getMockBuilder('\OCP\IUser')->getMock(); $user->expects($this->any()) ->method('getUID') ->will($this->returnValue('jane')); @@ -446,7 +446,7 @@ class LoginControllerTest extends TestCase { public function testLoginWithValidCredentialsAndRedirectUrl() { /** @var IUser | \PHPUnit_Framework_MockObject_MockObject $user */ - $user = $this->createMock('\OCP\IUser'); + $user = $this->getMockBuilder('\OCP\IUser')->getMock(); $user->expects($this->any()) ->method('getUID') ->will($this->returnValue('jane')); @@ -493,7 +493,7 @@ class LoginControllerTest extends TestCase { public function testLoginWithTwoFactorEnforced() { /** @var IUser | \PHPUnit_Framework_MockObject_MockObject $user */ - $user = $this->createMock('\OCP\IUser'); + $user = $this->getMockBuilder('\OCP\IUser')->getMock(); $user->expects($this->any()) ->method('getUID') ->will($this->returnValue('john')); @@ -544,7 +544,7 @@ class LoginControllerTest extends TestCase { public function testToNotLeakLoginName() { /** @var IUser | \PHPUnit_Framework_MockObject_MockObject $user */ - $user = $this->createMock('\OCP\IUser'); + $user = $this->getMockBuilder('\OCP\IUser')->getMock(); $user->expects($this->any()) ->method('getUID') ->will($this->returnValue('john')); From c16c411275892fdd462f266e4d75fed5d540fa7e Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Mon, 15 Aug 2016 17:13:58 +0200 Subject: [PATCH 03/10] Add new dependency --- tests/Settings/Controller/CheckSetupControllerTest.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/Settings/Controller/CheckSetupControllerTest.php b/tests/Settings/Controller/CheckSetupControllerTest.php index f48e9c04f3..bc697285ee 100644 --- a/tests/Settings/Controller/CheckSetupControllerTest.php +++ b/tests/Settings/Controller/CheckSetupControllerTest.php @@ -29,6 +29,7 @@ use OCP\AppFramework\Http\RedirectResponse; use OCP\Http\Client\IClientService; use OCP\IConfig; use OCP\IL10N; +use OCP\ILogger; use OCP\IRequest; use OCP\IURLGenerator; use OC_Util; @@ -68,6 +69,8 @@ class CheckSetupControllerTest extends TestCase { private $util; /** @var IL10N */ private $l10n; + /** @var ILogger */ + private $logger; /** @var Checker */ private $checker; @@ -95,6 +98,7 @@ class CheckSetupControllerTest extends TestCase { })); $this->checker = $this->getMockBuilder('\OC\IntegrityCheck\Checker') ->disableOriginalConstructor()->getMock(); + $this->logger = $this->getMockBuilder('\OCP\ILogger')->getMock(); $this->checkSetupController = $this->getMockBuilder('\OC\Settings\Controller\CheckSetupController') ->setConstructorArgs([ 'settings', @@ -105,6 +109,7 @@ class CheckSetupControllerTest extends TestCase { $this->util, $this->l10n, $this->checker, + $this->logger ]) ->setMethods(['getCurlVersion'])->getMock(); } @@ -373,7 +378,8 @@ class CheckSetupControllerTest extends TestCase { $this->urlGenerator, $this->util, $this->l10n, - $this->checker + $this->checker, + $this->logger ]) ->setMethods(null)->getMock(); From 1c7fa3333ec91badc4ec83a62336d2940aa5768a Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Mon, 15 Aug 2016 17:15:14 +0200 Subject: [PATCH 04/10] Add reference to current user --- tests/Settings/Controller/AuthSettingsControllerTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Settings/Controller/AuthSettingsControllerTest.php b/tests/Settings/Controller/AuthSettingsControllerTest.php index 1705cb5ddf..b57aea0930 100644 --- a/tests/Settings/Controller/AuthSettingsControllerTest.php +++ b/tests/Settings/Controller/AuthSettingsControllerTest.php @@ -91,6 +91,7 @@ class AuthSettingsControllerTest extends TestCase { 'lastActivity' => null, 'type' => null, 'canDelete' => false, + 'current' => true, ], [ 'id' => 200, From 75d135d8d4edda203cd289c705fdc6bb2f9cbec6 Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Mon, 15 Aug 2016 17:19:32 +0200 Subject: [PATCH 05/10] Fix tests for LoginController --- tests/Core/Controller/LoginControllerTest.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/Core/Controller/LoginControllerTest.php b/tests/Core/Controller/LoginControllerTest.php index bef0952638..58788af2f4 100644 --- a/tests/Core/Controller/LoginControllerTest.php +++ b/tests/Core/Controller/LoginControllerTest.php @@ -181,6 +181,7 @@ class LoginControllerTest extends TestCase { 'alt_login' => [], 'rememberLoginAllowed' => \OC_Util::rememberLoginAllowed(), 'rememberLoginState' => 0, + 'resetPasswordLink' => null, ], 'guest' ); @@ -239,6 +240,7 @@ class LoginControllerTest extends TestCase { 'alt_login' => [], 'rememberLoginAllowed' => \OC_Util::rememberLoginAllowed(), 'rememberLoginState' => 0, + 'resetPasswordLink' => false, ], 'guest' ); @@ -277,6 +279,7 @@ class LoginControllerTest extends TestCase { 'alt_login' => [], 'rememberLoginAllowed' => \OC_Util::rememberLoginAllowed(), 'rememberLoginState' => 0, + 'resetPasswordLink' => false, ], 'guest' ); @@ -328,7 +331,7 @@ class LoginControllerTest extends TestCase { /** @var IUser | \PHPUnit_Framework_MockObject_MockObject $user */ $user = $this->getMockBuilder('\OCP\IUser')->getMock(); $password = 'secret'; - $indexPageUrl = 'some url'; + $indexPageUrl = 'http://localhost/index.php/apps/files/'; $this->request ->expects($this->exactly(2)) @@ -360,10 +363,6 @@ class LoginControllerTest extends TestCase { ->method('isTwoFactorAuthenticated') ->with($user) ->will($this->returnValue(false)); - $this->urlGenerator->expects($this->once()) - ->method('linkToRoute') - ->with('files.view.index') - ->will($this->returnValue($indexPageUrl)); $expected = new \OCP\AppFramework\Http\RedirectResponse($indexPageUrl); $this->assertEquals($expected, $this->loginController->tryLogin($user, $password, null)); From d6992e3f9f5bdd8d3a6ad5ea47381944a914ac66 Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Mon, 15 Aug 2016 17:19:50 +0200 Subject: [PATCH 06/10] Fix template test --- tests/Core/Templates/TemplatesTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Core/Templates/TemplatesTest.php b/tests/Core/Templates/TemplatesTest.php index 03565411a1..cd1502fd22 100644 --- a/tests/Core/Templates/TemplatesTest.php +++ b/tests/Core/Templates/TemplatesTest.php @@ -13,7 +13,7 @@ class TemplatesTest extends \Test\TestCase { public function test404() { $template = \OC::$SERVERROOT . '/core/templates/404.php'; $href = \OC::$server->getURLGenerator()->linkTo('', 'index.php'); - $expectedHtml = ""; + $expectedHtml = ""; $this->assertTemplate($expectedHtml, $template); } From 910176c540de634981c753224629cc4459312ded Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Mon, 15 Aug 2016 17:36:45 +0200 Subject: [PATCH 07/10] Fix CheckSetupController tests --- settings/Controller/CheckSetupController.php | 22 +++-- .../Controller/CheckSetupControllerTest.php | 86 ++++++------------- 2 files changed, 40 insertions(+), 68 deletions(-) diff --git a/settings/Controller/CheckSetupController.php b/settings/Controller/CheckSetupController.php index 13e7e44362..19d0e01a68 100644 --- a/settings/Controller/CheckSetupController.php +++ b/settings/Controller/CheckSetupController.php @@ -233,6 +233,19 @@ class CheckSetupController extends Controller { return ''; } + /** + * Whether the version is outdated + * + * @return bool + */ + protected function isPhpOutdated() { + if (version_compare(PHP_VERSION, '5.5.0') === -1) { + return true; + } + + return false; + } + /** * Whether the php version is still supported (at time of release) * according to: https://secure.php.net/supported-versions.php @@ -240,14 +253,7 @@ class CheckSetupController extends Controller { * @return array */ private function isPhpSupported() { - $eol = false; - - //PHP 5.4 is EOL on 14 Sep 2015 - if (version_compare(PHP_VERSION, '5.5.0') === -1) { - $eol = true; - } - - return ['eol' => $eol, 'version' => PHP_VERSION]; + return ['eol' => $this->isPhpOutdated(), 'version' => PHP_VERSION]; } /** diff --git a/tests/Settings/Controller/CheckSetupControllerTest.php b/tests/Settings/Controller/CheckSetupControllerTest.php index bc697285ee..fca19b0dbb 100644 --- a/tests/Settings/Controller/CheckSetupControllerTest.php +++ b/tests/Settings/Controller/CheckSetupControllerTest.php @@ -36,25 +36,12 @@ use OC_Util; use Test\TestCase; use OC\IntegrityCheck\Checker; -/** - * Mock version_compare - * @param string $version1 - * @param string $version2 - * @return int - */ -function version_compare($version1, $version2) { - return CheckSetupControllerTest::$version_compare; -} - /** * Class CheckSetupControllerTest * * @package Tests\Settings\Controller */ class CheckSetupControllerTest extends TestCase { - /** @var int */ - public static $version_compare; - /** @var CheckSetupController */ private $checkSetupController; /** @var IRequest */ @@ -111,7 +98,7 @@ class CheckSetupControllerTest extends TestCase { $this->checker, $this->logger ]) - ->setMethods(['getCurlVersion'])->getMock(); + ->setMethods(['getCurlVersion', 'isPhpOutdated'])->getMock(); } public function testIsInternetConnectionWorkingDisabledViaConfig() { @@ -136,12 +123,8 @@ class CheckSetupControllerTest extends TestCase { $client = $this->getMockBuilder('\OCP\Http\Client\IClient') ->disableOriginalConstructor()->getMock(); - $client->expects($this->at(0)) - ->method('get') - ->with('https://www.owncloud.org/', []); - $client->expects($this->at(1)) - ->method('get') - ->with('http://www.owncloud.org/', []); + $client->expects($this->any()) + ->method('get'); $this->clientService->expects($this->once()) ->method('newClient') @@ -156,7 +139,7 @@ class CheckSetupControllerTest extends TestCase { ); } - public function testIsInternetConnectionHttpsFail() { + public function testIsInternetConnectionFail() { $this->config->expects($this->once()) ->method('getSystemValue') ->with('has_internet_connection', true) @@ -164,12 +147,11 @@ class CheckSetupControllerTest extends TestCase { $client = $this->getMockBuilder('\OCP\Http\Client\IClient') ->disableOriginalConstructor()->getMock(); - $client->expects($this->at(0)) + $client->expects($this->any()) ->method('get') - ->with('https://www.owncloud.org/', []) ->will($this->throwException(new \Exception())); - $this->clientService->expects($this->once()) + $this->clientService->expects($this->exactly(3)) ->method('newClient') ->will($this->returnValue($client)); @@ -181,33 +163,6 @@ class CheckSetupControllerTest extends TestCase { ); } - public function testIsInternetConnectionHttpFail() { - $this->config->expects($this->once()) - ->method('getSystemValue') - ->with('has_internet_connection', true) - ->will($this->returnValue(true)); - - $client = $this->getMockBuilder('\OCP\Http\Client\IClient') - ->disableOriginalConstructor()->getMock(); - $client->expects($this->at(0)) - ->method('get') - ->with('https://www.owncloud.org/', []); - $client->expects($this->at(1)) - ->method('get') - ->with('http://www.owncloud.org/', []) - ->will($this->throwException(new \Exception())); - - $this->clientService->expects($this->once()) - ->method('newClient') - ->will($this->returnValue($client)); - - $this->assertFalse( - self::invokePrivate( - $this->checkSetupController, - 'isInternetConnectionWorking' - ) - ); - } public function testIsMemcacheConfiguredFalse() { $this->config->expects($this->once()) @@ -238,7 +193,10 @@ class CheckSetupControllerTest extends TestCase { } public function testIsPhpSupportedFalse() { - self::$version_compare = -1; + $this->checkSetupController + ->expects($this->once()) + ->method('isPhpOutdated') + ->willReturn(true); $this->assertEquals( ['eol' => true, 'version' => PHP_VERSION], @@ -247,7 +205,10 @@ class CheckSetupControllerTest extends TestCase { } public function testIsPhpSupportedTrue() { - self::$version_compare = 0; + $this->checkSetupController + ->expects($this->exactly(2)) + ->method('isPhpOutdated') + ->willReturn(false); $this->assertEquals( ['eol' => false, 'version' => PHP_VERSION], @@ -255,8 +216,6 @@ class CheckSetupControllerTest extends TestCase { ); - self::$version_compare = 1; - $this->assertEquals( ['eol' => false, 'version' => PHP_VERSION], self::invokePrivate($this->checkSetupController, 'isPhpSupported') @@ -323,13 +282,17 @@ class CheckSetupControllerTest extends TestCase { ->disableOriginalConstructor()->getMock(); $client->expects($this->at(0)) ->method('get') - ->with('https://www.owncloud.org/', []); + ->with('http://www.nextcloud.com/', []) + ->will($this->throwException(new \Exception())); $client->expects($this->at(1)) ->method('get') - ->with('http://www.owncloud.org/', []) + ->with('http://www.google.com/', []) ->will($this->throwException(new \Exception())); - - $this->clientService->expects($this->once()) + $client->expects($this->at(2)) + ->method('get') + ->with('http://www.github.com/', []) + ->will($this->throwException(new \Exception())); + $this->clientService->expects($this->exactly(3)) ->method('newClient') ->will($this->returnValue($client)); $this->urlGenerator->expects($this->at(0)) @@ -340,7 +303,10 @@ class CheckSetupControllerTest extends TestCase { ->method('linkToDocs') ->with('admin-security') ->willReturn('https://doc.owncloud.org/server/8.1/admin_manual/configuration_server/hardening.html'); - self::$version_compare = -1; + $this->checkSetupController + ->expects($this->once()) + ->method('isPhpOutdated') + ->willReturn(true); $this->urlGenerator->expects($this->at(2)) ->method('linkToDocs') ->with('admin-reverse-proxy') From cf3cfca356962899d535e7c018486654a6fc8d0f Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Mon, 15 Aug 2016 17:37:55 +0200 Subject: [PATCH 08/10] Use generated URL --- tests/Core/Controller/LoginControllerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Core/Controller/LoginControllerTest.php b/tests/Core/Controller/LoginControllerTest.php index 58788af2f4..8eaa7c9843 100644 --- a/tests/Core/Controller/LoginControllerTest.php +++ b/tests/Core/Controller/LoginControllerTest.php @@ -331,7 +331,7 @@ class LoginControllerTest extends TestCase { /** @var IUser | \PHPUnit_Framework_MockObject_MockObject $user */ $user = $this->getMockBuilder('\OCP\IUser')->getMock(); $password = 'secret'; - $indexPageUrl = 'http://localhost/index.php/apps/files/'; + $indexPageUrl = \OC_Util::getDefaultPageUrl(); $this->request ->expects($this->exactly(2)) From 09f4ce43890f62f682c08594ed464f7f1ec7eaac Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Mon, 15 Aug 2016 20:07:07 +0200 Subject: [PATCH 09/10] Fix mock call in AvatarControllerTest --- .../Core/Controller/AvatarControllerTest.php | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/Core/Controller/AvatarControllerTest.php b/tests/Core/Controller/AvatarControllerTest.php index 937d8aaf17..4a7b7f2178 100644 --- a/tests/Core/Controller/AvatarControllerTest.php +++ b/tests/Core/Controller/AvatarControllerTest.php @@ -32,7 +32,7 @@ use Punic\Exception; use Test\Traits\UserTrait; /** - * Overwrite is_uploaded_file in this namespace to allow proper unit testing of + * Overwrite is_uploaded_file in this namespace to allow proper unit testing of * the postAvatar call. */ function is_uploaded_file($filename) { @@ -68,19 +68,19 @@ class AvatarControllerTest extends \Test\TestCase { $app = new Application; $this->container = $app->getContainer(); $this->container['AppName'] = 'core'; - $this->container['AvatarManager'] = $this->getMock('OCP\IAvatarManager'); + $this->container['AvatarManager'] = $this->getMockBuilder('OCP\IAvatarManager')->getMock(); $this->container['Cache'] = $this->getMockBuilder('OC\Cache\File') ->disableOriginalConstructor()->getMock(); - $this->container['L10N'] = $this->getMock('OCP\IL10N'); + $this->container['L10N'] = $this->getMockBuilder('OCP\IL10N')->getMock(); $this->container['L10N']->method('t')->will($this->returnArgument(0)); - $this->container['UserManager'] = $this->getMock('OCP\IUserManager'); - $this->container['UserSession'] = $this->getMock('OCP\IUserSession'); - $this->container['Request'] = $this->getMock('OCP\IRequest'); - $this->container['UserFolder'] = $this->getMock('OCP\Files\Folder'); - $this->container['Logger'] = $this->getMock('OCP\ILogger'); + $this->container['UserManager'] = $this->getMockBuilder('OCP\IUserManager')->getMock(); + $this->container['UserSession'] = $this->getMockBuilder('OCP\IUserSession')->getMock(); + $this->container['Request'] = $this->getMockBuilder('OCP\IRequest')->getMock(); + $this->container['UserFolder'] = $this->getMockBuilder('OCP\Files\Folder')->getMock(); + $this->container['Logger'] = $this->getMockBuilder('OCP\ILogger')->getMock(); - $this->avatarMock = $this->getMock('OCP\IAvatar'); - $this->userMock = $this->getMock('OCP\IUser'); + $this->avatarMock = $this->getMockBuilder('OCP\IAvatar')->getMock(); + $this->userMock = $this->getMockBuilder('OCP\IUser')->getMock(); $this->avatarController = $this->container['AvatarController']; @@ -91,7 +91,7 @@ class AvatarControllerTest extends \Test\TestCase { ->willReturnMap([['userId', $this->userMock]]); $this->container['UserSession']->method('getUser')->willReturn($this->userMock); - $this->avatarFile = $this->getMock('OCP\Files\File'); + $this->avatarFile = $this->getMockBuilder('OCP\Files\File')->getMock(); $this->avatarFile->method('getContent')->willReturn('image data'); $this->avatarFile->method('getMimeType')->willReturn('image type'); $this->avatarFile->method('getEtag')->willReturn('my etag'); @@ -326,7 +326,7 @@ class AvatarControllerTest extends \Test\TestCase { * Test posting avatar from existing folder */ public function testPostAvatarFromNoFile() { - $file = $this->getMock('OCP\Files\Node'); + $file = $this->getMockBuilder('OCP\Files\Node')->getMock(); $this->container['UserFolder'] ->method('get') ->with('folder') From 87ac72d004b318c4b90c93f303575ba19f5b9cd9 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Mon, 15 Aug 2016 20:08:20 +0200 Subject: [PATCH 10/10] We have to mock the is_uploaded_file in the OC\Core\Controller namespace --- tests/Core/Controller/AvatarControllerTest.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/tests/Core/Controller/AvatarControllerTest.php b/tests/Core/Controller/AvatarControllerTest.php index 4a7b7f2178..d45d061823 100644 --- a/tests/Core/Controller/AvatarControllerTest.php +++ b/tests/Core/Controller/AvatarControllerTest.php @@ -19,6 +19,16 @@ * */ +namespace OC\Core\Controller; + +/** + * Overwrite is_uploaded_file in the OC\Core\Controller namespace to allow + * proper unit testing of the postAvatar call. + */ +function is_uploaded_file($filename) { + return file_exists($filename); +} + namespace Tests\Core\Controller; use OC\Core\Application; @@ -31,14 +41,6 @@ use OCP\IAvatar; use Punic\Exception; use Test\Traits\UserTrait; -/** - * Overwrite is_uploaded_file in this namespace to allow proper unit testing of - * the postAvatar call. - */ -function is_uploaded_file($filename) { - return file_exists($filename); -} - /** * Class AvatarControllerTest *