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

Commit 12d6644

Browse files
committed
WIP@refactor testing for http response codes in behat
- match NoEventsToRaffleException to HTTP response status 400
1 parent 3316b0e commit 12d6644

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

features/bootstrap/RaffleApiContext.php

+23-1
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,16 @@ class RaffleApiContext implements Context
2020

2121
/** @var string|null */
2222
private $raffleId;
23+
2324
/** @var array|null */
2425
private $picked;
2526

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

30+
/** @var int */
31+
private $responseCode;
32+
2933
public function __construct(KernelInterface $kernel)
3034
{
3135
$this->kernel = $kernel;
@@ -237,9 +241,13 @@ private function apiPostJson(string $url, array $options = [])
237241
try {
238242
$response = $this->getGuzzle()->post($this->testApiUrl.$url, $options);
239243

244+
$this->responseCode = $response->getStatusCode();
245+
240246
return json_decode($response->getBody()->getContents(), true);
241247
} catch (ClientException $ex) {
242-
return $ex->getMessage();
248+
$this->responseCode = $ex->getCode();
249+
250+
return;
243251
}
244252
}
245253

@@ -252,4 +260,18 @@ protected function getService(string $name)
252260
{
253261
return $this->kernel->getContainer()->get($name);
254262
}
263+
264+
/**
265+
* @Then /^we get an http response with status code (\d+)$/
266+
*/
267+
public function weGetAnHttpResponseWithCode(int $statusCode)
268+
{
269+
$options = [
270+
'json' => ['events' => []],
271+
];
272+
273+
$this->apiPostJson('/raffle/start', $options);
274+
275+
Assert::eq($this->responseCode, $statusCode);
276+
}
255277
}

features/bootstrap/RaffleContext.php

+16
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,22 @@ public function weCannotContinueRaffling()
240240
}
241241
}
242242

243+
/**
244+
* @Then /^we get an http response with status code (\d+)$/
245+
*/
246+
public function weGetAnHttpResponseWithCode(int $statusCode)
247+
{
248+
// $options = [
249+
// 'json' => ['events' => []],
250+
// ];
251+
//
252+
// $this->apiPostJson('/raffle/start', $options);
253+
//
254+
// Assert::eq($this->responseCode, $statusCode);
255+
256+
$this->weGetAnExceptionForARaffleWithNoMeetups();
257+
}
258+
243259
/**
244260
* @Then we get an exception for a raffle with no comments
245261
*/

features/raffle/picking-events-to-raffle.feature

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Feature:
3636
Then there should be 2 events on the raffle
3737

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

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

0 commit comments

Comments
 (0)