webhookEntryFactoryMock = $this->createMock(WebhookEntryFactory::class); } public function testGetWebhookConfig() { $this->registry = new WebhookFileRegistry([ WebhookFileRegistry::OPTION_EVENTS => [ 'TestEvent' => ['wh1'] ], WebhookFileRegistry::OPTION_WEBHOOKS => [ 'wh1' => [ 'id' => 'wh1', 'url' => 'http://url.com', 'httpMethod' => 'POST', 'auth' => [ 'authClass' => 'SomeClass', 'properties' => [ 'p1' => 'v1' ] ] ] ] ]); $serviceLocator = $this->getServiceLocatorMock([ WebhookEntryFactory::class => $this->webhookEntryFactoryMock ]); $this->registry->setServiceLocator($serviceLocator); $returnValue = new Webhook( 'wh1', 'http://url.com', 'POST', 5, new WebhookAuth('SomeClass', ['p1' => 'v1']), true ); $this->webhookEntryFactoryMock->expects($this->once()) ->method('createEntryFromArray') ->with([ 'id' => 'wh1', 'url' => 'http://url.com', 'httpMethod' => 'POST', 'auth' => [ 'authClass' => 'SomeClass', 'properties' => [ 'p1' => 'v1' ] ] ]) ->willReturn($returnValue); $whConfig = $this->registry->getWebhookConfig('wh1'); $this->assertSame($returnValue, $whConfig); $this->assertNull($this->registry->getWebhookConfig('wh2')); } public function testGetWebhookConfigIds() { $this->registry = new WebhookFileRegistry([ WebhookFileRegistry::OPTION_EVENTS => [ 'TestEvent' => ['wh1'] ], WebhookFileRegistry::OPTION_WEBHOOKS => ['wh1' => []] ]); $result = $this->registry->getWebhookConfigIds('TestEvent'); $this->assertEquals(['wh1'], $result); $this->assertEquals([], $this->registry->getWebhookConfigIds('AnotherEvent')); } public function testGetUnexistingWebhookConfigIds() { $this->registry = new WebhookFileRegistry([ WebhookFileRegistry::OPTION_EVENTS => [ 'TestEvent' => ['wh1'] ], WebhookFileRegistry::OPTION_WEBHOOKS => ['wh1' => []] ]); $result = $this->registry->getWebhookConfigIds('AnotherEvent'); $this->assertEquals([], $result); } }