Browse Source

Properly inject the logger

Signed-off-by: Morris Jobke <hey@morrisjobke.de>
tags/v17.0.0beta1
Morris Jobke 5 years ago
parent
commit
99f2c82222
No account linked to committer's email address
4 changed files with 24 additions and 11 deletions
  1. 9
    3
      lib/private/App/AppManager.php
  2. 2
    1
      lib/private/Server.php
  3. 11
    6
      tests/lib/App/AppManagerTest.php
  4. 2
    1
      tests/lib/AppTest.php

+ 9
- 3
lib/private/App/AppManager.php View File

@@ -39,6 +39,7 @@ use OCP\App\ManagerEvent;
use OCP\ICacheFactory;
use OCP\IGroup;
use OCP\IGroupManager;
use OCP\ILogger;
use OCP\IUser;
use OCP\IUserSession;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
@@ -72,6 +73,9 @@ class AppManager implements IAppManager {
/** @var EventDispatcherInterface */
private $dispatcher;

/** @var ILogger */
private $logger;

/** @var string[] $appId => $enabled */
private $installedAppsCache;

@@ -98,12 +102,14 @@ class AppManager implements IAppManager {
AppConfig $appConfig,
IGroupManager $groupManager,
ICacheFactory $memCacheFactory,
EventDispatcherInterface $dispatcher) {
EventDispatcherInterface $dispatcher,
ILogger $logger) {
$this->userSession = $userSession;
$this->appConfig = $appConfig;
$this->groupManager = $groupManager;
$this->memCacheFactory = $memCacheFactory;
$this->dispatcher = $dispatcher;
$this->logger = $logger;
}

/**
@@ -220,7 +226,7 @@ class AppManager implements IAppManager {

if (!is_array($groupIds)) {
$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;
}

@@ -253,7 +259,7 @@ class AppManager implements IAppManager {

if (!is_array($groupIds)) {
$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;
}


+ 2
- 1
lib/private/Server.php View File

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

+ 11
- 6
tests/lib/App/AppManagerTest.php View File

@@ -19,6 +19,7 @@ use OCP\ICache;
use OCP\ICacheFactory;
use OCP\IGroup;
use OCP\IGroupManager;
use OCP\ILogger;
use OCP\IUser;
use OCP\IUserSession;
use OCP\IAppConfig;
@@ -90,6 +91,9 @@ class AppManagerTest extends TestCase {
/** @var EventDispatcherInterface|\PHPUnit_Framework_MockObject_MockObject */
protected $eventDispatcher;

/** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */
protected $logger;

/** @var IAppManager */
protected $manager;

@@ -102,11 +106,12 @@ class AppManagerTest extends TestCase {
$this->cacheFactory = $this->createMock(ICacheFactory::class);
$this->cache = $this->createMock(ICache::class);
$this->eventDispatcher = $this->createMock(EventDispatcherInterface::class);
$this->logger = $this->createMock(ILogger::class);
$this->cacheFactory->expects($this->any())
->method('createDistributed')
->with('settings')
->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() {
@@ -159,7 +164,7 @@ class AppManagerTest extends TestCase {
/** @var AppManager|\PHPUnit_Framework_MockObject_MockObject $manager */
$manager = $this->getMockBuilder(AppManager::class)
->setConstructorArgs([
$this->userSession, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher
$this->userSession, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher, $this->logger
])
->setMethods([
'getAppPath',
@@ -206,7 +211,7 @@ class AppManagerTest extends TestCase {
/** @var AppManager|\PHPUnit_Framework_MockObject_MockObject $manager */
$manager = $this->getMockBuilder(AppManager::class)
->setConstructorArgs([
$this->userSession, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher
$this->userSession, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher, $this->logger
])
->setMethods([
'getAppPath',
@@ -259,7 +264,7 @@ class AppManagerTest extends TestCase {
/** @var AppManager|\PHPUnit_Framework_MockObject_MockObject $manager */
$manager = $this->getMockBuilder(AppManager::class)
->setConstructorArgs([
$this->userSession, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher
$this->userSession, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher, $this->logger
])
->setMethods([
'getAppPath',
@@ -418,7 +423,7 @@ class AppManagerTest extends TestCase {
public function testGetAppsNeedingUpgrade() {
/** @var AppManager|\PHPUnit_Framework_MockObject_MockObject $manager */
$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'])
->getMock();

@@ -466,7 +471,7 @@ class AppManagerTest extends TestCase {
public function testGetIncompatibleApps() {
/** @var AppManager|\PHPUnit_Framework_MockObject_MockObject $manager */
$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'])
->getMock();


+ 2
- 1
tests/lib/AppTest.php View File

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


Loading…
Cancel
Save