diff options
author | Christoph Wurst <ChristophWurst@users.noreply.github.com> | 2022-02-09 10:25:03 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-09 10:25:03 +0100 |
commit | cd7a217c29a38a778aea54827dcecccd254e6f20 (patch) | |
tree | f84baaec393b30daa2199a5b2c6fd2b220ec6415 /tests | |
parent | f4c719734a1939b846929a9a8303b26f5b7a3ed6 (diff) | |
parent | 9a656e5b35d004b55fbe09d10d51254a8ec4fd67 (diff) | |
download | nextcloud-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
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/Calendar/Resource/ManagerTest.php | 102 | ||||
-rw-r--r-- | tests/lib/Calendar/Room/ManagerTest.php | 100 |
2 files changed, 126 insertions, 76 deletions
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()); } } |