From 1c6f666bbfc46b9092312c81f82a5e0cbe59fc18 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Fri, 24 Aug 2018 15:21:04 +0200 Subject: [PATCH 1/2] adjust Calendar resource / room interfaces to use class implementation Signed-off-by: Georg Ehrke --- ...ateCalendarResourcesRoomsBackgroundJob.php | 32 +++++++++++---- lib/private/Calendar/Resource/Manager.php | 41 +++++++++++++------ lib/private/Calendar/Room/Manager.php | 41 +++++++++++++------ lib/public/Calendar/Resource/IManager.php | 12 +++--- lib/public/Calendar/Room/IManager.php | 12 +++--- tests/lib/Calendar/Resource/ManagerTest.php | 32 +++++++++++---- tests/lib/Calendar/Room/ManagerTest.php | 32 +++++++++++---- 7 files changed, 144 insertions(+), 58 deletions(-) diff --git a/apps/dav/lib/BackgroundJob/UpdateCalendarResourcesRoomsBackgroundJob.php b/apps/dav/lib/BackgroundJob/UpdateCalendarResourcesRoomsBackgroundJob.php index c5f8f6586e..3a9e3def05 100644 --- a/apps/dav/lib/BackgroundJob/UpdateCalendarResourcesRoomsBackgroundJob.php +++ b/apps/dav/lib/BackgroundJob/UpdateCalendarResourcesRoomsBackgroundJob.php @@ -113,8 +113,12 @@ class UpdateCalendarResourcesRoomsBackgroundJob extends TimedJob { foreach($sortedResources['new'] as $backendId => $newResources) { foreach ($newResources as $newResource) { - $resource = $this->resourceManager->getBackend($backendId) - ->getResource($newResource); + $backend = $this->resourceManager->getBackend($backendId); + if ($backend === null) { + continue; + } + + $resource = $backend->getResource($newResource); $this->addToCache($this->resourceDbTable, $resource); } } @@ -126,8 +130,12 @@ class UpdateCalendarResourcesRoomsBackgroundJob extends TimedJob { } foreach($sortedResources['edited'] as $backendId => $editedResources) { foreach ($editedResources as $editedResource) { - $resource = $this->resourceManager->getBackend($backendId) - ->getResource($editedResource); + $backend = $this->resourceManager->getBackend($backendId); + if ($backend === null) { + continue; + } + + $resource = $backend->getResource($editedResource); $this->updateCache($this->resourceDbTable, $resource); } } @@ -157,8 +165,12 @@ class UpdateCalendarResourcesRoomsBackgroundJob extends TimedJob { foreach($sortedRooms['new'] as $backendId => $newRooms) { foreach ($newRooms as $newRoom) { - $resource = $this->roomManager->getBackend($backendId) - ->getRoom($newRoom); + $backend = $this->roomManager->getBackend($backendId); + if ($backend === null) { + continue; + } + + $resource = $backend->getRoom($newRoom); $this->addToCache($this->roomDbTable, $resource); } } @@ -170,8 +182,12 @@ class UpdateCalendarResourcesRoomsBackgroundJob extends TimedJob { } foreach($sortedRooms['edited'] as $backendId => $editedRooms) { foreach ($editedRooms as $editedRoom) { - $resource = $this->roomManager->getBackend($backendId) - ->getRoom($editedRoom); + $backend = $this->roomManager->getBackend($backendId); + if ($backend === null) { + continue; + } + + $resource = $backend->getRoom($editedRoom); $this->updateCache($this->roomDbTable, $resource); } } diff --git a/lib/private/Calendar/Resource/Manager.php b/lib/private/Calendar/Resource/Manager.php index baa8117e85..04ef69d69e 100644 --- a/lib/private/Calendar/Resource/Manager.php +++ b/lib/private/Calendar/Resource/Manager.php @@ -27,49 +27,65 @@ use OCP\Calendar\Resource\IBackend; class Manager implements \OCP\Calendar\Resource\IManager { - /** @var IBackend[] holds all registered resource backends */ + /** @var string[] holds all registered resource backends */ private $backends = []; + /** @var IBackend[] holds all backends that have been initialized already */ + private $initializedBackends = []; + /** * Registers a resource backend * - * @param IBackend $backend + * @param string $backendClass * @return void * @since 14.0.0 */ - public function registerBackend(IBackend $backend) { - $this->backends[$backend->getBackendIdentifier()] = $backend; + public function registerBackend(string $backendClass) { + $this->backends[$backendClass] = $backendClass; } /** * Unregisters a resource backend * - * @param IBackend $backend + * @param string $backendClass * @return void * @since 14.0.0 */ - public function unregisterBackend(IBackend $backend) { - unset($this->backends[$backend->getBackendIdentifier()]); + public function unregisterBackend(string $backendClass) { + unset($this->backends[$backendClass], $this->initializedBackends[$backendClass]); } /** * @return IBackend[] + * @throws \OCP\AppFramework\QueryException * @since 14.0.0 */ public function getBackends():array { - return array_values($this->backends); + foreach($this->backends as $backend) { + if (isset($this->initializedBackends[$backend])) { + continue; + } + + $this->initializedBackends[$backend] = \OC::$server->query($backend); + } + + return array_values($this->initializedBackends); } /** * @param string $backendId + * @throws \OCP\AppFramework\QueryException * @return IBackend|null */ - public function getBackend($backendId):IBackend { - if (!isset($this->backends[$backendId])) { - return null; + public function getBackend($backendId) { + $backends = $this->getBackends(); + foreach($backends as $backend) { + if ($backend->getBackendIdentifier() === $backendId) { + return $backend; + } } - return $this->backends[$backendId]; + return null; } /** @@ -79,5 +95,6 @@ class Manager implements \OCP\Calendar\Resource\IManager { */ public function clear() { $this->backends = []; + $this->initializedBackends = []; } } diff --git a/lib/private/Calendar/Room/Manager.php b/lib/private/Calendar/Room/Manager.php index aef9f2ed32..8664149549 100644 --- a/lib/private/Calendar/Room/Manager.php +++ b/lib/private/Calendar/Room/Manager.php @@ -27,49 +27,65 @@ use OCP\Calendar\Room\IBackend; class Manager implements \OCP\Calendar\Room\IManager { - /** @var IBackend[] holds all registered resource backends */ + /** @var string[] holds all registered resource backends */ private $backends = []; + /** @var IBackend[] holds all backends that have been initialized already */ + private $initializedBackends = []; + /** * Registers a resource backend * - * @param IBackend $backend + * @param string $backendClass * @return void * @since 14.0.0 */ - public function registerBackend(IBackend $backend) { - $this->backends[$backend->getBackendIdentifier()] = $backend; + public function registerBackend(string $backendClass) { + $this->backends[$backendClass] = $backendClass; } /** * Unregisters a resource backend * - * @param IBackend $backend + * @param string $backendClass * @return void * @since 14.0.0 */ - public function unregisterBackend(IBackend $backend) { - unset($this->backends[$backend->getBackendIdentifier()]); + public function unregisterBackend(string $backendClass) { + unset($this->backends[$backendClass], $this->initializedBackends[$backendClass]); } /** * @return IBackend[] + * @throws \OCP\AppFramework\QueryException * @since 14.0.0 */ public function getBackends():array { - return array_values($this->backends); + foreach($this->backends as $backend) { + if (isset($this->initializedBackends[$backend])) { + continue; + } + + $this->initializedBackends[$backend] = \OC::$server->query($backend); + } + + return array_values($this->initializedBackends); } /** * @param string $backendId + * @throws \OCP\AppFramework\QueryException * @return IBackend|null */ - public function getBackend($backendId):IBackend { - if (!isset($this->backends[$backendId])) { - return null; + public function getBackend($backendId) { + $backends = $this->getBackends(); + foreach($backends as $backend) { + if ($backend->getBackendIdentifier() === $backendId) { + return $backend; + } } - return $this->backends[$backendId]; + return null; } /** @@ -79,5 +95,6 @@ class Manager implements \OCP\Calendar\Room\IManager { */ public function clear() { $this->backends = []; + $this->initializedBackends = []; } } diff --git a/lib/public/Calendar/Resource/IManager.php b/lib/public/Calendar/Resource/IManager.php index 8542e13eba..b59cb6c797 100644 --- a/lib/public/Calendar/Resource/IManager.php +++ b/lib/public/Calendar/Resource/IManager.php @@ -34,20 +34,20 @@ interface IManager { /** * Registers a resource backend * - * @param IBackend $backend + * @param string $backendClass * @return void * @since 14.0.0 */ - public function registerBackend(IBackend $backend); + public function registerBackend(string $backendClass); /** * Unregisters a resource backend * - * @param IBackend $backend + * @param string $backendClass * @return void * @since 14.0.0 */ - public function unregisterBackend(IBackend $backend); + public function unregisterBackend(string $backendClass); /** * @return IBackend[] @@ -57,10 +57,10 @@ interface IManager { /** * @param string $backendId - * @return IBackend + * @return IBackend|null * @since 14.0.0 */ - public function getBackend($backendId):IBackend; + public function getBackend($backendId); /** * removes all registered backend instances diff --git a/lib/public/Calendar/Room/IManager.php b/lib/public/Calendar/Room/IManager.php index 39e85c43e4..9aa61aa3f6 100644 --- a/lib/public/Calendar/Room/IManager.php +++ b/lib/public/Calendar/Room/IManager.php @@ -34,20 +34,20 @@ interface IManager { /** * Registers a room backend * - * @param IBackend $backend + * @param string $backendClass * @return void * @since 14.0.0 */ - public function registerBackend(IBackend $backend); + public function registerBackend(string $backendClass); /** * Unregisters a room backend * - * @param IBackend $backend + * @param string $backendClass * @return void * @since 14.0.0 */ - public function unregisterBackend(IBackend $backend); + public function unregisterBackend(string $backendClass); /** * @return IBackend[] @@ -57,10 +57,10 @@ interface IManager { /** * @param string $backendId - * @return IBackend + * @return IBackend|null * @since 14.0.0 */ - public function getBackend($backendId):IBackend; + public function getBackend($backendId); /** * removes all registered backend instances diff --git a/tests/lib/Calendar/Resource/ManagerTest.php b/tests/lib/Calendar/Resource/ManagerTest.php index ccc6bbf182..fb1c1435d0 100644 --- a/tests/lib/Calendar/Resource/ManagerTest.php +++ b/tests/lib/Calendar/Resource/ManagerTest.php @@ -41,18 +41,24 @@ class ManagerTest extends TestCase { 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; + }); $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->manager->registerBackend($backend1); - $this->manager->registerBackend($backend2); + $this->manager->registerBackend('calendar_resource_backend1'); + $this->manager->registerBackend('calendar_resource_backend2'); $this->assertEquals([ $backend1, $backend2 ], $this->manager->getBackends()); - $this->manager->unregisterBackend($backend1); + $this->manager->unregisterBackend('calendar_resource_backend1'); $this->assertEquals([ $backend2 @@ -62,12 +68,18 @@ 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; + }); $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->manager->registerBackend($backend1); - $this->manager->registerBackend($backend2); + $this->manager->registerBackend('calendar_resource_backend1'); + $this->manager->registerBackend('calendar_resource_backend2'); $this->assertEquals($backend1, $this->manager->getBackend('backend_1')); $this->assertEquals($backend2, $this->manager->getBackend('backend_2')); @@ -76,12 +88,18 @@ 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; + }); $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->manager->registerBackend($backend1); - $this->manager->registerBackend($backend2); + $this->manager->registerBackend('calendar_resource_backend1'); + $this->manager->registerBackend('calendar_resource_backend2'); $this->assertEquals([ $backend1, $backend2 diff --git a/tests/lib/Calendar/Room/ManagerTest.php b/tests/lib/Calendar/Room/ManagerTest.php index 34d69d127e..eaa22f9930 100644 --- a/tests/lib/Calendar/Room/ManagerTest.php +++ b/tests/lib/Calendar/Room/ManagerTest.php @@ -41,18 +41,24 @@ class ManagerTest extends TestCase { 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; + }); $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->manager->registerBackend($backend1); - $this->manager->registerBackend($backend2); + $this->manager->registerBackend('calendar_room_backend1'); + $this->manager->registerBackend('calendar_room_backend2'); $this->assertEquals([ $backend1, $backend2 ], $this->manager->getBackends()); - $this->manager->unregisterBackend($backend1); + $this->manager->unregisterBackend('calendar_room_backend1'); $this->assertEquals([ $backend2 @@ -62,12 +68,18 @@ 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; + }); $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->manager->registerBackend($backend1); - $this->manager->registerBackend($backend2); + $this->manager->registerBackend('calendar_room_backend1'); + $this->manager->registerBackend('calendar_room_backend2'); $this->assertEquals($backend1, $this->manager->getBackend('backend_1')); $this->assertEquals($backend2, $this->manager->getBackend('backend_2')); @@ -76,12 +88,18 @@ 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; + }); $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->manager->registerBackend($backend1); - $this->manager->registerBackend($backend2); + $this->manager->registerBackend('calendar_room_backend1'); + $this->manager->registerBackend('calendar_room_backend2'); $this->assertEquals([ $backend1, $backend2 From 970242b6ca79a0dbb1ac1a868c7b82c7aa49bd8a Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Mon, 8 Oct 2018 01:50:17 +0200 Subject: [PATCH 2/2] RoomManager/ResourceManager: Inject IServerContainer instead of using OC Server Signed-off-by: Georg Ehrke --- lib/private/Calendar/Resource/Manager.php | 15 ++++++- lib/private/Calendar/Room/Manager.php | 15 ++++++- tests/lib/Calendar/Resource/ManagerTest.php | 49 +++++++++++++-------- 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 04ef69d69e..224ca2a439 100644 --- a/lib/private/Calendar/Resource/Manager.php +++ b/lib/private/Calendar/Resource/Manager.php @@ -24,15 +24,28 @@ 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 = []; /** @var IBackend[] holds all backends that have been initialized already */ private $initializedBackends = []; + /** + * Manager constructor. + * + * @param IServerContainer $server + */ + public function __construct(IServerContainer $server) { + $this->server = $server; + } + /** * Registers a resource backend * @@ -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 8664149549..d73b52cfb1 100644 --- a/lib/private/Calendar/Room/Manager.php +++ b/lib/private/Calendar/Room/Manager.php @@ -24,15 +24,28 @@ 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 = []; /** @var IBackend[] holds all backends that have been initialized already */ private $initializedBackends = []; + /** + * Manager constructor. + * + * @param IServerContainer $server + */ + public function __construct(IServerContainer $server) { + $this->server = $server; + } + /** * Registers a resource backend * @@ -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 fb1c1435d0..1d9229856d 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 eaa22f9930..52347f439f 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');