Skip to content

Commit 384ffc5

Browse files
authored
Merge pull request #93 from sagalbot/fix-install-process
fix: Prevent install command from breaking when `/tests` doesn't exist
2 parents 5604db7 + 5fa897d commit 384ffc5

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

src/Console/InstallCommand.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use Laravel\Prompts\Terminal;
2424
use Symfony\Component\Console\Attribute\AsCommand;
2525
use Symfony\Component\Finder\Finder;
26+
use Symfony\Component\Process\Process;
2627

2728
use function Laravel\Prompts\intro;
2829
use function Laravel\Prompts\multiselect;
@@ -58,6 +59,8 @@ class InstallCommand extends Command
5859

5960
private bool $enforceTests = true;
6061

62+
const MIN_TEST_COUNT = 6;
63+
6164
private string $greenTick;
6265

6366
private string $redCross;
@@ -118,9 +121,9 @@ private function discoverEnvironment(): void
118121
private function collectInstallationPreferences(): void
119122
{
120123
$this->selectedBoostFeatures = $this->selectBoostFeatures();
121-
$this->enforceTests = $this->determineTestEnforcement(ask: false);
122124
$this->selectedTargetMcpClient = $this->selectTargetMcpClients();
123125
$this->selectedTargetAgents = $this->selectTargetAgents();
126+
$this->enforceTests = $this->determineTestEnforcement(ask: false);
124127
}
125128

126129
private function performInstallation(): void
@@ -198,11 +201,19 @@ private function hyperlink(string $label, string $url): string
198201
*/
199202
protected function determineTestEnforcement(bool $ask = true): bool
200203
{
201-
$hasMinimumTests = Finder::create()
202-
->in(base_path('tests'))
203-
->files()
204-
->name('*.php')
205-
->count() > 6;
204+
$hasMinimumTests = false;
205+
206+
if (file_exists(base_path('vendor/bin/phpunit'))) {
207+
$process = new Process([PHP_BINARY, 'artisan', 'test', '--list-tests'], base_path());
208+
$process->run();
209+
210+
/** Count the number of tests - they'll always have :: between the filename and test name */
211+
$hasMinimumTests = Str::of($process->getOutput())
212+
->trim()
213+
->explode("\n")
214+
->filter(fn ($line) => str_contains($line, '::'))
215+
->count() >= self::MIN_TEST_COUNT;
216+
}
206217

207218
if (! $hasMinimumTests && $ask) {
208219
$hasMinimumTests = select(

0 commit comments

Comments
 (0)