subject = new WebhookEntryFactory(); } public function testCreateEntryFromArray() { $extraPayload = [ 'extra' => 'data' ]; $webhook = $this->subject->createEntryFromArray([ 'id' => 'wh1', 'url' => 'http://url.com', 'httpMethod' => 'POST', 'retryMax' => 5, 'responseValidation' => true, 'auth' => [ 'authClass' => 'SomeClass', 'credentials' => [ 'p1' => 'v1' ] ], 'extraPayload' => $extraPayload ]); $this->assertInstanceOf(WebhookInterface::class, $webhook); $this->assertEquals('wh1', $webhook->getId()); $this->assertEquals('http://url.com', $webhook->getUrl()); $this->assertEquals('POST', $webhook->getHttpMethod()); $this->assertEquals(5, $webhook->getMaxRetries()); $this->assertEquals('SomeClass', $webhook->getAuth()->getAuthClass()); $this->assertEquals(['p1' => 'v1'], $webhook->getAuth()->getCredentials()); $this->assertEquals(true, $webhook->getResponseValidationEnable()); $this->assertEquals($extraPayload, $webhook->getExtraPayload()); } public function testCreateEntryFromArrayWithoutAuth() { $webhook = $this->subject->createEntryFromArray([ 'id' => 'wh1', 'url' => 'http://url.com', 'httpMethod' => 'POST', 'retryMax' => 5, 'responseValidation' => true ]); $this->assertInstanceOf(WebhookInterface::class, $webhook); $this->assertEquals('wh1', $webhook->getId()); $this->assertEquals('http://url.com', $webhook->getUrl()); $this->assertEquals('POST', $webhook->getHttpMethod()); $this->assertEquals(true, $webhook->getResponseValidationEnable()); $this->assertNull($webhook->getAuth()); } public function testInvalidConfig() { $this->expectException(\InvalidArgumentException::class); try { $this->subject->createEntryFromArray([ 'id' => 'wh1', 'httpMethod' => 123, 'retryMax' => 5, 'auth' => [ 'authClass' => 'SomeClass', 'credentials' => [ 'p1' => 'v1' ] ] ]); } catch (\InvalidArgumentException $exception) { $this->assertStringContainsString('httpMethod', $exception->getMessage()); $this->assertStringContainsString('url', $exception->getMessage()); throw $exception; } } public function testInvalidAuthConfig() { $this->expectException(\InvalidArgumentException::class); try { $this->subject->createEntryFromArray([ 'id' => 'wh1', 'url' => 'http://url.com', 'httpMethod' => 'POST', 'retryMax' => 5, 'auth' => [ 'credentials' => [ 'p1' => 'v1' ] ] ]); } catch (\InvalidArgumentException $exception) { $this->assertStringContainsString('authClass', $exception->getMessage()); throw $exception; } } }