VOOZH about

URL: https://deepwiki.com/hypervel/testbench/8.5-exception-handling-and-views

⇱ Exception Handling and Views | hypervel/testbench | DeepWiki


Loading...
Last indexed: 7 February 2026 (93289f)
Menu

Exception Handling and Views

This document explains exception handling configuration, view templates, and localization within the Hypervel Testbench workbench environment. It covers the custom ExceptionHandler class, Blade view templates, and language file organization for internationalization support.

For information about other workbench components, see page 8.1 (Workbench Structure and Discovery) and page 8.3 (HTTP Routes and Controllers). For configuration details, see page 6 (Configuration Management).

Overview

The workbench provides three key presentation layer components:

  1. Exception Handler: Extends Hypervel\Foundation\Exceptions\Handler to control how errors and exceptions are reported, rendered, and logged during test execution
  2. View Templates: Blade template examples demonstrating view rendering in tests
  3. Localization: Language file structure for internationalization support

These components allow the testbench to demonstrate and test exception handling, view rendering, and localization functionality.

Sources: workbench/app/Exceptions/ExceptionHandler.php1-36 workbench/resources/views/welcome.blade.php1 workbench/lang/en/welcome.php1-7

Exception Handler Class Structure


The ExceptionHandler class extends Hypervel\Foundation\Exceptions\Handler, inheriting core exception handling functionality from the Hypervel framework. The workbench implementation customizes behavior through the register() method and defines sensitive fields that should not be flashed to the session.

Sources: workbench/app/Exceptions/ExceptionHandler.php11-35

Configuration Binding


The exception handler is registered through the configuration system. The workbench/config/exceptions.php6-10 file binds the Workbench\App\Exceptions\ExceptionHandler class as the HTTP exception handler. During application bootstrapping, this configuration is loaded and the exception handler is instantiated from the service container.

Configuration KeyValuePurpose
handler.http[Workbench\App\Exceptions\ExceptionHandler::class]Defines the HTTP exception handler class

Sources: workbench/config/exceptions.php1-12

Sensitive Data Protection

The $dontFlash property protects sensitive input fields from being flashed to the session during validation exceptions:


The workbench/app/Exceptions/ExceptionHandler.php18-22 defines the $dontFlash array with three sensitive fields:

  • current_password - Current user password
  • password - New password
  • password_confirmation - Password confirmation field

These fields are never stored in the session when validation fails, preventing sensitive data from being inadvertently persisted or logged.

Sources: workbench/app/Exceptions/ExceptionHandler.php14-22

Exception Handling Registration

The register() method configures exception handling callbacks:


The workbench/app/Exceptions/ExceptionHandler.php27-34 method configures two key behaviors:

JSON Rendering Configuration

The shouldRenderJsonWhen() callback at workbench/app/Exceptions/ExceptionHandler.php29-31 is configured to always return true, forcing all exceptions to be rendered as JSON responses. This is particularly useful for API testing where JSON responses are expected.

Reportable Exceptions

The reportable() callback at workbench/app/Exceptions/ExceptionHandler.php33 registers a handler for reportable exceptions. The workbench implementation provides an empty callback, meaning exceptions are not actively reported to external services (appropriate for a testing environment).

Sources: workbench/app/Exceptions/ExceptionHandler.php27-34

Integration with Testing


During test execution, the exception handler is automatically configured as part of the application bootstrap process. Each test receives a fresh application instance with a properly configured exception handler. This ensures:

  1. Consistent Exception Behavior: All tests use the same exception handling logic
  2. JSON Response Format: Exceptions are rendered as JSON, making assertions easier
  3. Sensitive Data Protection: Password fields are never flashed to session
  4. No External Reporting: Exceptions aren't sent to external logging services during tests

The exception handler integrates seamlessly with the TestCase base class (see page 2.2 for Application Creation and Container Setup) and the Bootstrapper (see page 5 for Environment Bootstrapping).

Sources: workbench/app/Exceptions/ExceptionHandler.php1-36

Extension Points

When creating custom exception handlers for your own tests, you can extend the workbench's ExceptionHandler or create a new handler extending Hypervel\Foundation\Exceptions\Handler. Key methods to override:

MethodPurposeLocation
register()Configure exception handling callbacksworkbench/app/Exceptions/ExceptionHandler.php27
$dontFlashDefine sensitive fields to exclude from session flashworkbench/app/Exceptions/ExceptionHandler.php18

You can customize exception rendering, reporting, and filtering by modifying these extension points in your test environment.

Sources: workbench/app/Exceptions/ExceptionHandler.php11-35