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

index dad7546dcb8616d6497f2aecc4cb852c480c8673..5a2bc477fee568a79f6743907dce1b69cb6ecfe3 100644 (file)
@@ -32,9 +32,6 @@ namespace OC\Core;
 
 use OC\Security\IdentityProof\Manager;
 use OCP\AppFramework\App;
-use OC\Core\Controller\CssController;
-use OCP\AppFramework\Utility\ITimeFactory;
-use OCP\IRequest;
 use OCP\Util;
 
 /**
@@ -58,13 +55,5 @@ class Application extends App {
                                \OC::$server->getCrypto()
                        );
                });
-               $container->registerService(CssController::class, function () use ($container) {
-                       return new CssController(
-                               $container->query('appName'),
-                               $container->query(IRequest::class),
-                               \OC::$server->getAppDataDir('css'),
-                               $container->query(ITimeFactory::class)
-                       );
-               });
        }
 }
index 57197e9999e5e21f634c84c569b35363cd05f3b2..3cf477290fe7e8e33203779aba1675fb3e0da672 100644 (file)
@@ -21,6 +21,7 @@
 
 namespace OC\Core\Controller;
 
+use OC\Files\AppData\Factory;
 use OCP\AppFramework\Controller;
 use OCP\AppFramework\Http;
 use OCP\AppFramework\Http\NotFoundResponse;
@@ -43,13 +44,13 @@ class CssController 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('css');
                $this->timeFactory = $timeFactory;
        }
 
index 30bbc12809e9bd024966baa67dd91529f326855e..c78233d8917575bcc5d4728cfda33db5161230d1 100644 (file)
@@ -23,7 +23,7 @@
 namespace Tests\Core\Controller;
 
 use OC\Core\Controller\CssController;
-use OC\HintException;
+use OC\Files\AppData\Factory;
 use OCP\AppFramework\Http;
 use OCP\AppFramework\Http\FileDisplayResponse;
 use OCP\AppFramework\Http\NotFoundResponse;
@@ -40,7 +40,7 @@ class CssControllerTest extends TestCase {
        /** @var IAppData|\PHPUnit_Framework_MockObject_MockObject */
        private $appData;
 
-       /** @var IRequests|\PHPUnit_Framework_MockObject_MockObject */
+       /** @var IRequest|\PHPUnit_Framework_MockObject_MockObject */
        private $request;
 
        /** @var CssController */
@@ -49,8 +49,15 @@ class CssControllerTest 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('css')
+                       ->willReturn($this->appData);
 
+               /** @var ITimeFactory|\PHPUnit_Framework_MockObject_MockObject $timeFactory */
                $timeFactory = $this->createMock(ITimeFactory::class);
                $timeFactory->method('getTime')
                        ->willReturn(1337);
@@ -60,7 +67,7 @@ class CssControllerTest extends TestCase {
                $this->controller = new CssController(
                        'core',
                        $this->request,
-                       $this->appData,
+                       $factory,
                        $timeFactory
                );
        }