public function testRenderingWithProblem() { $renderer = new ProblemRenderer(); $exception = new HTTPProblemException(403, 'This action is not allowed', ['data1' => 'abcd', 'data2' => 1234]); $exception->problem()->withTitle('test title')->withType('http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html')->withInstance('http://example.com/12345'); ob_start(); $renderer->render(500, ['exception' => $exception]); $output = ob_get_clean(); $expected = <<<JSON { "status": 403, "title": "test title", "type": "http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html", "detail": "This action is not allowed", "instance": "http://example.com/12345", "data1": "abcd", "data2": 1234 } JSON; $this->assertSame($expected, $output); }
public function testExceptionCreatesProblem() { $extensions = ['data1' => '1234', 'data2' => 'abcd']; $exception = new HTTPProblemException(500, 'An error occurred.', $extensions); $this->assertInstanceof(HTTPProblem::CLASS, $exception->problem()); $this->assertSame(500, $exception->problem()->status()); $this->assertSame('Internal Server Error', $exception->problem()->title()); $this->assertSame('An error occurred.', $exception->problem()->detail()); $this->assertSame($extensions, $exception->problem()->extensions()); }