diff options
author | Joas Schilling <coding@schilljs.com> | 2017-05-10 09:56:38 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2017-05-10 09:56:38 +0200 |
commit | 538d32fe8734f563f3116c473f770bd4277c925b (patch) | |
tree | 004d99e6d04fdf07863ce3983869805b76833b3a | |
parent | ca399406146d74f2f46f8b8815f0b3c165c996ab (diff) | |
download | nextcloud-server-538d32fe8734f563f3116c473f770bd4277c925b.tar.gz nextcloud-server-538d32fe8734f563f3116c473f770bd4277c925b.zip |
Automatic injection into the Fetchers
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r-- | lib/private/App/AppStore/Fetcher/AppFetcher.php | 8 | ||||
-rw-r--r-- | lib/private/App/AppStore/Fetcher/CategoryFetcher.php | 8 | ||||
-rw-r--r-- | lib/private/App/AppStore/Fetcher/Fetcher.php | 7 | ||||
-rw-r--r-- | lib/private/Server.php | 20 | ||||
-rw-r--r-- | lib/private/Updater.php | 1 | ||||
-rw-r--r-- | settings/Application.php | 22 | ||||
-rw-r--r-- | tests/lib/App/AppStore/Fetcher/AppFetcherTest.php | 9 | ||||
-rw-r--r-- | tests/lib/App/AppStore/Fetcher/CategoryFetcherTest.php | 4 | ||||
-rw-r--r-- | tests/lib/App/AppStore/Fetcher/FetcherBase.php | 8 |
9 files changed, 32 insertions, 55 deletions
diff --git a/lib/private/App/AppStore/Fetcher/AppFetcher.php b/lib/private/App/AppStore/Fetcher/AppFetcher.php index e020390988e..2e181d754f1 100644 --- a/lib/private/App/AppStore/Fetcher/AppFetcher.php +++ b/lib/private/App/AppStore/Fetcher/AppFetcher.php @@ -22,24 +22,24 @@ 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 diff --git a/lib/private/App/AppStore/Fetcher/CategoryFetcher.php b/lib/private/App/AppStore/Fetcher/CategoryFetcher.php index 8b79259a66a..4c786652833 100644 --- a/lib/private/App/AppStore/Fetcher/CategoryFetcher.php +++ b/lib/private/App/AppStore/Fetcher/CategoryFetcher.php @@ -21,24 +21,24 @@ 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 diff --git a/lib/private/App/AppStore/Fetcher/Fetcher.php b/lib/private/App/AppStore/Fetcher/Fetcher.php index 5354d334eb1..ccf5162ed82 100644 --- a/lib/private/App/AppStore/Fetcher/Fetcher.php +++ b/lib/private/App/AppStore/Fetcher/Fetcher.php @@ -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; diff --git a/lib/private/Server.php b/lib/private/Server.php index 07e449ee4a9..8e17ae397b7 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -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); } /** diff --git a/lib/private/Updater.php b/lib/private/Updater.php index 5c4a7725a1b..023b3e6972c 100644 --- a/lib/private/Updater.php +++ b/lib/private/Updater.php @@ -32,7 +32,6 @@ namespace OC; -use OC\App\AppStore\Fetcher\AppFetcher; use OC\Hooks\BasicEmitter; use OC\IntegrityCheck\Checker; use OC_App; diff --git a/settings/Application.php b/settings/Application.php index 52661c5bae2..0ca2d28dfe6 100644 --- a/settings/Application.php +++ b/settings/Application.php @@ -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() { diff --git a/tests/lib/App/AppStore/Fetcher/AppFetcherTest.php b/tests/lib/App/AppStore/Fetcher/AppFetcherTest.php index 6c0d079a204..f3769fc09c3 100644 --- a/tests/lib/App/AppStore/Fetcher/AppFetcherTest.php +++ b/tests/lib/App/AppStore/Fetcher/AppFetcherTest.php @@ -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 diff --git a/tests/lib/App/AppStore/Fetcher/CategoryFetcherTest.php b/tests/lib/App/AppStore/Fetcher/CategoryFetcherTest.php index 27f33bed997..6143da662dc 100644 --- a/tests/lib/App/AppStore/Fetcher/CategoryFetcherTest.php +++ b/tests/lib/App/AppStore/Fetcher/CategoryFetcherTest.php @@ -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 diff --git a/tests/lib/App/AppStore/Fetcher/FetcherBase.php b/tests/lib/App/AppStore/Fetcher/FetcherBase.php index 96e4f3ae81a..3d89ae942ab 100644 --- a/tests/lib/App/AppStore/Fetcher/FetcherBase.php +++ b/tests/lib/App/AppStore/Fetcher/FetcherBase.php @@ -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); |