Skip to content

Commit

Permalink
Fix Issue #34: Testing 'Internal Server Error (500)' (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
Starli0n authored and craig-davis committed Apr 25, 2017
1 parent 0c5981e commit 8558755
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"source": "https://github.com/there4/slim-test-helpers"
},
"require": {
"slim/slim": "3.*",
"slim/slim": "~3.1",
"phpunit/phpunit": "^4.8|5.*",
"phpunit/dbunit": "2.*",
"illuminate/database": ">=4.0"
Expand Down
4 changes: 2 additions & 2 deletions src/There4/Slim/Test/WebTestClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ 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);
$this->response = $app->process($this->request, $response);

// Return the application output.
return (string)$this->response->getBody();
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 testInternalError()
{
$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 8558755

Please sign in to comment.