/** * {@inheritdoc} */ public function body(HTTPProblem $problem) { $data = ['status' => $problem->status()]; if ($problem->title()) { $data['title'] = $problem->title(); } if (!in_array($problem->type(), [null, 'about:blank'], true)) { $data['type'] = $problem->type(); } if ($problem->detail()) { $data['detail'] = $problem->detail(); } if ($problem->instance()) { $data['instance'] = $problem->instance(); } $data += $problem->extensions(); return json_encode($data, $this->encodingOptions); }
public function testMinimumValidProblem() { $status = 418; $detail = 'A detailed message specific to this problem, but not unique.'; $problem = new HTTPProblem($status, $detail); $this->assertSame(418, $problem->status()); $this->assertSame('A detailed message specific to this problem, but not unique.', $problem->detail()); $this->assertSame([], $problem->extensions()); // Title autodetermined from status if not provided. $this->assertSame("I'm a teapot", $problem->title()); $this->assertSame(null, $problem->type()); $this->assertSame(null, $problem->instance()); }