Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ tests/Screenshots

docs/*.blade.php
docs/**/*.blade.php
.phpunit.cache/test-results
.phpunit.cache
65 changes: 65 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
}
],
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": "^8.1",
"illuminate/support": "^10|^11|^12",
Expand Down Expand Up @@ -48,8 +49,6 @@
"serve": [
"Composer\\Config::disableProcessTimeout",
"@php vendor/bin/testbench serve --ansi"
],
"dev": [
]
}
}
2 changes: 1 addition & 1 deletion src/Console/Commands/DumpTestOnly.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function __construct()
$this->setHidden();
}

public function handle()
public function handle(): void
{
if ($this->option('uuid')) {
dump($this->option('uuid'));
Expand Down
2 changes: 1 addition & 1 deletion src/Console/Commands/Dumps.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
6 changes: 2 additions & 4 deletions src/Providers/DumpServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]);
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/Support/CustomDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions testbench.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
providers:
- SoloTerm\Dumps\Providers\DumpServiceProvider
- SoloTerm\Dumps\Tests\Support\DumpTestServiceProvider
- App\Providers\AppServiceProvider

migrations: false
Expand Down
2 changes: 0 additions & 2 deletions tests/Integration/BasicTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
9 changes: 7 additions & 2 deletions tests/Support/DumpTestServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]);
}
}
}