diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2020-07-16 17:08:03 +0200 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2020-07-21 20:43:18 +0200 |
commit | 91e7f12088cb87ffef5660429ece404364167978 (patch) | |
tree | baf44ebc7b240bd49eb0f6bf615cbb1ed99d13db /apps/comments | |
parent | e029055e766298c5852eedabf06ff42b06a50198 (diff) | |
download | nextcloud-server-91e7f12088cb87ffef5660429ece404364167978.tar.gz nextcloud-server-91e7f12088cb87ffef5660429ece404364167978.zip |
Adjust apps' code to use the ContainerInterface
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'apps/comments')
-rw-r--r-- | apps/comments/lib/AppInfo/Application.php | 11 | ||||
-rw-r--r-- | apps/comments/lib/JSSettingsHelper.php | 8 | ||||
-rw-r--r-- | apps/comments/tests/Unit/JSSettingsHelperTest.php | 16 |
3 files changed, 18 insertions, 17 deletions
diff --git a/apps/comments/lib/AppInfo/Application.php b/apps/comments/lib/AppInfo/Application.php index fafac0c6040..247ba034107 100644 --- a/apps/comments/lib/AppInfo/Application.php +++ b/apps/comments/lib/AppInfo/Application.php @@ -27,6 +27,7 @@ namespace OCA\Comments\AppInfo; +use Closure; use OCA\Comments\Capabilities; use OCA\Comments\Controller\Notifications; use OCA\Comments\EventHandler; @@ -44,6 +45,8 @@ use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IRegistrationContext; use OCP\Comments\CommentsEntityEvent; +use OCP\IConfig; +use OCP\ISearch; use OCP\IServerContainer; use OCP\Util; @@ -75,13 +78,13 @@ class Application extends App implements IBootstrap { } public function boot(IBootContext $context): void { - $this->registerNotifier($context->getServerContainer()); - $this->registerCommentsEventHandler($context->getServerContainer()); + $context->injectFn(Closure::fromCallable([$this, 'registerNotifier'])); + $context->injectFn(Closure::fromCallable([$this, 'registerCommentsEventHandler'])); - $jsSettingsHelper = new JSSettingsHelper($context->getServerContainer()); + $jsSettingsHelper = new JSSettingsHelper($context->getAppContainer()->get(IConfig::class)); Util::connectHook('\OCP\Config', 'js', $jsSettingsHelper, 'extend'); - $context->getServerContainer()->getSearch()->registerProvider(LegacyProvider::class, ['apps' => ['files']]); + $context->getServerContainer()->get(ISearch::class)->registerProvider(LegacyProvider::class, ['apps' => ['files']]); } protected function registerNotifier(IServerContainer $container) { diff --git a/apps/comments/lib/JSSettingsHelper.php b/apps/comments/lib/JSSettingsHelper.php index 4c54bb07c1c..93578e06295 100644 --- a/apps/comments/lib/JSSettingsHelper.php +++ b/apps/comments/lib/JSSettingsHelper.php @@ -23,20 +23,20 @@ namespace OCA\Comments; -use OCP\IServerContainer; +use OCP\IConfig; class JSSettingsHelper { - /** @var IServerContainer */ + /** @var IConfig */ private $c; - public function __construct(IServerContainer $c) { + public function __construct(IConfig $c) { $this->c = $c; } public function extend(array $settings) { $appConfig = json_decode($settings['array']['oc_appconfig'], true); - $value = (int)$this->c->getConfig()->getAppValue('comments', 'maxAutoCompleteResults', 10); + $value = (int)$this->c->getAppValue('comments', 'maxAutoCompleteResults', 10); $appConfig['comments']['maxAutoCompleteResults'] = $value; $settings['array']['oc_appconfig'] = json_encode($appConfig); diff --git a/apps/comments/tests/Unit/JSSettingsHelperTest.php b/apps/comments/tests/Unit/JSSettingsHelperTest.php index 26cdee1f26b..94d13a77d94 100644 --- a/apps/comments/tests/Unit/JSSettingsHelperTest.php +++ b/apps/comments/tests/Unit/JSSettingsHelperTest.php @@ -1,4 +1,7 @@ <?php + +declare(strict_types=1); + /** * @copyright Copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de> * @@ -26,11 +29,11 @@ namespace OCA\Comments\Tests\Unit; use OCA\Comments\JSSettingsHelper; use OCP\IConfig; -use OCP\IServerContainer; +use PHPUnit\Framework\MockObject\MockObject; use Test\TestCase; class JSSettingsHelperTest extends TestCase { - /** @var IServerContainer|\PHPUnit_Framework_MockObject_MockObject */ + /** @var IConfig|MockObject */ protected $c; /** @var JSSettingsHelper */ protected $helper; @@ -38,22 +41,17 @@ class JSSettingsHelperTest extends TestCase { protected function setUp(): void { parent::setUp(); - $this->c = $this->createMock(IServerContainer::class); + $this->c = $this->createMock(IConfig::class); $this->helper = new JSSettingsHelper($this->c); } public function testExtend() { - $config = $this->createMock(IConfig::class); - $config->expects($this->once()) + $this->c->expects($this->once()) ->method('getAppValue') ->with('comments', 'maxAutoCompleteResults') ->willReturn(13); - $this->c->expects($this->once()) - ->method('getConfig') - ->willReturn($config); - $config = [ 'oc_appconfig' => json_encode([ 'anotherapp' => [ |