aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2018-01-17 13:46:18 +0100
committerGitHub <noreply@github.com>2018-01-17 13:46:18 +0100
commitf8756d96bc7821a1082dd19cb8aea6d0b933505a (patch)
tree7fc39b205b0f38948fb6965eae8b693ecb4d0055
parent73cc4ac1f688cb181e3072490699f054b8c91e8c (diff)
parent8614eb91db754eec7904841e44fbbbc63ffb013a (diff)
downloadnextcloud-server-f8756d96bc7821a1082dd19cb8aea6d0b933505a.tar.gz
nextcloud-server-f8756d96bc7821a1082dd19cb8aea6d0b933505a.zip
Merge pull request #7847 from nextcloud/avatarmanager_strict
Fixes for avatarmanager
-rw-r--r--apps/dav/lib/Avatars/AvatarHome.php2
-rw-r--r--apps/dav/tests/unit/Avatars/AvatarHomeTest.php17
-rw-r--r--lib/private/AvatarManager.php14
-rw-r--r--lib/private/Server.php7
-rw-r--r--lib/public/IAvatarManager.php7
-rw-r--r--tests/lib/AvatarManagerTest.php5
6 files changed, 27 insertions, 25 deletions
diff --git a/apps/dav/lib/Avatars/AvatarHome.php b/apps/dav/lib/Avatars/AvatarHome.php
index ee654f2aaa2..2047c5894e4 100644
--- a/apps/dav/lib/Avatars/AvatarHome.php
+++ b/apps/dav/lib/Avatars/AvatarHome.php
@@ -70,7 +70,7 @@ class AvatarHome implements ICollection {
throw new MethodNotAllowed('Invalid image size');
}
$avatar = $this->avatarManager->getAvatar($this->getName());
- if ($avatar === null || !$avatar->exists()) {
+ if (!$avatar->exists()) {
throw new NotFound();
}
return new AvatarNode($size, $ext, $avatar);
diff --git a/apps/dav/tests/unit/Avatars/AvatarHomeTest.php b/apps/dav/tests/unit/Avatars/AvatarHomeTest.php
index aa5c4bf3049..2dffa8b7424 100644
--- a/apps/dav/tests/unit/Avatars/AvatarHomeTest.php
+++ b/apps/dav/tests/unit/Avatars/AvatarHomeTest.php
@@ -86,11 +86,10 @@ class AvatarHomeTest extends TestCase {
if ($expectedException !== null) {
$this->expectException($expectedException);
}
- $avatar = null;
- if ($hasAvatar) {
- $avatar = $this->createMock(IAvatar::class);
- $avatar->expects($this->once())->method('exists')->willReturn(true);
- }
+
+ $avatar = $this->createMock(IAvatar::class);
+ $avatar->method('exists')->willReturn($hasAvatar);
+
$this->avatarManager->expects($this->any())->method('getAvatar')->with('admin')->willReturn($avatar);
$avatarNode = $this->home->getChild($path);
$this->assertInstanceOf(AvatarNode::class, $avatarNode);
@@ -111,11 +110,9 @@ class AvatarHomeTest extends TestCase {
* @dataProvider providesTestGetChild
*/
public function testChildExists($expectedException, $hasAvatar, $path) {
- $avatar = null;
- if ($hasAvatar) {
- $avatar = $this->createMock(IAvatar::class);
- $avatar->expects($this->once())->method('exists')->willReturn(true);
- }
+ $avatar = $this->createMock(IAvatar::class);
+ $avatar->method('exists')->willReturn($hasAvatar);
+
$this->avatarManager->expects($this->any())->method('getAvatar')->with('admin')->willReturn($avatar);
$childExists = $this->home->childExists($path);
$this->assertEquals($hasAvatar, $childExists);
diff --git a/lib/private/AvatarManager.php b/lib/private/AvatarManager.php
index b8c6c2a1eb6..eb455642101 100644
--- a/lib/private/AvatarManager.php
+++ b/lib/private/AvatarManager.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
@@ -27,12 +28,13 @@
namespace OC;
+use OC\User\Manager;
use OCP\Files\IAppData;
use OCP\Files\NotFoundException;
+use OCP\IAvatar;
use OCP\IAvatarManager;
use OCP\IConfig;
use OCP\ILogger;
-use OCP\IUserManager;
use OCP\IL10N;
/**
@@ -40,7 +42,7 @@ use OCP\IL10N;
*/
class AvatarManager implements IAvatarManager {
- /** @var IUserManager */
+ /** @var Manager */
private $userManager;
/** @var IAppData */
@@ -58,14 +60,14 @@ class AvatarManager implements IAvatarManager {
/**
* AvatarManager constructor.
*
- * @param IUserManager $userManager
+ * @param Manager $userManager
* @param IAppData $appData
* @param IL10N $l
* @param ILogger $logger
* @param IConfig $config
*/
public function __construct(
- IUserManager $userManager,
+ Manager $userManager,
IAppData $appData,
IL10N $l,
ILogger $logger,
@@ -85,9 +87,9 @@ class AvatarManager implements IAvatarManager {
* @throws \Exception In case the username is potentially dangerous
* @throws NotFoundException In case there is no user folder yet
*/
- public function getAvatar($userId) {
+ public function getAvatar(string $userId) : IAvatar {
$user = $this->userManager->get($userId);
- if (is_null($user)) {
+ if ($user === null) {
throw new \Exception('user does not exist');
}
diff --git a/lib/private/Server.php b/lib/private/Server.php
index 4a851d67226..380ab633b8c 100644
--- a/lib/private/Server.php
+++ b/lib/private/Server.php
@@ -284,11 +284,12 @@ class Server extends ServerContainer implements IServerContainer {
});
$this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class);
- $this->registerService(\OCP\IUserManager::class, function (Server $c) {
+ $this->registerService(\OC\User\Manager::class, function (Server $c) {
$config = $c->getConfig();
return new \OC\User\Manager($config);
});
- $this->registerAlias('UserManager', \OCP\IUserManager::class);
+ $this->registerAlias('UserManager', \OC\User\Manager::class);
+ $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class);
$this->registerService(\OCP\IGroupManager::class, function (Server $c) {
$groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger());
@@ -523,7 +524,7 @@ class Server extends ServerContainer implements IServerContainer {
$this->registerService(\OCP\IAvatarManager::class, function (Server $c) {
return new AvatarManager(
- $c->getUserManager(),
+ $c->query(\OC\User\Manager::class),
$c->getAppDataDir('avatar'),
$c->getL10N('lib'),
$c->getLogger(),
diff --git a/lib/public/IAvatarManager.php b/lib/public/IAvatarManager.php
index 04f4cd00d0d..19e4b93503a 100644
--- a/lib/public/IAvatarManager.php
+++ b/lib/public/IAvatarManager.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
@@ -35,12 +36,12 @@ interface IAvatarManager {
/**
* return a user specific instance of \OCP\IAvatar
- * @see \OCP\IAvatar
+ * @see IAvatar
* @param string $user the ownCloud user id
- * @return \OCP\IAvatar
+ * @return IAvatar
* @throws \Exception In case the username is potentially dangerous
* @throws \OCP\Files\NotFoundException In case there is no user folder yet
* @since 6.0.0
*/
- public function getAvatar($user);
+ public function getAvatar(string $user) : IAvatar;
}
diff --git a/tests/lib/AvatarManagerTest.php b/tests/lib/AvatarManagerTest.php
index 83a5cfd9b30..9f2a4f4f337 100644
--- a/tests/lib/AvatarManagerTest.php
+++ b/tests/lib/AvatarManagerTest.php
@@ -27,6 +27,7 @@ namespace Test;
use OC\Avatar;
use OC\AvatarManager;
use OC\Files\AppData\AppData;
+use OC\User\Manager;
use OCP\Files\IAppData;
use OCP\Files\SimpleFS\ISimpleFolder;
use OCP\IConfig;
@@ -39,7 +40,7 @@ use OCP\IUserManager;
* Class AvatarManagerTest
*/
class AvatarManagerTest extends \Test\TestCase {
- /** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
+ /** @var Manager|\PHPUnit_Framework_MockObject_MockObject */
private $userManager;
/** @var IAppData|\PHPUnit_Framework_MockObject_MockObject */
private $appData;
@@ -55,7 +56,7 @@ class AvatarManagerTest extends \Test\TestCase {
public function setUp() {
parent::setUp();
- $this->userManager = $this->createMock(IUserManager::class);
+ $this->userManager = $this->createMock(Manager::class);
$this->appData = $this->createMock(IAppData::class);
$this->l10n = $this->createMock(IL10N::class);
$this->logger = $this->createMock(ILogger::class);