]> source.dussan.org Git - nextcloud-server.git/commitdiff
Properly inject the logger 16075/head
authorMorris Jobke <hey@morrisjobke.de>
Mon, 15 Jul 2019 20:19:11 +0000 (22:19 +0200)
committerMorris Jobke <hey@morrisjobke.de>
Tue, 16 Jul 2019 20:38:14 +0000 (22:38 +0200)
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
lib/private/App/AppManager.php
lib/private/Server.php
tests/lib/App/AppManagerTest.php
tests/lib/AppTest.php

index 77756999c793c698671cf90749ec48d5ee3fd57c..17addc86c9d840b184932feeb0e8d70d5966a54f 100644 (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;
                        }
 
index 408b457ec390a5cededaeedb28df76880c785ddb..ed095f7a5fd4d3c319f75eca0f4857109697c9f6 100644 (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);
index ba693999205aa009f8befc14fe93bd567cf05e69..371c2373f81ce5cb5f0e0009450155b1e6532cdb 100644 (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();
 
index 5d98dc7df5799d88bbe69ea509a7cb4b48563409..954ffcfae7f1fd3a5d8e8eb38d2167ee3a721673 100644 (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()
                ));
        }