Skip to content

fix: Prevent install command from breaking when /tests doesn't exist #93

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 15, 2025

Conversation

sagalbot
Copy link
Contributor

@sagalbot sagalbot commented Aug 14, 2025

Currently, on v1.0.9, php artisan boost:install will fail for any project that doesn't contain a tests directory at the root of the project.

~/Sites/central install-laravel-boost* 20s
❯ php artisan boost:install

 ██████╗   ██████╗   ██████╗  ███████╗ ████████╗
 ██╔══██╗ ██╔═══██╗ ██╔═══██╗ ██╔════╝ ╚══██╔══╝
 ██████╔╝ ██║   ██║ ██║   ██║ ███████╗    ██║
 ██╔══██╗ ██║   ██║ ██║   ██║ ╚════██║    ██║
 ██████╔╝ ╚██████╔╝ ╚██████╔╝ ███████║    ██║
 ╚═════╝   ╚═════╝   ╚═════╝  ╚══════╝    ╚═╝

  ✦ Laravel Boost :: Install :: We Must Ship ✦ 

 Let's give Redacted Project Name a Boost

Symfony\Component\Finder\Exception\DirectoryNotFoundException 

The "/Users/sagalbot/Sites/central/tests" directory does not exist.

at vendor/symfony/finder/Finder.php:646
  642▕             } elseif ($glob = glob($dir, (\defined('GLOB_BRACE') ? \GLOB_BRACE : 0) | \GLOB_ONLYDIR | \GLOB_NOSORT)) {
  643▕                 sort($glob);
  644▕                 $resolvedDirs[] = array_map($this->normalizeDir(...), $glob);
  645▕             } else {
➜ 646▕                 throw new DirectoryNotFoundException(\sprintf('The "%s" directory does not exist.', $dir));
  647▕             }
  648▕         }
  649▕ 
  650▕         $this->dirs = array_merge($this->dirs, ...$resolvedDirs);

    +15 vendor frames 

16  artisan:35
    Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

The installer looks for tests within the directory to determine if the user should be prompted about AI writing tests. The strategy here makes sense - remove an install step if no tests are found, but the current implementation will fail for many projects.

I think the simplest possible solution here is to just ask the user. Yes, it's one extra step, but it puts control in the hands of the user. If you're installing into a fresh Laravel project, the arbitrary 6 test threshold means you won't be asked about AI test guidelines.

If you do want to use the presence of tests as a way to determine if this question should be asked, you could call phpunit --list-tests and check if the output is >=6 lines. That should work for jest and phpunit regardless of test ___location.

Changes

  • removes check for /tests (fixes install failure)
  • changes flow so asking is the last step

Resolves #45

Simplifies the determineTestEnforcement method by removing the minimum test file check and always prompting the user to decide if AI should create tests. Updates collectInstallationPreferences to match the new method signature.
@sagalbot
Copy link
Contributor Author

I just noticed that the current flow is set to never ask and have $enforceTests always true. Easier fix - just delete the method and the call? Let me know and I can update the PR.

@pushpak1300
Copy link
Member

@sagalbot
Initially, we're aiming to keep the number of questions during installation to a minimum, which is why we have the ask option available but haven't enabled it yet.
I was thinking if we could make the failure avoid when the test directory doesn't exist. For example, we could implement something like this:

$testsPath = base_path('tests');
$hasMinimumTests = false;
if (is_dir($testsPath)) {
    $hasMinimumTests = Finder::create()
        ->in($testsPath)
        ->files()
        ->name('*.php')
        ->count() > 6;
}

What do you think about this suggestion?

@ashleyhindle
Copy link
Collaborator

This would be my preference too for right now, checking if tests exists before searching.

We added the ask option because we do want to ask at some point when needed, but it's a bit in the way at the minute and we need to find a better DX for that & other questions 👌

pushpak1300 and others added 2 commits August 14, 2025 16:18
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.
Replaces the use of collect and explode with Str helper methods for trimming and splitting the process output when counting tests.
Replaces hardcoded 'php' with PHP_BINARY and sets the working directory to base_path() when running the test listing process. This improves compatibility with different PHP environments and ensures the process runs in the correct directory.
@ashleyhindle ashleyhindle self-assigned this Aug 14, 2025
@sagalbot sagalbot changed the title Fix: Prevent install command from breaking when /tests doesn't exist fix: Prevent install command from breaking when /tests doesn't exist Aug 14, 2025
Copy link
Member

@pushpak1300 pushpak1300 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ashleyhindle I have tested this locally.

LGTM 🚀

@ashleyhindle ashleyhindle merged commit 384ffc5 into laravel:main Aug 15, 2025
9 checks passed
@ashleyhindle
Copy link
Collaborator

Thanks @sagalbot, you're the best 🫶

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

When the tests directory does not exist, boost:install fails
4 participants