Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return HTTP status code 500 if the build fails #166

Merged
merged 1 commit into from
Dec 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Playbloom/Satisfy/Webhook/AbstractWebhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
64 changes: 64 additions & 0 deletions tests/Playbloom/Satisfy/Webhook/AbstractWebhookTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

namespace Tests\Playbloom\Satisfy\Webhook;

use PHPUnit\Framework\TestCase;
use Playbloom\Satisfy\Model\Repository;
use Playbloom\Satisfy\Model\RepositoryInterface;
use Playbloom\Satisfy\Service\Manager;
use Playbloom\Satisfy\Webhook\AbstractWebhook;
use Prophecy\PhpUnit\ProphecyTrait;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\HttpFoundation\Request;

class AbstractWebhookTest extends TestCase
{
use ProphecyTrait;

public function testGetResponseReturnsTheCommandExitCode()
{
$webhook = $this->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;
}
}