VOOZH about

URL: https://deepwiki.com/hypervel/testbench/8.4-console-commands-and-routes

⇱ Console Commands and Routes | hypervel/testbench | DeepWiki


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

Console Commands and Routes

This page documents the console command examples provided in the workbench environment. The workbench includes both a class-based command (DummyCommand) and a closure-based command route (workbench:inspire) to demonstrate the two primary patterns for implementing console commands in Hypervel applications.

For information about how commands are discovered and registered by the service provider, see page 8.1 (Workbench Structure and Discovery). For HTTP routing patterns, see page 8.3 (HTTP Routes and Controllers).

Command Registration Approaches

The workbench demonstrates two primary methods for defining console commands in Hypervel applications:

ApproachFile LocationUse Case
Class-basedworkbench/app/Console/Commands/Reusable commands with complex logic
Closure-basedworkbench/routes/console.phpSimple, one-off commands with inline logic

Sources: workbench/app/Console/Commands/DummyCommand.php1-22 workbench/routes/console.php1-22

Console Command Structure

Command Implementation Patterns

The following diagram maps the two command patterns to their concrete implementations in the workbench:


Sources: workbench/app/Console/Commands/DummyCommand.php1-22 workbench/routes/console.php1-22

Class-Based Commands

The DummyCommand class workbench/app/Console/Commands/DummyCommand.php9-21 demonstrates the standard pattern for creating reusable console commands.

Command Structure

ComponentPurposeExample Value
Base classExtends Hypervel\Console\Commandworkbench/app/Console/Commands/DummyCommand.php9
$signatureDefines command name and syntax'sample:command' workbench/app/Console/Commands/DummyCommand.php11
$descriptionHelp text displayed in command list'Sample command' workbench/app/Console/Commands/DummyCommand.php13
handle()Command execution logicworkbench/app/Console/Commands/DummyCommand.php15-20
Output methodsWrite to console$this->info('It works!') workbench/app/Console/Commands/DummyCommand.php17
Return valueExit code (0 = success)return 0; workbench/app/Console/Commands/DummyCommand.php19

Command Namespace

Class-based commands in the workbench use the Workbench\App\Console\Commands namespace workbench/app/Console/Commands/DummyCommand.php5 and are automatically discovered by the framework's command scanner.

Sources: workbench/app/Console/Commands/DummyCommand.php1-22

Closure-Based Commands

The workbench/routes/console.php file demonstrates closure-based command registration workbench/routes/console.php18-21

Closure Command Registration


Sources: workbench/routes/console.php18-21

Console Routes File Structure

The console.php file workbench/routes/console.php1-22 provides:

ElementDescription
Locationworkbench/routes/console.php
Facade importuse Hypervel\Support\Facades\Artisan; workbench/routes/console.php5
Command definitionArtisan::command('workbench:inspire', function() {...}) workbench/routes/console.php18
Output method$this->comment() for formatted text workbench/routes/console.php20
Purpose metadata->purpose('Display an inspiring quote') workbench/routes/console.php21

The closure receives access to console output methods through the $this context, allowing the use of comment(), info(), error(), and other output formatters.

Sources: workbench/routes/console.php1-22

Command Discovery and Registration

Console commands in the workbench are discovered and registered through the framework's service provider system. The registration process involves two phases: class discovery and console route loading.

Command Registration Flow


Sources: Referenced from service provider patterns, workbench/app/Console/Commands/DummyCommand.php1-22 workbench/routes/console.php1-22

Discovery Configuration

The testbench.yaml file controls which directories are scanned for commands and whether console routes are loaded. Command discovery is enabled by default in the workbench configuration. See page 6.1 (Testbench Configuration) for details on discovery settings.

Sources: workbench/app/Console/Commands/DummyCommand.php1-22 workbench/routes/console.php1-22

Testing Integration

The workbench routes and commands are designed specifically for testing scenarios:

Route Testing Patterns

  • Success paths: Welcome route for testing view rendering
  • Error paths: Failed routes for exception handling verification
  • API responses: JSON endpoint for HTTP client testing
  • Middleware: Routes can be used to test middleware functionality

Command Testing Patterns

  • Output verification: Commands demonstrate different output methods (info(), comment())
  • Exit codes: Proper return value handling for process testing
  • Class vs. closure: Examples of both registration approaches for comprehensive testing

The consistent error handling patterns across both web and API routes workbench/routes/web.php18 and workbench/routes/api.php22 provide standardized endpoints for testing exception handling in different contexts.

Sources: workbench/routes/web.php18-20 workbench/routes/api.php18-22 workbench/app/Console/Commands/DummyCommand.php15-20 workbench/routes/console.php18-21