From 91e7f12088cb87ffef5660429ece404364167978 Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Thu, 16 Jul 2020 17:08:03 +0200 Subject: Adjust apps' code to use the ContainerInterface Signed-off-by: Christoph Wurst --- apps/comments/lib/AppInfo/Application.php | 11 +++++++---- apps/comments/lib/JSSettingsHelper.php | 8 ++++---- apps/comments/tests/Unit/JSSettingsHelperTest.php | 16 +++++++--------- 3 files changed, 18 insertions(+), 17 deletions(-) (limited to 'apps/comments') 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 @@ * @@ -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' => [ -- cgit v1.2.3