Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Issue #34: Testing 'Internal Server Error (500)' #35

Merged
merged 1 commit into from
Apr 25, 2017
Merged
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
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);
}
}