Skip to content

Commit

Permalink
Fix Issue there4#34: Testing 'Internal Server Error (500)'
Browse files Browse the repository at this point in the history
  • Loading branch information
Starli0n committed Sep 5, 2016
1 parent 0c5981e commit b4beac1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/There4/Slim/Test/WebTestClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private function request($method, $path, $data = array(), $optionalHeaders = arr
$this->request = new Request($method, $uri, $headers, $cookies, $serverParams, $body);
$response = new Response();

// Invoke request
// Process request
$app = $this->app;
$this->response = $app($this->request, $response);

Expand Down
22 changes: 22 additions & 0 deletions tests/There4Test/Slim/Test/WebTestClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,26 @@ private function getValidUri()
{
return '/testing';
}

public function estInternalError()
{
$this->getSlimInstance()->get('/internalerror', function ($request, $response, $args) {
throw new \Exception('Testing /internalerror.');
return $response;
});

$container = $this->getSlimInstance()->getContainer();
$container['errorHandler'] = function ($c) {
return function ($request, $response, $exception) use ($c) {
$data = array('message' => 'Internal Server Error');
return $c['response']->withJson($data, 500);
};
};

$client = new WebTestClient($this->getSlimInstance());
$client->get('/internalerror');
self::assertEquals(500, $client->response->getStatusCode());
$data = json_decode($client->response->getBody());
self::assertEquals('Internal Server Error', $data->message);
}
}

0 comments on commit b4beac1

Please sign in to comment.