/** * {@inheritdoc} */ public function __invoke(ServerRequestInterface $request, ResponseInterface $response) { // Example from HAL Hypermedia spec at http://stateless.co/hal_specification.html $data = ['_links' => ['self' => ['href' => '/api-example'], "admin" => [['href' => '/admins/2', 'title' => 'Fred'], ['href' => '/admins/5', 'title' => 'Kate']]], '_embedded' => ['order' => [['_links' => ['self' => ['href' => '/orders/123'], 'customer' => ['href' => '/customers/21']], 'total' => 30.0, 'currency' => 'USD', 'status' => 'shipped'], ['_links' => ['self' => ['href' => '/orders/456'], 'customer' => ['href' => '/customers/22']], 'total' => 20.0, 'currency' => 'USD', 'status' => 'processing']]], 'currentlyProcessing' => 14, 'shippedToday' => 20]; $rendered = $this->json->encode($data); $response->getBody()->write($rendered); $response = $response->withHeader('Content-Type', 'application/hal+json'); return $response; }
public function testErrorWhileDecoding() { $input = <<<FORMATTED { "test1"::"abcd1", "test2"::"abcd2" } FORMATTED; $expected = 'Invalid json (Syntax error)'; $json = new Json(); $output = $json->decode($input); $this->assertSame(null, $output); $this->assertSame($expected, $json($input)); }