]> source.dussan.org Git - nextcloud-server.git/commitdiff
Automatic injection into the Fetchers 4783/head
authorJoas Schilling <coding@schilljs.com>
Wed, 10 May 2017 07:56:38 +0000 (09:56 +0200)
committerJoas Schilling <coding@schilljs.com>
Wed, 10 May 2017 07:56:38 +0000 (09:56 +0200)
Signed-off-by: Joas Schilling <coding@schilljs.com>
lib/private/App/AppStore/Fetcher/AppFetcher.php
lib/private/App/AppStore/Fetcher/CategoryFetcher.php
lib/private/App/AppStore/Fetcher/Fetcher.php
lib/private/Server.php
lib/private/Updater.php
settings/Application.php
tests/lib/App/AppStore/Fetcher/AppFetcherTest.php
tests/lib/App/AppStore/Fetcher/CategoryFetcherTest.php
tests/lib/App/AppStore/Fetcher/FetcherBase.php

index e020390988e9ebad35e2f8919901302bf378741e..2e181d754f126d4886e77c45cd5e199dc8f1462b 100644 (file)
 namespace OC\App\AppStore\Fetcher;
 
 use OC\App\AppStore\Version\VersionParser;
+use OC\Files\AppData\Factory;
 use OCP\AppFramework\Utility\ITimeFactory;
-use OCP\Files\IAppData;
 use OCP\Http\Client\IClientService;
 use OCP\IConfig;
 
 class AppFetcher extends Fetcher {
        /**
-        * @param IAppData $appData
+        * @param Factory $appDataFactory
         * @param IClientService $clientService
         * @param ITimeFactory $timeFactory
         * @param IConfig $config;
         */
-       public function __construct(IAppData $appData,
+       public function __construct(Factory $appDataFactory,
                                                                IClientService $clientService,
                                                                ITimeFactory $timeFactory,
                                                                IConfig $config) {
                parent::__construct(
-                       $appData,
+                       $appDataFactory,
                        $clientService,
                        $timeFactory,
                        $config
index 8b79259a66af3fddcf169b730b6be1326a571c21..4c78665283386c2c617ce36b3b4b9f969d5e7298 100644 (file)
 
 namespace OC\App\AppStore\Fetcher;
 
+use OC\Files\AppData\Factory;
 use OCP\AppFramework\Utility\ITimeFactory;
-use OCP\Files\IAppData;
 use OCP\Http\Client\IClientService;
 use OCP\IConfig;
 
 class CategoryFetcher extends Fetcher {
        /**
-        * @param IAppData $appData
+        * @param Factory $appDataFactory
         * @param IClientService $clientService
         * @param ITimeFactory $timeFactory
         * @param IConfig $config
         */
-       public function __construct(IAppData $appData,
+       public function __construct(Factory $appDataFactory,
                                                                IClientService $clientService,
                                                                ITimeFactory $timeFactory,
                                                                IConfig $config) {
                parent::__construct(
-                       $appData,
+                       $appDataFactory,
                        $clientService,
                        $timeFactory,
                        $config
index 5354d334eb101a0f3f9aaa5a596ddc5930175d26..ccf5162ed82c4806fe1172caf76c1757f08ab075 100644 (file)
@@ -21,6 +21,7 @@
 
 namespace OC\App\AppStore\Fetcher;
 
+use OC\Files\AppData\Factory;
 use OCP\AppFramework\Http;
 use OCP\AppFramework\Utility\ITimeFactory;
 use OCP\Files\IAppData;
@@ -47,16 +48,16 @@ abstract class Fetcher {
        protected $version;
 
        /**
-        * @param IAppData $appData
+        * @param Factory $appDataFactory
         * @param IClientService $clientService
         * @param ITimeFactory $timeFactory
         * @param IConfig $config
         */
-       public function __construct(IAppData $appData,
+       public function __construct(Factory $appDataFactory,
                                                                IClientService $clientService,
                                                                ITimeFactory $timeFactory,
                                                                IConfig $config) {
-               $this->appData = $appData;
+               $this->appData = $appDataFactory->get('appstore');
                $this->clientService = $clientService;
                $this->timeFactory = $timeFactory;
                $this->config = $config;
index 07e449ee4a9d4ca6864f52c4f5e53293166e6b1b..8e17ae397b73eaeffb1ab758d63f6bad426358e7 100644 (file)
@@ -420,24 +420,8 @@ class Server extends ServerContainer implements IServerContainer {
                $this->registerService('AppHelper', function ($c) {
                        return new \OC\AppHelper();
                });
-               $this->registerService(AppFetcher::class, function ($c) {
-                       return new AppFetcher(
-                               $this->getAppDataDir('appstore'),
-                               $this->getHTTPClientService(),
-                               $this->query(TimeFactory::class),
-                               $this->getConfig()
-                       );
-               });
                $this->registerAlias('AppFetcher', AppFetcher::class);
-
-               $this->registerService('CategoryFetcher', function ($c) {
-                       return new CategoryFetcher(
-                               $this->getAppDataDir('appstore'),
-                               $this->getHTTPClientService(),
-                               $this->query(TimeFactory::class),
-                               $this->getConfig()
-                       );
-               });
+               $this->registerAlias('CategoryFetcher', CategoryFetcher::class);
 
                $this->registerService(\OCP\ICache::class, function ($c) {
                        return new Cache\File();
@@ -1290,7 +1274,7 @@ class Server extends ServerContainer implements IServerContainer {
         * @return AppFetcher
         */
        public function getAppFetcher() {
-               return $this->query('AppFetcher');
+               return $this->query(AppFetcher::class);
        }
 
        /**
index 5c4a7725a1b208b395c62fa06627b264ac897e96..023b3e6972cefa02cdddc9f312e1bcc820d41ad5 100644 (file)
@@ -32,7 +32,6 @@
 
 namespace OC;
 
-use OC\App\AppStore\Fetcher\AppFetcher;
 use OC\Hooks\BasicEmitter;
 use OC\IntegrityCheck\Checker;
 use OC_App;
index 52661c5bae22af6c421e5a08b3807abef70c3f9c..0ca2d28dfe6a29431f950eced1ae9d389cfe6114 100644 (file)
@@ -30,8 +30,6 @@
 
 namespace OC\Settings;
 
-use OC\App\AppStore\Fetcher\AppFetcher;
-use OC\App\AppStore\Fetcher\CategoryFetcher;
 use OC\AppFramework\Utility\TimeFactory;
 use OC\Authentication\Token\IProvider;
 use OC\Server;
@@ -110,26 +108,6 @@ class Application extends App {
                                Util::getDefaultEmailAddress('no-reply')
                        );
                });
-               $container->registerService(AppFetcher::class, function (IContainer $c) {
-                       /** @var Server $server */
-                       $server = $c->query('ServerContainer');
-                       return new AppFetcher(
-                               $server->getAppDataDir('appstore'),
-                               $server->getHTTPClientService(),
-                               $server->query(TimeFactory::class),
-                               $server->getConfig()
-                       );
-               });
-               $container->registerService(CategoryFetcher::class, function (IContainer $c) {
-                       /** @var Server $server */
-                       $server = $c->query('ServerContainer');
-                       return new CategoryFetcher(
-                               $server->getAppDataDir('appstore'),
-                               $server->getHTTPClientService(),
-                               $server->query(TimeFactory::class),
-                               $server->getConfig()
-                       );
-               });
        }
 
        public function register() {
index 6c0d079a2041b0cecb8b40b6c7d7ca2332e4b9a0..f3769fc09c36df56a9a5ef0fef17ae0576b3ff69 100644 (file)
@@ -22,6 +22,7 @@
 namespace Test\App\AppStore\Fetcher;
 
 use OC\App\AppStore\Fetcher\AppFetcher;
+use OC\Files\AppData\Factory;
 use OCP\AppFramework\Utility\ITimeFactory;
 use OCP\Files\IAppData;
 use OCP\Files\NotFoundException;
@@ -53,7 +54,13 @@ EOD;
        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('appstore')
+                       ->willReturn($this->appData);
                $this->clientService = $this->createMock(IClientService::class);
                $this->timeFactory = $this->createMock(ITimeFactory::class);
                $this->config = $this->createMock(IConfig::class);
@@ -64,7 +71,7 @@ EOD;
                        ->with('version')
                        ->willReturn('11.0.0.2');
                $this->fetcher = new AppFetcher(
-                       $this->appData,
+                       $factory,
                        $this->clientService,
                        $this->timeFactory,
                        $this->config
index 27f33bed99729683858bbbf117a853aa5507f3a2..6143da662dc9c4735ce7a70a612a13c75e679c0e 100644 (file)
@@ -23,14 +23,14 @@ namespace Test\App\AppStore\Fetcher;
 
 use OC\App\AppStore\Fetcher\CategoryFetcher;
 
-class CategoryFetcherTest extends FetcherBase  {
+class CategoryFetcherTest extends FetcherBase {
        public function setUp() {
                parent::setUp();
                $this->fileName = 'categories.json';
                $this->endpoint = 'https://apps.nextcloud.com/api/v1/categories.json';
 
                $this->fetcher = new CategoryFetcher(
-                       $this->appData,
+                       $this->appDataFactory,
                        $this->clientService,
                        $this->timeFactory,
                        $this->config
index 96e4f3ae81a821c82cd84a9e40a0fcbdc2b9e3ce..3d89ae942abdbe559374efe03849c9e0c07a9529 100644 (file)
@@ -22,6 +22,7 @@
 namespace Test\App\AppStore\Fetcher;
 
 use OC\App\AppStore\Fetcher\Fetcher;
+use OC\Files\AppData\Factory;
 use OCP\AppFramework\Utility\ITimeFactory;
 use OCP\Files\IAppData;
 use OCP\Files\NotFoundException;
@@ -34,6 +35,8 @@ use OCP\IConfig;
 use Test\TestCase;
 
 abstract class FetcherBase extends TestCase {
+       /** @var Factory|\PHPUnit_Framework_MockObject_MockObject */
+       protected $appDataFactory;
        /** @var IAppData|\PHPUnit_Framework_MockObject_MockObject */
        protected $appData;
        /** @var IClientService|\PHPUnit_Framework_MockObject_MockObject */
@@ -51,7 +54,12 @@ abstract class FetcherBase extends TestCase {
 
        public function setUp() {
                parent::setUp();
+               $this->appDataFactory = $this->createMock(Factory::class);
                $this->appData = $this->createMock(IAppData::class);
+               $this->appDataFactory->expects($this->once())
+                       ->method('get')
+                       ->with('appstore')
+                       ->willReturn($this->appData);
                $this->clientService = $this->createMock(IClientService::class);
                $this->timeFactory = $this->createMock(ITimeFactory::class);
                $this->config = $this->createMock(IConfig::class);