Test JSON responses.
This commit is contained in:
parent
8d5c16fc29
commit
207304b373
@ -53,4 +53,26 @@ class ControllerTest extends TestCase
|
||||
$this->assertEquals('<p>Oh no!</p>', $response->getBody());
|
||||
$this->assertEquals('text/html', $response->getHeaderLine('Content-Type'));
|
||||
}
|
||||
|
||||
public function testJsonResponse(): void
|
||||
{
|
||||
$testController = new class extends Controller {
|
||||
public function respond(): Response
|
||||
{
|
||||
return $this->json([ 'data' => 'hello' ]);
|
||||
}
|
||||
};
|
||||
|
||||
$app = $this->getAppInstance();
|
||||
$app->get('/test', $testController);
|
||||
|
||||
$request = $this->createRequest('GET', '/test');
|
||||
$response = $app->handle($request);
|
||||
|
||||
$this->assertEquals('{"data":"hello"}', $response->getBody());
|
||||
$this->assertEquals(
|
||||
'application/json',
|
||||
$response->getHeaderLine('Content-Type')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user