public function testException() { $exception = new \Exception("Error Processing Request"); $response = $this->execute([Middleware::ErrorHandler()->handler(function ($request, $response) { $exception = $request->getAttribute('EXCEPTION'); $response->getBody()->write((string) $exception); })->catchExceptions(), function ($request, $response, $next) use($exception) { throw $exception; }]); $this->assertEquals(500, $response->getStatusCode()); $this->assertEquals((string) $exception, (string) $response->getBody()); }