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

Commit

Permalink
WIP@refactor testing for http response codes in behat
Browse files Browse the repository at this point in the history
- match NoEventsToRaffleException to HTTP response status 400
  • Loading branch information
HcsOmot committed Jan 3, 2018
1 parent 3316b0e commit 12d6644
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
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

0 comments on commit 12d6644

Please sign in to comment.