Skip to content

Commit 23b705a

Browse files
committed
Enhance test enforcement logic in InstallCommand
Updated the determineTestEnforcement method to automatically check for a minimum number of tests before prompting the user. Introduced a constant for the minimum test count and integrated Symfony Process to list and count tests.
1 parent 2ef14f1 commit 23b705a

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

src/Console/InstallCommand.php

Lines changed: 26 additions & 7 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 = 2;
63+
6164
private string $greenTick;
6265

6366
private string $redCross;
@@ -120,7 +123,7 @@ private function collectInstallationPreferences(): void
120123
$this->selectedBoostFeatures = $this->selectBoostFeatures();
121124
$this->selectedTargetMcpClient = $this->selectTargetMcpClients();
122125
$this->selectedTargetAgents = $this->selectTargetAgents();
123-
$this->enforceTests = $this->determineTestEnforcement();
126+
$this->enforceTests = $this->determineTestEnforcement(ask: false);
124127
}
125128

126129
private function performInstallation(): void
@@ -196,13 +199,29 @@ private function hyperlink(string $label, string $url): string
196199
* won't have the CI setup to make use of them anyway, so we're just wasting their
197200
* tokens/money by enforcing them.
198201
*/
199-
protected function determineTestEnforcement(): bool
202+
protected function determineTestEnforcement(bool $ask = true): bool
200203
{
201-
return select(
202-
label: 'Should AI always create tests?',
203-
options: ['Yes', 'No'],
204-
default: 'Yes'
205-
) === 'Yes';
204+
$hasMinimumTests = false;
205+
206+
if (file_exists(base_path('vendor/bin/phpunit'))) {
207+
$process = new Process(['php', 'artisan', 'test', '--list-tests']);
208+
$process->run();
209+
210+
/** Count the number of tests - they'll always have :: between the filename and test name */
211+
$hasMinimumTests = collect(explode("\n", trim($process->getOutput())))
212+
->filter(fn ($line) => str_contains($line, '::'))
213+
->count() >= self::MIN_TEST_COUNT;
214+
}
215+
216+
if (! $hasMinimumTests && $ask) {
217+
$hasMinimumTests = select(
218+
label: 'Should AI always create tests?',
219+
options: ['Yes', 'No'],
220+
default: 'Yes'
221+
) === 'Yes';
222+
}
223+
224+
return $hasMinimumTests;
206225
}
207226

208227
/**

0 commit comments

Comments
 (0)