Properly inject the logger

Signed-off-by: Morris Jobke <hey@morrisjobke.de>
This commit is contained in:
Morris Jobke 2019-07-15 22:19:11 +02:00
parent 5898e87e0f
commit 99f2c82222
No known key found for this signature in database
GPG Key ID: FE03C3A163FEDE68
4 changed files with 24 additions and 11 deletions

View File

@ -39,6 +39,7 @@ use OCP\App\ManagerEvent;
use OCP\ICacheFactory; use OCP\ICacheFactory;
use OCP\IGroup; use OCP\IGroup;
use OCP\IGroupManager; use OCP\IGroupManager;
use OCP\ILogger;
use OCP\IUser; use OCP\IUser;
use OCP\IUserSession; use OCP\IUserSession;
use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface;
@ -72,6 +73,9 @@ class AppManager implements IAppManager {
/** @var EventDispatcherInterface */ /** @var EventDispatcherInterface */
private $dispatcher; private $dispatcher;
/** @var ILogger */
private $logger;
/** @var string[] $appId => $enabled */ /** @var string[] $appId => $enabled */
private $installedAppsCache; private $installedAppsCache;
@ -98,12 +102,14 @@ class AppManager implements IAppManager {
AppConfig $appConfig, AppConfig $appConfig,
IGroupManager $groupManager, IGroupManager $groupManager,
ICacheFactory $memCacheFactory, ICacheFactory $memCacheFactory,
EventDispatcherInterface $dispatcher) { EventDispatcherInterface $dispatcher,
ILogger $logger) {
$this->userSession = $userSession; $this->userSession = $userSession;
$this->appConfig = $appConfig; $this->appConfig = $appConfig;
$this->groupManager = $groupManager; $this->groupManager = $groupManager;
$this->memCacheFactory = $memCacheFactory; $this->memCacheFactory = $memCacheFactory;
$this->dispatcher = $dispatcher; $this->dispatcher = $dispatcher;
$this->logger = $logger;
} }
/** /**
@ -220,7 +226,7 @@ class AppManager implements IAppManager {
if (!is_array($groupIds)) { if (!is_array($groupIds)) {
$jsonError = json_last_error(); $jsonError = json_last_error();
\OC::$server->getLogger()->warning('AppManger::checkAppForUser - can\'t decode group IDs: ' . print_r($enabled, true) . ' - json error code: ' . $jsonError, ['app' => 'lib']); $this->logger->warning('AppManger::checkAppForUser - can\'t decode group IDs: ' . print_r($enabled, true) . ' - json error code: ' . $jsonError, ['app' => 'lib']);
return false; return false;
} }
@ -253,7 +259,7 @@ class AppManager implements IAppManager {
if (!is_array($groupIds)) { if (!is_array($groupIds)) {
$jsonError = json_last_error(); $jsonError = json_last_error();
\OC::$server->getLogger()->warning('AppManger::checkAppForUser - can\'t decode group IDs: ' . print_r($enabled, true) . ' - json error code: ' . $jsonError, ['app' => 'lib']); $this->logger->warning('AppManger::checkAppForUser - can\'t decode group IDs: ' . print_r($enabled, true) . ' - json error code: ' . $jsonError, ['app' => 'lib']);
return false; return false;
} }

View File

@ -695,7 +695,8 @@ class Server extends ServerContainer implements IServerContainer {
$c->query(\OC\AppConfig::class), $c->query(\OC\AppConfig::class),
$c->getGroupManager(), $c->getGroupManager(),
$c->getMemCacheFactory(), $c->getMemCacheFactory(),
$c->getEventDispatcher() $c->getEventDispatcher(),
$c->getLogger()
); );
}); });
$this->registerAlias('AppManager', AppManager::class); $this->registerAlias('AppManager', AppManager::class);

View File

@ -19,6 +19,7 @@ use OCP\ICache;
use OCP\ICacheFactory; use OCP\ICacheFactory;
use OCP\IGroup; use OCP\IGroup;
use OCP\IGroupManager; use OCP\IGroupManager;
use OCP\ILogger;
use OCP\IUser; use OCP\IUser;
use OCP\IUserSession; use OCP\IUserSession;
use OCP\IAppConfig; use OCP\IAppConfig;
@ -90,6 +91,9 @@ class AppManagerTest extends TestCase {
/** @var EventDispatcherInterface|\PHPUnit_Framework_MockObject_MockObject */ /** @var EventDispatcherInterface|\PHPUnit_Framework_MockObject_MockObject */
protected $eventDispatcher; protected $eventDispatcher;
/** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */
protected $logger;
/** @var IAppManager */ /** @var IAppManager */
protected $manager; protected $manager;
@ -102,11 +106,12 @@ class AppManagerTest extends TestCase {
$this->cacheFactory = $this->createMock(ICacheFactory::class); $this->cacheFactory = $this->createMock(ICacheFactory::class);
$this->cache = $this->createMock(ICache::class); $this->cache = $this->createMock(ICache::class);
$this->eventDispatcher = $this->createMock(EventDispatcherInterface::class); $this->eventDispatcher = $this->createMock(EventDispatcherInterface::class);
$this->logger = $this->createMock(ILogger::class);
$this->cacheFactory->expects($this->any()) $this->cacheFactory->expects($this->any())
->method('createDistributed') ->method('createDistributed')
->with('settings') ->with('settings')
->willReturn($this->cache); ->willReturn($this->cache);
$this->manager = new AppManager($this->userSession, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher); $this->manager = new AppManager($this->userSession, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher, $this->logger);
} }
protected function expectClearCache() { protected function expectClearCache() {
@ -159,7 +164,7 @@ class AppManagerTest extends TestCase {
/** @var AppManager|\PHPUnit_Framework_MockObject_MockObject $manager */ /** @var AppManager|\PHPUnit_Framework_MockObject_MockObject $manager */
$manager = $this->getMockBuilder(AppManager::class) $manager = $this->getMockBuilder(AppManager::class)
->setConstructorArgs([ ->setConstructorArgs([
$this->userSession, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher $this->userSession, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher, $this->logger
]) ])
->setMethods([ ->setMethods([
'getAppPath', 'getAppPath',
@ -206,7 +211,7 @@ class AppManagerTest extends TestCase {
/** @var AppManager|\PHPUnit_Framework_MockObject_MockObject $manager */ /** @var AppManager|\PHPUnit_Framework_MockObject_MockObject $manager */
$manager = $this->getMockBuilder(AppManager::class) $manager = $this->getMockBuilder(AppManager::class)
->setConstructorArgs([ ->setConstructorArgs([
$this->userSession, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher $this->userSession, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher, $this->logger
]) ])
->setMethods([ ->setMethods([
'getAppPath', 'getAppPath',
@ -259,7 +264,7 @@ class AppManagerTest extends TestCase {
/** @var AppManager|\PHPUnit_Framework_MockObject_MockObject $manager */ /** @var AppManager|\PHPUnit_Framework_MockObject_MockObject $manager */
$manager = $this->getMockBuilder(AppManager::class) $manager = $this->getMockBuilder(AppManager::class)
->setConstructorArgs([ ->setConstructorArgs([
$this->userSession, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher $this->userSession, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher, $this->logger
]) ])
->setMethods([ ->setMethods([
'getAppPath', 'getAppPath',
@ -418,7 +423,7 @@ class AppManagerTest extends TestCase {
public function testGetAppsNeedingUpgrade() { public function testGetAppsNeedingUpgrade() {
/** @var AppManager|\PHPUnit_Framework_MockObject_MockObject $manager */ /** @var AppManager|\PHPUnit_Framework_MockObject_MockObject $manager */
$manager = $this->getMockBuilder(AppManager::class) $manager = $this->getMockBuilder(AppManager::class)
->setConstructorArgs([$this->userSession, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher]) ->setConstructorArgs([$this->userSession, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher, $this->logger])
->setMethods(['getAppInfo']) ->setMethods(['getAppInfo'])
->getMock(); ->getMock();
@ -466,7 +471,7 @@ class AppManagerTest extends TestCase {
public function testGetIncompatibleApps() { public function testGetIncompatibleApps() {
/** @var AppManager|\PHPUnit_Framework_MockObject_MockObject $manager */ /** @var AppManager|\PHPUnit_Framework_MockObject_MockObject $manager */
$manager = $this->getMockBuilder(AppManager::class) $manager = $this->getMockBuilder(AppManager::class)
->setConstructorArgs([$this->userSession, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher]) ->setConstructorArgs([$this->userSession, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher, $this->logger])
->setMethods(['getAppInfo']) ->setMethods(['getAppInfo'])
->getMock(); ->getMock();

View File

@ -542,7 +542,8 @@ class AppTest extends \Test\TestCase {
$appConfig, $appConfig,
\OC::$server->getGroupManager(), \OC::$server->getGroupManager(),
\OC::$server->getMemCacheFactory(), \OC::$server->getMemCacheFactory(),
\OC::$server->getEventDispatcher() \OC::$server->getEventDispatcher(),
\OC::$server->getLogger()
)); ));
} }