aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph Wurst <ChristophWurst@users.noreply.github.com>2022-02-09 10:25:03 +0100
committerGitHub <noreply@github.com>2022-02-09 10:25:03 +0100
commitcd7a217c29a38a778aea54827dcecccd254e6f20 (patch)
treef84baaec393b30daa2199a5b2c6fd2b220ec6415
parentf4c719734a1939b846929a9a8303b26f5b7a3ed6 (diff)
parent9a656e5b35d004b55fbe09d10d51254a8ec4fd67 (diff)
downloadnextcloud-server-cd7a217c29a38a778aea54827dcecccd254e6f20.tar.gz
nextcloud-server-cd7a217c29a38a778aea54827dcecccd254e6f20.zip
Merge pull request #31007 from nextcloud/enhancement/bootstrap-calendar-resource-room-backend-registration
Move calendar resource/room backend registration to IBootstrap
-rw-r--r--lib/private/AppFramework/Bootstrap/RegistrationContext.php52
-rw-r--r--lib/private/Calendar/Resource/Manager.php45
-rw-r--r--lib/private/Calendar/Room/Manager.php55
-rw-r--r--lib/public/AppFramework/Bootstrap/IRegistrationContext.php20
-rw-r--r--lib/public/Calendar/Resource/IManager.php11
-rw-r--r--lib/public/Calendar/Room/IManager.php11
-rw-r--r--tests/lib/Calendar/Resource/ManagerTest.php102
-rw-r--r--tests/lib/Calendar/Room/ManagerTest.php100
8 files changed, 294 insertions, 102 deletions
diff --git a/lib/private/AppFramework/Bootstrap/RegistrationContext.php b/lib/private/AppFramework/Bootstrap/RegistrationContext.php
index 401a967c988..b40d3356d1a 100644
--- a/lib/private/AppFramework/Bootstrap/RegistrationContext.php
+++ b/lib/private/AppFramework/Bootstrap/RegistrationContext.php
@@ -30,6 +30,8 @@ declare(strict_types=1);
namespace OC\AppFramework\Bootstrap;
use Closure;
+use OCP\Calendar\Resource\IBackend as IResourceBackend;
+use OCP\Calendar\Room\IBackend as IRoomBackend;
use OCP\Talk\ITalkBackend;
use RuntimeException;
use function array_shift;
@@ -70,6 +72,12 @@ class RegistrationContext {
/** @var null|ServiceRegistration<ITalkBackend> */
private $talkBackendRegistration = null;
+ /** @var ServiceRegistration<IResourceBackend>[] */
+ private $calendarResourceBackendRegistrations = [];
+
+ /** @var ServiceRegistration<IRoomBackend>[] */
+ private $calendarRoomBackendRegistrations = [];
+
/** @var ServiceFactoryRegistration[] */
private $services = [];
@@ -271,6 +279,20 @@ class RegistrationContext {
$backend
);
}
+
+ public function registerCalendarResourceBackend(string $class): void {
+ $this->context->registerCalendarResourceBackend(
+ $this->appId,
+ $class
+ );
+ }
+
+ public function registerCalendarRoomBackend(string $class): void {
+ $this->context->registerCalendarRoomBackend(
+ $this->appId,
+ $class
+ );
+ }
};
}
@@ -376,6 +398,20 @@ class RegistrationContext {
$this->talkBackendRegistration = new ServiceRegistration($appId, $backend);
}
+ public function registerCalendarResourceBackend(string $appId, string $class) {
+ $this->calendarResourceBackendRegistrations[] = new ServiceRegistration(
+ $appId,
+ $class,
+ );
+ }
+
+ public function registerCalendarRoomBackend(string $appId, string $class) {
+ $this->calendarRoomBackendRegistrations[] = new ServiceRegistration(
+ $appId,
+ $class,
+ );
+ }
+
/**
* @param App[] $apps
*/
@@ -635,4 +671,20 @@ class RegistrationContext {
public function getTalkBackendRegistration(): ?ServiceRegistration {
return $this->talkBackendRegistration;
}
+
+ /**
+ * @return ServiceRegistration[]
+ * @psalm-return ServiceRegistration<IResourceBackend>[]
+ */
+ public function getCalendarResourceBackendRegistrations(): array {
+ return $this->calendarResourceBackendRegistrations;
+ }
+
+ /**
+ * @return ServiceRegistration[]
+ * @psalm-return ServiceRegistration<IRoomBackend>[]
+ */
+ public function getCalendarRoomBackendRegistrations(): array {
+ return $this->calendarRoomBackendRegistrations;
+ }
}
diff --git a/lib/private/Calendar/Resource/Manager.php b/lib/private/Calendar/Resource/Manager.php
index 935541d9c87..ebde4ac5eb5 100644
--- a/lib/private/Calendar/Resource/Manager.php
+++ b/lib/private/Calendar/Resource/Manager.php
@@ -1,4 +1,7 @@
<?php
+
+declare(strict_types=1);
+
/**
* @copyright 2018, Georg Ehrke <oc.list@georgehrke.com>
*
@@ -24,26 +27,30 @@
*/
namespace OC\Calendar\Resource;
+use OC\AppFramework\Bootstrap\Coordinator;
use OCP\Calendar\Resource\IBackend;
+use OCP\Calendar\Resource\IManager;
use OCP\IServerContainer;
-class Manager implements \OCP\Calendar\Resource\IManager {
+class Manager implements IManager {
+ private Coordinator $bootstrapCoordinator;
- /** @var IServerContainer */
- private $server;
+ private IServerContainer $server;
- /** @var string[] holds all registered resource backends */
+ private bool $bootstrapBackendsLoaded = false;
+
+ /**
+ * @var string[] holds all registered resource backends
+ * @psalm-var class-string<IBackend>[]
+ */
private $backends = [];
/** @var IBackend[] holds all backends that have been initialized already */
private $initializedBackends = [];
- /**
- * Manager constructor.
- *
- * @param IServerContainer $server
- */
- public function __construct(IServerContainer $server) {
+ public function __construct(Coordinator $bootstrapCoordinator,
+ IServerContainer $server) {
+ $this->bootstrapCoordinator = $bootstrapCoordinator;
$this->server = $server;
}
@@ -69,12 +76,30 @@ class Manager implements \OCP\Calendar\Resource\IManager {
unset($this->backends[$backendClass], $this->initializedBackends[$backendClass]);
}
+ private function fetchBootstrapBackends(): void {
+ if ($this->bootstrapBackendsLoaded) {
+ return;
+ }
+
+ $context = $this->bootstrapCoordinator->getRegistrationContext();
+ if ($context === null) {
+ // Too soon
+ return;
+ }
+
+ foreach ($context->getCalendarResourceBackendRegistrations() as $registration) {
+ $this->backends[] = $registration->getService();
+ }
+ }
+
/**
* @return IBackend[]
* @throws \OCP\AppFramework\QueryException
* @since 14.0.0
*/
public function getBackends():array {
+ $this->fetchBootstrapBackends();
+
foreach ($this->backends as $backend) {
if (isset($this->initializedBackends[$backend])) {
continue;
diff --git a/lib/private/Calendar/Room/Manager.php b/lib/private/Calendar/Room/Manager.php
index 25db5197ef2..7e6af2823a3 100644
--- a/lib/private/Calendar/Room/Manager.php
+++ b/lib/private/Calendar/Room/Manager.php
@@ -1,4 +1,7 @@
<?php
+
+declare(strict_types=1);
+
/**
* @copyright 2018, Georg Ehrke <oc.list@georgehrke.com>
*
@@ -24,26 +27,30 @@
*/
namespace OC\Calendar\Room;
+use OC\AppFramework\Bootstrap\Coordinator;
use OCP\Calendar\Room\IBackend;
+use OCP\Calendar\Room\IManager;
use OCP\IServerContainer;
-class Manager implements \OCP\Calendar\Room\IManager {
+class Manager implements IManager {
+ private Coordinator $bootstrapCoordinator;
- /** @var IServerContainer */
- private $server;
+ private IServerContainer $server;
- /** @var string[] holds all registered resource backends */
- private $backends = [];
-
- /** @var IBackend[] holds all backends that have been initialized already */
- private $initializedBackends = [];
+ private bool $bootstrapBackendsLoaded = false;
/**
- * Manager constructor.
- *
- * @param IServerContainer $server
+ * @var string[] holds all registered resource backends
+ * @psalm-var class-string<IBackend>[]
*/
- public function __construct(IServerContainer $server) {
+ private array $backends = [];
+
+ /** @var IBackend[] holds all backends that have been initialized already */
+ private array $initializedBackends = [];
+
+ public function __construct(Coordinator $bootstrapCoordinator,
+ IServerContainer $server) {
+ $this->bootstrapCoordinator = $bootstrapCoordinator;
$this->server = $server;
}
@@ -69,17 +76,41 @@ class Manager implements \OCP\Calendar\Room\IManager {
unset($this->backends[$backendClass], $this->initializedBackends[$backendClass]);
}
+ private function fetchBootstrapBackends(): void {
+ if ($this->bootstrapBackendsLoaded) {
+ return;
+ }
+
+ $context = $this->bootstrapCoordinator->getRegistrationContext();
+ if ($context === null) {
+ // Too soon
+ return;
+ }
+
+ foreach ($context->getCalendarRoomBackendRegistrations() as $registration) {
+ $this->backends[] = $registration->getService();
+ }
+ }
+
/**
* @return IBackend[]
* @throws \OCP\AppFramework\QueryException
* @since 14.0.0
*/
public function getBackends():array {
+ $this->fetchBootstrapBackends();
+
foreach ($this->backends as $backend) {
if (isset($this->initializedBackends[$backend])) {
continue;
}
+ /**
+ * @todo fetch from the app container
+ *
+ * The backend might have services injected that can't be build from the
+ * server container.
+ */
$this->initializedBackends[$backend] = $this->server->query($backend);
}
diff --git a/lib/public/AppFramework/Bootstrap/IRegistrationContext.php b/lib/public/AppFramework/Bootstrap/IRegistrationContext.php
index 19b5665f547..89583912e00 100644
--- a/lib/public/AppFramework/Bootstrap/IRegistrationContext.php
+++ b/lib/public/AppFramework/Bootstrap/IRegistrationContext.php
@@ -275,4 +275,24 @@ interface IRegistrationContext {
* @since 24.0.0
*/
public function registerTalkBackend(string $backend): void;
+
+ /**
+ * Register a resource backend for the DAV server
+ *
+ * @param string $actionClass
+ * @psalm-param class-string<\OCP\Calendar\Resource\IBackend> $actionClass
+ * @return void
+ * @since 24.0.0
+ */
+ public function registerCalendarResourceBackend(string $class): void;
+
+ /**
+ * Register a room backend for the DAV server
+ *
+ * @param string $actionClass
+ * @psalm-param class-string<\OCP\Calendar\Room\IBackend> $actionClass
+ * @return void
+ * @since 24.0.0
+ */
+ public function registerCalendarRoomBackend(string $class): void;
}
diff --git a/lib/public/Calendar/Resource/IManager.php b/lib/public/Calendar/Resource/IManager.php
index 6910ecb164c..268cf8ec633 100644
--- a/lib/public/Calendar/Resource/IManager.php
+++ b/lib/public/Calendar/Resource/IManager.php
@@ -1,4 +1,7 @@
<?php
+
+declare(strict_types=1);
+
/**
* @copyright 2018, Georg Ehrke <oc.list@georgehrke.com>
*
@@ -23,9 +26,8 @@
namespace OCP\Calendar\Resource;
/**
- * Interface IManager
- *
* @since 14.0.0
+ * @deprecated 24.0.0
*/
interface IManager {
@@ -35,6 +37,7 @@ interface IManager {
* @param string $backendClass
* @return void
* @since 14.0.0
+ * @deprecated 24.0.0 use \OCP\AppFramework\Bootstrap\IRegistrationContext::registerCalendarResourceBackend
*/
public function registerBackend(string $backendClass);
@@ -44,12 +47,14 @@ interface IManager {
* @param string $backendClass
* @return void
* @since 14.0.0
+ * @deprecated 24.0.0
*/
public function unregisterBackend(string $backendClass);
/**
* @return IBackend[]
* @since 14.0.0
+ * @deprecated 24.0.0
*/
public function getBackends():array;
@@ -57,6 +62,7 @@ interface IManager {
* @param string $backendId
* @return IBackend|null
* @since 14.0.0
+ * @deprecated 24.0.0
*/
public function getBackend($backendId);
@@ -64,6 +70,7 @@ interface IManager {
* removes all registered backend instances
* @return void
* @since 14.0.0
+ * @deprecated 24.0.0
*/
public function clear();
}
diff --git a/lib/public/Calendar/Room/IManager.php b/lib/public/Calendar/Room/IManager.php
index 6529ad265b6..c55f3fd4ae4 100644
--- a/lib/public/Calendar/Room/IManager.php
+++ b/lib/public/Calendar/Room/IManager.php
@@ -1,4 +1,7 @@
<?php
+
+declare(strict_types=1);
+
/**
* @copyright 2018, Georg Ehrke <oc.list@georgehrke.com>
*
@@ -23,9 +26,8 @@
namespace OCP\Calendar\Room;
/**
- * Interface IManager
- *
* @since 14.0.0
+ * @deprecated 24.0.0
*/
interface IManager {
@@ -35,6 +37,7 @@ interface IManager {
* @param string $backendClass
* @return void
* @since 14.0.0
+ * @deprecated 24.0.0 use \OC\AppFramework\Bootstrap\::registerCalendarRoomBackend
*/
public function registerBackend(string $backendClass);
@@ -44,12 +47,14 @@ interface IManager {
* @param string $backendClass
* @return void
* @since 14.0.0
+ * @deprecated 24.0.0
*/
public function unregisterBackend(string $backendClass);
/**
* @return IBackend[]
* @since 14.0.0
+ * @deprecated 24.0.0
*/
public function getBackends():array;
@@ -57,6 +62,7 @@ interface IManager {
* @param string $backendId
* @return IBackend|null
* @since 14.0.0
+ * @deprecated 24.0.0
*/
public function getBackend($backendId);
@@ -64,6 +70,7 @@ interface IManager {
* removes all registered backend instances
* @return void
* @since 14.0.0
+ * @deprecated 24.0.0
*/
public function clear();
}
diff --git a/tests/lib/Calendar/Resource/ManagerTest.php b/tests/lib/Calendar/Resource/ManagerTest.php
index 30b0e16c948..8753f547fb2 100644
--- a/tests/lib/Calendar/Resource/ManagerTest.php
+++ b/tests/lib/Calendar/Resource/ManagerTest.php
@@ -1,4 +1,7 @@
<?php
+
+declare(strict_types=1);
+
/**
* @copyright 2018, Georg Ehrke <oc.list@georgehrke.com>
*
@@ -23,101 +26,122 @@
namespace Test\Calendar\Resource;
+use OC\AppFramework\Bootstrap\Coordinator;
+use OC\AppFramework\Bootstrap\RegistrationContext;
+use OC\AppFramework\Bootstrap\ServiceRegistration;
use OC\Calendar\Resource\Manager;
use OCP\Calendar\Resource\IBackend;
use OCP\IServerContainer;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class ManagerTest extends TestCase {
- /** @var Manager */
- private $manager;
+ /** @var Coordinator|MockObject */
+ private $coordinator;
- /** @var IServerContainer */
+ /** @var IServerContainer|MockObject */
private $server;
+ /** @var Manager */
+ private $manager;
+
protected function setUp(): void {
parent::setUp();
+ $this->coordinator = $this->createMock(Coordinator::class);
$this->server = $this->createMock(IServerContainer::class);
- $this->manager = new Manager($this->server);
+ $this->manager = new Manager(
+ $this->coordinator,
+ $this->server,
+ );
}
- public function testRegisterUnregisterBackend() {
+ public function testRegisterUnregisterBackend(): void {
$backend1 = $this->createMock(IBackend::class);
$backend1->method('getBackendIdentifier')->willReturn('backend_1');
- $this->server->expects($this->at(0))
- ->method('query')
- ->with('calendar_resource_backend1')
- ->willReturn($backend1);
-
$backend2 = $this->createMock(IBackend::class);
$backend2->method('getBackendIdentifier')->willReturn('backend_2');
- $this->server->expects($this->at(1))
+ $this->server->expects(self::exactly(2))
->method('query')
- ->with('calendar_resource_backend2')
- ->willReturn($backend2);
+ ->willReturnMap([
+ ['calendar_resource_backend1', true, $backend1,],
+ ['calendar_resource_backend2', true, $backend2,],
+ ]);
$this->manager->registerBackend('calendar_resource_backend1');
$this->manager->registerBackend('calendar_resource_backend2');
- $this->assertEquals([
+ self::assertEquals([
$backend1, $backend2
], $this->manager->getBackends());
-
$this->manager->unregisterBackend('calendar_resource_backend1');
-
- $this->assertEquals([
+ self::assertEquals([
$backend2
], $this->manager->getBackends());
}
- public function testGetBackend() {
- $backend1 = $this->createMock(IBackend::class);
- $backend1->method('getBackendIdentifier')->willReturn('backend_1');
- $this->server->expects($this->at(0))
+ public function testGetBackendFromBootstrapRegistration(): void {
+ $backendClass = '\\OCA\\CalendarResourceFoo\\Backend';
+ $backend = $this->createMock(IBackend::class);
+ $backend->method('getBackendIdentifier')->willReturn('from_bootstrap');
+ $context = $this->createMock(RegistrationContext::class);
+ $this->coordinator->expects(self::once())
+ ->method('getRegistrationContext')
+ ->willReturn($context);
+ $context->expects(self::once())
+ ->method('getCalendarResourceBackendRegistrations')
+ ->willReturn([
+ new ServiceRegistration('calendar_resource_foo', $backendClass)
+ ]);
+ $this->server->expects(self::once())
->method('query')
- ->with('calendar_resource_backend1')
- ->willReturn($backend1);
+ ->with($backendClass)
+ ->willReturn($backend);
+
+ self::assertEquals($backend, $this->manager->getBackend('from_bootstrap'));
+ }
+ public function testGetBackend(): void {
+ $backend1 = $this->createMock(IBackend::class);
+ $backend1->method('getBackendIdentifier')->willReturn('backend_1');
$backend2 = $this->createMock(IBackend::class);
$backend2->method('getBackendIdentifier')->willReturn('backend_2');
- $this->server->expects($this->at(1))
+ $this->server->expects(self::exactly(2))
->method('query')
- ->with('calendar_resource_backend2')
- ->willReturn($backend2);
+ ->willReturnMap([
+ ['calendar_resource_backend1', true, $backend1,],
+ ['calendar_resource_backend2', true, $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'));
+ self::assertEquals($backend1, $this->manager->getBackend('backend_1'));
+ self::assertEquals($backend2, $this->manager->getBackend('backend_2'));
}
- public function testClear() {
+ public function testClear(): void {
$backend1 = $this->createMock(IBackend::class);
$backend1->method('getBackendIdentifier')->willReturn('backend_1');
- $this->server->expects($this->at(0))
- ->method('query')
- ->with('calendar_resource_backend1')
- ->willReturn($backend1);
-
$backend2 = $this->createMock(IBackend::class);
$backend2->method('getBackendIdentifier')->willReturn('backend_2');
- $this->server->expects($this->at(1))
+ $this->server->expects(self::exactly(2))
->method('query')
- ->with('calendar_resource_backend2')
- ->willReturn($backend2);
+ ->willReturnMap([
+ ['calendar_resource_backend1', true, $backend1,],
+ ['calendar_resource_backend2', true, $backend2,],
+ ]);
$this->manager->registerBackend('calendar_resource_backend1');
$this->manager->registerBackend('calendar_resource_backend2');
- $this->assertEquals([
+ self::assertEquals([
$backend1, $backend2
], $this->manager->getBackends());
$this->manager->clear();
- $this->assertEquals([], $this->manager->getBackends());
+ self::assertEquals([], $this->manager->getBackends());
}
}
diff --git a/tests/lib/Calendar/Room/ManagerTest.php b/tests/lib/Calendar/Room/ManagerTest.php
index b01d16945ad..598415246dc 100644
--- a/tests/lib/Calendar/Room/ManagerTest.php
+++ b/tests/lib/Calendar/Room/ManagerTest.php
@@ -1,4 +1,7 @@
<?php
+
+declare(strict_types=1);
+
/**
* @copyright 2018, Georg Ehrke <oc.list@georgehrke.com>
*
@@ -23,101 +26,124 @@
namespace Test\Calendar\Room;
+use OC\AppFramework\Bootstrap\Coordinator;
+use OC\AppFramework\Bootstrap\RegistrationContext;
+use OC\AppFramework\Bootstrap\ServiceRegistration;
use OC\Calendar\Room\Manager;
use OCP\Calendar\Room\IBackend;
use OCP\IServerContainer;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class ManagerTest extends TestCase {
- /** @var Manager */
- private $manager;
+ /** @var Coordinator|MockObject */
+ private $coordinator;
- /** @var IServerContainer */
+ /** @var IServerContainer|MockObject */
private $server;
+ /** @var Manager */
+ private $manager;
+
protected function setUp(): void {
parent::setUp();
+ $this->coordinator = $this->createMock(Coordinator::class);
$this->server = $this->createMock(IServerContainer::class);
- $this->manager = new Manager($this->server);
+ $this->manager = new Manager(
+ $this->coordinator,
+ $this->server,
+ );
}
- public function testRegisterUnregisterBackend() {
+ public function testRegisterUnregisterBackend(): void {
$backend1 = $this->createMock(IBackend::class);
$backend1->method('getBackendIdentifier')->willReturn('backend_1');
- $this->server->expects($this->at(0))
- ->method('query')
- ->with('calendar_room_backend1')
- ->willReturn($backend1);
-
$backend2 = $this->createMock(IBackend::class);
$backend2->method('getBackendIdentifier')->willReturn('backend_2');
- $this->server->expects($this->at(1))
+ $this->server->expects(self::exactly(2))
->method('query')
- ->with('calendar_room_backend2')
- ->willReturn($backend2);
+ ->willReturnMap([
+ ['calendar_room_backend1', true, $backend1,],
+ ['calendar_room_backend2', true, $backend2,],
+ ]);
$this->manager->registerBackend('calendar_room_backend1');
$this->manager->registerBackend('calendar_room_backend2');
- $this->assertEquals([
+ self::assertEquals([
$backend1, $backend2
], $this->manager->getBackends());
$this->manager->unregisterBackend('calendar_room_backend1');
- $this->assertEquals([
+ self::assertEquals([
$backend2
], $this->manager->getBackends());
}
- public function testGetBackend() {
- $backend1 = $this->createMock(IBackend::class);
- $backend1->method('getBackendIdentifier')->willReturn('backend_1');
- $this->server->expects($this->at(0))
+ public function testGetBackendFromBootstrapRegistration(): void {
+ $backendClass = '\\OCA\\CalendarRoomFoo\\Backend';
+ $backend = $this->createMock(IBackend::class);
+ $backend->method('getBackendIdentifier')->willReturn('from_bootstrap');
+ $context = $this->createMock(RegistrationContext::class);
+ $this->coordinator->expects(self::once())
+ ->method('getRegistrationContext')
+ ->willReturn($context);
+ $context->expects(self::once())
+ ->method('getCalendarRoomBackendRegistrations')
+ ->willReturn([
+ new ServiceRegistration('calendar_room_foo', $backendClass)
+ ]);
+ $this->server->expects(self::once())
->method('query')
- ->with('calendar_room_backend1')
- ->willReturn($backend1);
+ ->with($backendClass)
+ ->willReturn($backend);
+
+ self::assertEquals($backend, $this->manager->getBackend('from_bootstrap'));
+ }
+ public function testGetBackend(): void {
+ $backend1 = $this->createMock(IBackend::class);
+ $backend1->method('getBackendIdentifier')->willReturn('backend_1');
$backend2 = $this->createMock(IBackend::class);
$backend2->method('getBackendIdentifier')->willReturn('backend_2');
- $this->server->expects($this->at(1))
+ $this->server->expects(self::exactly(2))
->method('query')
- ->with('calendar_room_backend2')
- ->willReturn($backend2);
+ ->willReturnMap([
+ ['calendar_room_backend1', true, $backend1,],
+ ['calendar_room_backend2', true, $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'));
+ self::assertEquals($backend1, $this->manager->getBackend('backend_1'));
+ self::assertEquals($backend2, $this->manager->getBackend('backend_2'));
}
- public function testClear() {
+ public function testClear(): void {
$backend1 = $this->createMock(IBackend::class);
$backend1->method('getBackendIdentifier')->willReturn('backend_1');
- $this->server->expects($this->at(0))
- ->method('query')
- ->with('calendar_room_backend1')
- ->willReturn($backend1);
-
$backend2 = $this->createMock(IBackend::class);
$backend2->method('getBackendIdentifier')->willReturn('backend_2');
- $this->server->expects($this->at(1))
+ $this->server->expects(self::exactly(2))
->method('query')
- ->with('calendar_room_backend2')
- ->willReturn($backend2);
+ ->willReturnMap([
+ ['calendar_room_backend1', true, $backend1,],
+ ['calendar_room_backend2', true, $backend2,],
+ ]);
$this->manager->registerBackend('calendar_room_backend1');
$this->manager->registerBackend('calendar_room_backend2');
- $this->assertEquals([
+ self::assertEquals([
$backend1, $backend2
], $this->manager->getBackends());
$this->manager->clear();
- $this->assertEquals([], $this->manager->getBackends());
+ self::assertEquals([], $this->manager->getBackends());
}
}