Skip to content
Merged
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
24 changes: 23 additions & 1 deletion src/Commands/FilamentTestsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Process;

use function Laravel\Prompts\multiselect;

class FilamentTestsCommand extends Command
{
protected $signature = 'make:filament-test';
protected $signature = 'make:filament-test
{--skip-pint : Skip running Pint on generated files}';

protected $description = 'Create a new test for a Filament component';

Expand All @@ -25,6 +27,7 @@ class FilamentTestsCommand extends Command
public function __construct(
protected ?Collection $resources = null,
protected ?Collection $panels = null,
protected array $generatedFiles = [],
protected ?Filesystem $files = null,
) {
$this->resources ??= collect();
Expand Down Expand Up @@ -54,9 +57,13 @@ public function handle(): void

file_put_contents($filePath, $rendered);

$this->generatedFiles[] = $filePath;

$this->info("Created test for {$resourceClass} → {$filePath}");
}
}

$this->runPintOnGeneratedFiles();
}

/**
Expand All @@ -72,6 +79,21 @@ protected function renderTestsForResource(string $resourceClass): string
]);
}

protected function runPintOnGeneratedFiles(): void
{
if ($this->generatedFiles === []) {
return;
}

if ($this->option('skip-pint')) {
return;
}

$files = implode(' ', $this->generatedFiles);

Process::run("vendor/bin/pint {$files}");
}

protected function getTestFilePath(string $resourceClass): string
{
$relativeClass = str($resourceClass)
Expand Down