/** * @runInSeparateProcess */ public function testJson() { $response = new Response($this->makeRequest()); $response->setJson(['a' => 'b']); $this->expectOutputString(json_encode(['a' => 'b', 'c' => 'd'])); $response->json(['c' => 'd']); $this->assertContains('Content-type: application/json', xdebug_get_headers()); }
/** * Render template as JSON, add render result to Response output * Set Response[status] as $status * * @param string $name * @param string $status * @return void */ public static function renderJson($template, $status = 'ok', $data = null) { $template = new Template($template); $output = ['status' => $status, 'data' => $template->render()]; if (is_array($data)) { $output = array_merge($output, $data); } Response::setJson(); Response::add($output); }