]> source.dussan.org Git - nextcloud-server.git/commitdiff
Automatic injection for JsController
authorJoas Schilling <coding@schilljs.com>
Wed, 10 May 2017 07:41:33 +0000 (09:41 +0200)
committerJoas Schilling <coding@schilljs.com>
Wed, 10 May 2017 07:42:15 +0000 (09:42 +0200)
Signed-off-by: Joas Schilling <coding@schilljs.com>
core/Application.php
core/Controller/JsController.php
tests/Core/Controller/JsControllerTest.php

index 6fa301e59062983b4557586ca9b2a6e69cb0c4f0..dad7546dcb8616d6497f2aecc4cb852c480c8673 100644 (file)
@@ -30,7 +30,6 @@
 
 namespace OC\Core;
 
-use OC\Core\Controller\JsController;
 use OC\Security\IdentityProof\Manager;
 use OCP\AppFramework\App;
 use OC\Core\Controller\CssController;
@@ -67,13 +66,5 @@ class Application extends App {
                                $container->query(ITimeFactory::class)
                        );
                });
-               $container->registerService(JsController::class, function () use ($container) {
-                       return new JsController(
-                               $container->query('AppName'),
-                               $container->query(IRequest::class),
-                               $container->getServer()->getAppDataDir('js'),
-                               $container->query(ITimeFactory::class)
-                       );
-               });
        }
 }
index c7c9dea9101681b2e62c3ad964970fb1c90d8b60..1a025edbcad0d14fbdb504c55a5cf5402abe025e 100644 (file)
@@ -22,6 +22,7 @@
  */
 namespace OC\Core\Controller;
 
+use OC\Files\AppData\Factory;
 use OCP\AppFramework\Controller;
 use OCP\AppFramework\Http;
 use OCP\AppFramework\Http\NotFoundResponse;
@@ -44,13 +45,13 @@ class JsController extends Controller {
        /**
         * @param string $appName
         * @param IRequest $request
-        * @param IAppData $appData
+        * @param Factory $appDataFactory
         * @param ITimeFactory $timeFactory
         */
-       public function __construct($appName, IRequest $request, IAppData $appData, ITimeFactory $timeFactory) {
+       public function __construct($appName, IRequest $request, Factory $appDataFactory, ITimeFactory $timeFactory) {
                parent::__construct($appName, $request);
 
-               $this->appData = $appData;
+               $this->appData = $appDataFactory->get('js');
                $this->timeFactory = $timeFactory;
        }
 
index 8456ba8b6e3890a1262750c064a2473beceecef8..571318c89d0fdcaa9ff41c56b94d598f6e4cefc3 100644 (file)
@@ -23,6 +23,7 @@
 namespace Tests\Core\Controller;
 
 use OC\Core\Controller\JsController;
+use OC\Files\AppData\Factory;
 use OCP\AppFramework\Http;
 use OCP\AppFramework\Http\FileDisplayResponse;
 use OCP\AppFramework\Http\NotFoundResponse;
@@ -48,8 +49,15 @@ class JsControllerTest extends TestCase {
        public function setUp() {
                parent::setUp();
 
+               /** @var Factory|\PHPUnit_Framework_MockObject_MockObject $factory */
+               $factory = $this->createMock(Factory::class);
                $this->appData = $this->createMock(IAppData::class);
+               $factory->expects($this->once())
+                       ->method('get')
+                       ->with('js')
+                       ->willReturn($this->appData);
 
+               /** @var ITimeFactory|\PHPUnit_Framework_MockObject_MockObject $timeFactory */
                $timeFactory = $this->createMock(ITimeFactory::class);
                $timeFactory->method('getTime')
                        ->willReturn(1337);
@@ -59,7 +67,7 @@ class JsControllerTest extends TestCase {
                $this->controller = new JsController(
                        'core',
                        $this->request,
-                       $this->appData,
+                       $factory,
                        $timeFactory
                );
        }