diff --git a/.gitignore b/.gitignore index 8e9d6e9..c97b59d 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,4 @@ tests/Screenshots docs/*.blade.php docs/**/*.blade.php -.phpunit.cache/test-results +.phpunit.cache diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..3bfd2a7 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,65 @@ +# CLAUDE.md + +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. + +## Overview + +Solo Dumps is a Laravel package that intercepts `dump()` calls and redirects them to a dedicated terminal window via a TCP server. This keeps browser/API responses clean while centralizing debug output. + +## Commands + +```bash +# Run all tests +./vendor/bin/phpunit + +# Run specific test suite +./vendor/bin/phpunit --testsuite=unit +./vendor/bin/phpunit --testsuite=integration + +# Run single test +./vendor/bin/phpunit --filter testMethodName + +# Start the dump server (for manual testing) +php vendor/bin/testbench solo:dumps +``` + +## Architecture + +### Data Flow + +```text +dump() call in app + ↓ +CustomDumper (VarDumper handler) + ↓ resolves source file/line + ↓ clones var with dumpSource context +ServerDumper → TCP socket (127.0.0.1:9984) + ↓ +DumpServer in `solo:dumps` command + ↓ extracts dumpSource from context +CliDumper → terminal output with source info +``` + +### Key Components + +- **CustomDumper** (`src/Support/CustomDumper.php`): Registers a custom VarDumper handler that: + - Resolves dump source (file:line) before sending + - Checks if dump server port is open + - Falls back to original handler if server unavailable + +- **Dumps Command** (`src/Console/Commands/Dumps.php`): Runs the TCP server that receives and displays dumps with source information + +### Fallback Behavior + +When the dump server isn't running, CustomDumper falls back to the original dump handler. The `portOpen()` check prevents drops on first dump (ServerDumper's built-in fallback only kicks in after first failure). + +## Configuration + +Host configured via `config/solo.php`: +```php +'dump_server_host' => 'tcp://127.0.0.1:9984' +``` + +## Testing Notes + +Integration tests spawn real processes to test the server/client interaction. Tests use Orchestra Testbench with process helpers. diff --git a/composer.json b/composer.json index 4d10a0a..224575c 100644 --- a/composer.json +++ b/composer.json @@ -10,6 +10,7 @@ } ], "minimum-stability": "dev", + "prefer-stable": true, "require": { "php": "^8.1", "illuminate/support": "^10|^11|^12", @@ -48,8 +49,6 @@ "serve": [ "Composer\\Config::disableProcessTimeout", "@php vendor/bin/testbench serve --ansi" - ], - "dev": [ ] } } diff --git a/src/Console/Commands/DumpTestOnly.php b/src/Console/Commands/DumpTestOnly.php index 2168dcd..aae1ac5 100644 --- a/src/Console/Commands/DumpTestOnly.php +++ b/src/Console/Commands/DumpTestOnly.php @@ -23,7 +23,7 @@ public function __construct() $this->setHidden(); } - public function handle() + public function handle(): void { if ($this->option('uuid')) { dump($this->option('uuid')); diff --git a/src/Console/Commands/Dumps.php b/src/Console/Commands/Dumps.php index 5b88e92..ce3cb13 100644 --- a/src/Console/Commands/Dumps.php +++ b/src/Console/Commands/Dumps.php @@ -22,7 +22,7 @@ class Dumps extends Command protected $description = 'Collect dumps from your Laravel application.'; - public function handle() + public function handle(): void { $dumper = new CliDumper( output: $this->getOutput()->getOutput(), diff --git a/src/Providers/DumpServiceProvider.php b/src/Providers/DumpServiceProvider.php index 30fd6c3..dfdf135 100644 --- a/src/Providers/DumpServiceProvider.php +++ b/src/Providers/DumpServiceProvider.php @@ -11,24 +11,22 @@ use Illuminate\Support\ServiceProvider; use SoloTerm\Dumps\Console\Commands\Dumps; -use SoloTerm\Dumps\Console\Commands\DumpTestOnly; use SoloTerm\Dumps\Support\CustomDumper; class DumpServiceProvider extends ServiceProvider { - public function register() + public function register(): void { // } - public function boot() + public function boot(): void { CustomDumper::register($this->app->basePath(), $this->app['config']->get('view.compiled')); if ($this->app->runningInConsole()) { $this->commands([ Dumps::class, - DumpTestOnly::class, ]); } } diff --git a/src/Support/CustomDumper.php b/src/Support/CustomDumper.php index bbac338..a57855c 100644 --- a/src/Support/CustomDumper.php +++ b/src/Support/CustomDumper.php @@ -10,7 +10,6 @@ namespace SoloTerm\Dumps\Support; use Illuminate\Foundation\Console\CliDumper; -use Illuminate\Foundation\Console\CliDumper as LaravelCliDumper; use Symfony\Component\Console\Output\StreamOutput; use Symfony\Component\VarDumper\Caster\ReflectionCaster; use Symfony\Component\VarDumper\Cloner\Data; @@ -22,7 +21,7 @@ class CustomDumper { - public static function register($basePath, $compiledViewPath): static + public static function register(string $basePath, ?string $compiledViewPath): static { return new static($basePath, $compiledViewPath); } @@ -32,7 +31,7 @@ public static function dumpServerHost(): string return config()->get('solo.dump_server_host', 'tcp://127.0.0.1:9984'); } - public function __construct(public string $basePath, public string $compiledViewPath) + public function __construct(public string $basePath, public ?string $compiledViewPath) { $cloner = new VarCloner; $cloner->addCasters(ReflectionCaster::UNSET_CLOSURE_FILE_INFO); @@ -89,7 +88,7 @@ protected function makeSourceResolvingDumper(): CliDumper { $output = new StreamOutput(fopen('php://memory', 'w')); - return new LaravelCliDumper($output, $this->basePath, $this->compiledViewPath); + return new CliDumper($output, $this->basePath, $this->compiledViewPath); } protected function makeFallbackDumper(): DataDumperInterface diff --git a/testbench.yaml b/testbench.yaml index 75f7b21..de6256d 100644 --- a/testbench.yaml +++ b/testbench.yaml @@ -1,5 +1,6 @@ providers: - SoloTerm\Dumps\Providers\DumpServiceProvider + - SoloTerm\Dumps\Tests\Support\DumpTestServiceProvider - App\Providers\AppServiceProvider migrations: false diff --git a/tests/Integration/BasicTest.php b/tests/Integration/BasicTest.php index 853c5d1..067c67f 100644 --- a/tests/Integration/BasicTest.php +++ b/tests/Integration/BasicTest.php @@ -54,8 +54,6 @@ public function start_and_stop_test() $loop = Process::start('php vendor/bin/testbench solo:dump-test-only --loop'); sleep(2); - ob_get_clean(); - echo json_encode($server->running()); echo PHP_EOL; echo $server->output(); diff --git a/tests/Support/DumpTestServiceProvider.php b/tests/Support/DumpTestServiceProvider.php index cd8443b..79f894e 100644 --- a/tests/Support/DumpTestServiceProvider.php +++ b/tests/Support/DumpTestServiceProvider.php @@ -10,11 +10,16 @@ namespace SoloTerm\Dumps\Tests\Support; use Illuminate\Support\ServiceProvider; +use SoloTerm\Dumps\Console\Commands\DumpTestOnly; class DumpTestServiceProvider extends ServiceProvider { - public function boot() + public function boot(): void { - // + if ($this->app->runningInConsole()) { + $this->commands([ + DumpTestOnly::class, + ]); + } } }