diff --git a/src/Playbloom/Satisfy/Webhook/AbstractWebhook.php b/src/Playbloom/Satisfy/Webhook/AbstractWebhook.php index c3e8489..6d6a41a 100644 --- a/src/Playbloom/Satisfy/Webhook/AbstractWebhook.php +++ b/src/Playbloom/Satisfy/Webhook/AbstractWebhook.php @@ -44,7 +44,7 @@ public function getResponse(Request $request): Response throw new ServiceUnavailableHttpException(); } - return new Response((string)$status); + return new Response((string) $status, 0 === $status ? Response::HTTP_OK : Response::HTTP_INTERNAL_SERVER_ERROR); } public function handle(RepositoryInterface $repository): ?int diff --git a/tests/Playbloom/Satisfy/Webhook/AbstractWebhookTest.php b/tests/Playbloom/Satisfy/Webhook/AbstractWebhookTest.php new file mode 100644 index 0000000..d76496d --- /dev/null +++ b/tests/Playbloom/Satisfy/Webhook/AbstractWebhookTest.php @@ -0,0 +1,64 @@ +createWebhook(0); + + $response = $webhook->getResponse(Request::create('/')); + + $this->assertEquals(200, $response->getStatusCode()); + $this->assertEquals('0', $response->getContent()); + } + + public function testGetResponseWithErrorsReturns500() + { + $webhook = $this->createWebhook(1); + + $response = $webhook->getResponse(Request::create('/')); + + $this->assertEquals(500, $response->getStatusCode()); + $this->assertEquals('1', $response->getContent()); + } + + public function createWebhook(int $status): AbstractWebhook + { + $manager = $this->prophesize(Manager::class); + + $webhook = new class($manager->reveal(), new EventDispatcher()) extends AbstractWebhook { + public $status; + + public function handle(RepositoryInterface $repository): ?int + { + return $this->status; + } + + protected function validate(Request $request): void + { + } + + protected function getRepository(Request $request): RepositoryInterface + { + return new Repository('git@git.example.com', 'git'); + } + }; + + $webhook->status = $status; + + return $webhook; + } +}