Skip to content

Commit 8558755

Browse files
Starli0ncraig-davis
authored andcommitted
Fix Issue #34: Testing 'Internal Server Error (500)' (#35)
1 parent 0c5981e commit 8558755

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"source": "https://github.com/there4/slim-test-helpers"
2121
},
2222
"require": {
23-
"slim/slim": "3.*",
23+
"slim/slim": "~3.1",
2424
"phpunit/phpunit": "^4.8|5.*",
2525
"phpunit/dbunit": "2.*",
2626
"illuminate/database": ">=4.0"

src/There4/Slim/Test/WebTestClient.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ private function request($method, $path, $data = array(), $optionalHeaders = arr
102102
$this->request = new Request($method, $uri, $headers, $cookies, $serverParams, $body);
103103
$response = new Response();
104104

105-
// Invoke request
105+
// Process request
106106
$app = $this->app;
107-
$this->response = $app($this->request, $response);
107+
$this->response = $app->process($this->request, $response);
108108

109109
// Return the application output.
110110
return (string)$this->response->getBody();

tests/There4Test/Slim/Test/WebTestClientTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,26 @@ private function getValidUri()
140140
{
141141
return '/testing';
142142
}
143+
144+
public function testInternalError()
145+
{
146+
$this->getSlimInstance()->get('/internalerror', function ($request, $response, $args) {
147+
throw new \Exception('Testing /internalerror.');
148+
return $response;
149+
});
150+
151+
$container = $this->getSlimInstance()->getContainer();
152+
$container['errorHandler'] = function ($c) {
153+
return function ($request, $response, $exception) use ($c) {
154+
$data = array('message' => 'Internal Server Error');
155+
return $c['response']->withJson($data, 500);
156+
};
157+
};
158+
159+
$client = new WebTestClient($this->getSlimInstance());
160+
$client->get('/internalerror');
161+
self::assertEquals(500, $client->response->getStatusCode());
162+
$data = json_decode($client->response->getBody());
163+
self::assertEquals('Internal Server Error', $data->message);
164+
}
143165
}

0 commit comments

Comments
 (0)