/** * Render an API Problem representation * * Also sets the $apiProblem member to the passed object. * * @param ApiProblem $apiProblem * @return string */ protected function renderApiProblem(ApiProblem $apiProblem) { $this->apiProblem = $apiProblem; if ($this->displayExceptions) { $apiProblem->setDetailIncludesStackTrace(true); } return parent::render($apiProblem->toArray()); }
public function testExceptionsCanTriggerInclusionOfNestedExceptions() { $exceptionChild = new \Exception('child exception'); $exceptionParent = new \Exception('parent exception', null, $exceptionChild); $apiProblem = new ApiProblem('500', $exceptionParent); $apiProblem->setDetailIncludesStackTrace(true); $payload = $apiProblem->toArray(); $this->assertArrayHasKey('exception_stack', $payload); $this->assertInternalType('array', $payload['exception_stack']); $expected = [['code' => $exceptionChild->getCode(), 'message' => $exceptionChild->getMessage(), 'trace' => $exceptionChild->getTrace()]]; $this->assertEquals($expected, $payload['exception_stack']); }