Skip to content
This repository was archived by the owner on Jun 11, 2024. It is now read-only.

WIP #151 - Add proper tests for http response codes #154

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
24 changes: 23 additions & 1 deletion features/bootstrap/RaffleApiContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@ class RaffleApiContext implements Context

/** @var string|null */
private $raffleId;

/** @var array|null */
private $picked;

/** @var string */
private $testApiUrl = 'http://test.raffler.loc:8000/api';

/** @var int */
private $responseCode;

public function __construct(KernelInterface $kernel)
{
$this->kernel = $kernel;
Expand Down Expand Up @@ -237,9 +241,13 @@ private function apiPostJson(string $url, array $options = [])
try {
$response = $this->getGuzzle()->post($this->testApiUrl.$url, $options);

$this->responseCode = $response->getStatusCode();

return json_decode($response->getBody()->getContents(), true);
} catch (ClientException $ex) {
return $ex->getMessage();
$this->responseCode = $ex->getCode();

return;
}
}

Expand All @@ -252,4 +260,18 @@ protected function getService(string $name)
{
return $this->kernel->getContainer()->get($name);
}

/**
* @Then /^we get an http response with status code (\d+)$/
*/
public function weGetAnHttpResponseWithCode(int $statusCode)
{
$options = [
'json' => ['events' => []],
];

$this->apiPostJson('/raffle/start', $options);

Assert::eq($this->responseCode, $statusCode);
}
}
16 changes: 16 additions & 0 deletions features/bootstrap/RaffleContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,22 @@ public function weCannotContinueRaffling()
}
}

/**
* @Then /^we get an http response with status code (\d+)$/
*/
public function weGetAnHttpResponseWithCode(int $statusCode)
{
// $options = [
// 'json' => ['events' => []],
// ];
//
// $this->apiPostJson('/raffle/start', $options);
//
// Assert::eq($this->responseCode, $statusCode);

$this->weGetAnExceptionForARaffleWithNoMeetups();
}

/**
* @Then we get an exception for a raffle with no comments
*/
Expand Down
2 changes: 1 addition & 1 deletion features/raffle/picking-events-to-raffle.feature
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Feature:
Then there should be 2 events on the raffle

Scenario: Organizer will try to start a raffle with no events
Then we get an exception for a raffle with no meetups
Then we get an http response with status code 400

Scenario: Organizer will try to start a raffle with events not having any comments
Given we have these uncommented meetups in the system
Expand Down