Skip to content

Commit

Permalink
Merge pull request #290 from dissto/run-pint-after-generation
Browse files Browse the repository at this point in the history
Run pint after generation
  • Loading branch information
CodeWithDennis authored Jul 10, 2024
2 parents cc56892 + 44c7aa1 commit 655cac5
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
5 changes: 5 additions & 0 deletions config/filament-tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,4 +309,9 @@
],
],
],

/**
* Run laravel/pint for the generated tests after they are generated.
*/
'run_pint_after_generation' => env('FILAMENT_TESTS_RUN_PINT_AFTER_GENERATION', true),
];
50 changes: 50 additions & 0 deletions src/Commands/FilamentTestsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Collection;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process;

use function Laravel\Prompts\confirm;
use function Laravel\Prompts\multiselect;
Expand Down Expand Up @@ -110,6 +112,8 @@ public function handle(): int

$this->tableOutput($resources);

$this->runPint($this->selectedResources);

return self::SUCCESS;
}

Expand Down Expand Up @@ -312,5 +316,51 @@ protected function tableOutput(Collection $resources): void
}

$this->components->twoColumnDetail('Duration', $totalDuration);

}

protected function runPint(Collection $resources): void
{
$this->warnPintNotInstalled();

if (! $this->isPintInstalled()) {
return;
}

if (config('filament-tests.run_pint') === false) {
return;
}

$this->newLine();

$this->info('Running Laravel Pint for the generated tests...');

$testFolder = config('filament-tests.directory_name');
$tests = $resources->map(fn ($resource) => $testFolder.DIRECTORY_SEPARATOR.$resource['name'].'Test.php')->toArray();

$process = new Process(['vendor/bin/pint', ...$tests], base_path());

$process->setTimeout(null);

try {
$process->mustRun();

} catch (ProcessFailedException $exception) {
$this->error($exception->getMessage());
}

$this->info('Laravel Pint has been run for the generated tests.');
}

protected function isPintInstalled(): bool
{
return \Composer\InstalledVersions::isInstalled('laravel/pint');
}

protected function warnPintNotInstalled(): void
{
if (! $this->isPintInstalled()) {
$this->info('Laravel Pint is not installed. Please install it to run the tests or disable the option in the configuration file.');
}
}
}

0 comments on commit 655cac5

Please sign in to comment.