renderInline( '

{{ name }}

', [ 'name' => 'Dave' ] ); } }; $app = $this->getAppInstance(); $app->get('/test', $testController); $request = $this->createRequest('GET', '/test'); $response = $app->handle($request); $this->assertEquals('

Dave

', $response->getBody()); } public function testHtmlInlineResponseCodes(): void { $testController = new class extends Controller { public function respond(): Response { $response = $this->renderInline( '

{{ name }}

', [ 'name' => 'Oh no!' ] ); return $response->withStatus(400); } }; $app = $this->getAppInstance(); $app->get('/test', $testController); $request = $this->createRequest('GET', '/test'); $response = $app->handle($request); $this->assertEquals(400, $response->getStatusCode()); $this->assertEquals('

Oh no!

', $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') ); } /** * We have some Global variables set in the Configuration, for now its * hardcoded in the Bootstrap class. */ public function testRenderSiteName(): void { $testController = new class extends Controller { public function respond(): Response { return $this->renderInline("

{{ site_name }}

"); } }; $app = $this->getAppInstance(); $app->get('/test', $testController); $request = $this->createRequest('GET', '/test'); $response = $app->handle($request); $this->assertEquals('

Slovocast

', $response->getBody()); } public function testFlashMessages(): void { $app = $this->getAppInstance(); $session = $app->getContainer()->get(SessionInterface::class); $testController = new class($session) extends Controller { protected SessionInterface $session; public function __construct(SessionInterface $session) { $this->session = $session; } public function respond(): Response { $this->session->getFlash()->add("error", "Error message"); return $this->response; } }; $app->get('/test', $testController); $request = $this->createRequest('GET', '/test'); $response = $app->handle($request); $flash = $app->getContainer()->get(SessionInterface::class)->getFlash(); $errorMessages = $flash->get('error'); $this->assertEquals('Error message', $errorMessages[0]); $this->assertEquals(1, count($errorMessages)); } }