diff options
author | Georg Ehrke <developer@georgehrke.com> | 2018-10-08 01:50:17 +0200 |
---|---|---|
committer | Georg Ehrke <developer@georgehrke.com> | 2018-10-08 01:50:17 +0200 |
commit | 970242b6ca79a0dbb1ac1a868c7b82c7aa49bd8a (patch) | |
tree | 0d7eee48a5f62670d008b174012ee5dc896f104e | |
parent | 1c6f666bbfc46b9092312c81f82a5e0cbe59fc18 (diff) | |
download | nextcloud-server-970242b6ca79a0dbb1ac1a868c7b82c7aa49bd8a.tar.gz nextcloud-server-970242b6ca79a0dbb1ac1a868c7b82c7aa49bd8a.zip |
RoomManager/ResourceManager: Inject IServerContainer instead of using OC Server
Signed-off-by: Georg Ehrke <developer@georgehrke.com>
-rw-r--r-- | lib/private/Calendar/Resource/Manager.php | 15 | ||||
-rw-r--r-- | lib/private/Calendar/Room/Manager.php | 15 | ||||
-rw-r--r-- | tests/lib/Calendar/Resource/ManagerTest.php | 49 | ||||
-rw-r--r-- | tests/lib/Calendar/Room/ManagerTest.php | 49 |
4 files changed, 88 insertions, 40 deletions
diff --git a/lib/private/Calendar/Resource/Manager.php b/lib/private/Calendar/Resource/Manager.php index 04ef69d69ea..224ca2a4390 100644 --- a/lib/private/Calendar/Resource/Manager.php +++ b/lib/private/Calendar/Resource/Manager.php @@ -24,9 +24,13 @@ namespace OC\Calendar\Resource; use OCP\Calendar\Resource\IBackend; +use OCP\IServerContainer; class Manager implements \OCP\Calendar\Resource\IManager { + /** @var IServerContainer */ + private $server; + /** @var string[] holds all registered resource backends */ private $backends = []; @@ -34,6 +38,15 @@ class Manager implements \OCP\Calendar\Resource\IManager { private $initializedBackends = []; /** + * Manager constructor. + * + * @param IServerContainer $server + */ + public function __construct(IServerContainer $server) { + $this->server = $server; + } + + /** * Registers a resource backend * * @param string $backendClass @@ -66,7 +79,7 @@ class Manager implements \OCP\Calendar\Resource\IManager { continue; } - $this->initializedBackends[$backend] = \OC::$server->query($backend); + $this->initializedBackends[$backend] = $this->server->query($backend); } return array_values($this->initializedBackends); diff --git a/lib/private/Calendar/Room/Manager.php b/lib/private/Calendar/Room/Manager.php index 8664149549d..d73b52cfb16 100644 --- a/lib/private/Calendar/Room/Manager.php +++ b/lib/private/Calendar/Room/Manager.php @@ -24,9 +24,13 @@ namespace OC\Calendar\Room; use OCP\Calendar\Room\IBackend; +use OCP\IServerContainer; class Manager implements \OCP\Calendar\Room\IManager { + /** @var IServerContainer */ + private $server; + /** @var string[] holds all registered resource backends */ private $backends = []; @@ -34,6 +38,15 @@ class Manager implements \OCP\Calendar\Room\IManager { private $initializedBackends = []; /** + * Manager constructor. + * + * @param IServerContainer $server + */ + public function __construct(IServerContainer $server) { + $this->server = $server; + } + + /** * Registers a resource backend * * @param string $backendClass @@ -66,7 +79,7 @@ class Manager implements \OCP\Calendar\Room\IManager { continue; } - $this->initializedBackends[$backend] = \OC::$server->query($backend); + $this->initializedBackends[$backend] = $this->server->query($backend); } return array_values($this->initializedBackends); diff --git a/tests/lib/Calendar/Resource/ManagerTest.php b/tests/lib/Calendar/Resource/ManagerTest.php index fb1c1435d0f..1d9229856db 100644 --- a/tests/lib/Calendar/Resource/ManagerTest.php +++ b/tests/lib/Calendar/Resource/ManagerTest.php @@ -25,6 +25,7 @@ namespace Test\Calendar\Resource; use \OC\Calendar\Resource\Manager; use \OCP\Calendar\Resource\IBackend; +use OCP\IServerContainer; use \Test\TestCase; class ManagerTest extends TestCase { @@ -32,24 +33,30 @@ class ManagerTest extends TestCase { /** @var Manager */ private $manager; + /** @var IServerContainer */ + private $server; + protected function setUp() { parent::setUp(); - $this->manager = new Manager(); + $this->server = $this->createMock(IServerContainer::class); + $this->manager = new Manager($this->server); } public function testRegisterUnregisterBackend() { $backend1 = $this->createMock(IBackend::class); $backend1->method('getBackendIdentifier')->will($this->returnValue('backend_1')); - \OC::$server->registerService('calendar_resource_backend1', function () use ($backend1) { - return $backend1; - }); + $this->server->expects($this->at(0)) + ->method('query') + ->with('calendar_resource_backend1') + ->will($this->returnValue($backend1)); $backend2 = $this->createMock(IBackend::class); $backend2->method('getBackendIdentifier')->will($this->returnValue('backend_2')); - \OC::$server->registerService('calendar_resource_backend2', function () use ($backend2) { - return $backend2; - }); + $this->server->expects($this->at(1)) + ->method('query') + ->with('calendar_resource_backend2') + ->will($this->returnValue($backend2)); $this->manager->registerBackend('calendar_resource_backend1'); $this->manager->registerBackend('calendar_resource_backend2'); @@ -68,15 +75,17 @@ class ManagerTest extends TestCase { public function testGetBackend() { $backend1 = $this->createMock(IBackend::class); $backend1->method('getBackendIdentifier')->will($this->returnValue('backend_1')); - \OC::$server->registerService('calendar_resource_backend1', function () use ($backend1) { - return $backend1; - }); + $this->server->expects($this->at(0)) + ->method('query') + ->with('calendar_resource_backend1') + ->will($this->returnValue($backend1)); $backend2 = $this->createMock(IBackend::class); $backend2->method('getBackendIdentifier')->will($this->returnValue('backend_2')); - \OC::$server->registerService('calendar_resource_backend2', function () use ($backend2) { - return $backend2; - }); + $this->server->expects($this->at(1)) + ->method('query') + ->with('calendar_resource_backend2') + ->will($this->returnValue($backend2)); $this->manager->registerBackend('calendar_resource_backend1'); $this->manager->registerBackend('calendar_resource_backend2'); @@ -88,15 +97,17 @@ class ManagerTest extends TestCase { public function testClear() { $backend1 = $this->createMock(IBackend::class); $backend1->method('getBackendIdentifier')->will($this->returnValue('backend_1')); - \OC::$server->registerService('calendar_resource_backend1', function () use ($backend1) { - return $backend1; - }); + $this->server->expects($this->at(0)) + ->method('query') + ->with('calendar_resource_backend1') + ->will($this->returnValue($backend1)); $backend2 = $this->createMock(IBackend::class); $backend2->method('getBackendIdentifier')->will($this->returnValue('backend_2')); - \OC::$server->registerService('calendar_resource_backend2', function () use ($backend2) { - return $backend2; - }); + $this->server->expects($this->at(1)) + ->method('query') + ->with('calendar_resource_backend2') + ->will($this->returnValue($backend2)); $this->manager->registerBackend('calendar_resource_backend1'); $this->manager->registerBackend('calendar_resource_backend2'); diff --git a/tests/lib/Calendar/Room/ManagerTest.php b/tests/lib/Calendar/Room/ManagerTest.php index eaa22f9930d..52347f439fa 100644 --- a/tests/lib/Calendar/Room/ManagerTest.php +++ b/tests/lib/Calendar/Room/ManagerTest.php @@ -25,6 +25,7 @@ namespace Test\Calendar\Room; use \OC\Calendar\Room\Manager; use \OCP\Calendar\Room\IBackend; +use OCP\IServerContainer; use \Test\TestCase; class ManagerTest extends TestCase { @@ -32,24 +33,30 @@ class ManagerTest extends TestCase { /** @var Manager */ private $manager; + /** @var IServerContainer */ + private $server; + protected function setUp() { parent::setUp(); - $this->manager = new Manager(); + $this->server = $this->createMock(IServerContainer::class); + $this->manager = new Manager($this->server); } public function testRegisterUnregisterBackend() { $backend1 = $this->createMock(IBackend::class); $backend1->method('getBackendIdentifier')->will($this->returnValue('backend_1')); - \OC::$server->registerService('calendar_room_backend1', function () use ($backend1) { - return $backend1; - }); + $this->server->expects($this->at(0)) + ->method('query') + ->with('calendar_room_backend1') + ->will($this->returnValue($backend1)); $backend2 = $this->createMock(IBackend::class); $backend2->method('getBackendIdentifier')->will($this->returnValue('backend_2')); - \OC::$server->registerService('calendar_room_backend2', function () use ($backend2) { - return $backend2; - }); + $this->server->expects($this->at(1)) + ->method('query') + ->with('calendar_room_backend2') + ->will($this->returnValue($backend2)); $this->manager->registerBackend('calendar_room_backend1'); $this->manager->registerBackend('calendar_room_backend2'); @@ -68,15 +75,17 @@ class ManagerTest extends TestCase { public function testGetBackend() { $backend1 = $this->createMock(IBackend::class); $backend1->method('getBackendIdentifier')->will($this->returnValue('backend_1')); - \OC::$server->registerService('calendar_room_backend1', function () use ($backend1) { - return $backend1; - }); + $this->server->expects($this->at(0)) + ->method('query') + ->with('calendar_room_backend1') + ->will($this->returnValue($backend1)); $backend2 = $this->createMock(IBackend::class); $backend2->method('getBackendIdentifier')->will($this->returnValue('backend_2')); - \OC::$server->registerService('calendar_room_backend2', function () use ($backend2) { - return $backend2; - }); + $this->server->expects($this->at(1)) + ->method('query') + ->with('calendar_room_backend2') + ->will($this->returnValue($backend2)); $this->manager->registerBackend('calendar_room_backend1'); $this->manager->registerBackend('calendar_room_backend2'); @@ -88,15 +97,17 @@ class ManagerTest extends TestCase { public function testClear() { $backend1 = $this->createMock(IBackend::class); $backend1->method('getBackendIdentifier')->will($this->returnValue('backend_1')); - \OC::$server->registerService('calendar_room_backend1', function () use ($backend1) { - return $backend1; - }); + $this->server->expects($this->at(0)) + ->method('query') + ->with('calendar_room_backend1') + ->will($this->returnValue($backend1)); $backend2 = $this->createMock(IBackend::class); $backend2->method('getBackendIdentifier')->will($this->returnValue('backend_2')); - \OC::$server->registerService('calendar_room_backend2', function () use ($backend2) { - return $backend2; - }); + $this->server->expects($this->at(1)) + ->method('query') + ->with('calendar_room_backend2') + ->will($this->returnValue($backend2)); $this->manager->registerBackend('calendar_room_backend1'); $this->manager->registerBackend('calendar_room_backend2'); |