[14.x] Forward `isReporting()` and `buildContextForException()` in `ExceptionHandlerFake`

Merged
SU
22d ago
+18-2

ExceptionHandlerFake got isReporting() and buildContextForException() when they were added to the handler contract (#59781), but as stubs that return false and []. JsonFormatter asks the container's handler for buildContextForException($e) and only falls back to $e->context() when it gets something other than an array, so once Exceptions::fake() is active the context disappears from JSON logs. That also applies to exceptions that aren't faked and go through to the real handler:

Exceptions::fake([PaymentFailed::class]);

// OrderFailed::context() returns ['order_id' => 42]
Log::error('Order failed', ['exception' => new OrderFailed]);
// JSON record has no order_id

The fake already forwards report(), render() and renderForConsole() to the handler it wraps, so this does the same for the two new methods.