Skip to content

Conversation

@davidhemphill
Copy link
Contributor

This PR introduces a new commandFileFinder method to the console Kernel and updates the command discovery logic to exclude test files by default.

Changes

  • Added a new protected commandFileFinder(array $paths) method that returns the Finder instance used for discovering command files
  • Updated the load method to use $this->commandFileFinder($paths) instead of directly instantiating the Finder
  • Test files matching *Test.php are now excluded from command auto-discovery by default

Benefits to End Users

  1. Fixes PHPUnit ignoring co-located test files - When developers co-locate PHPUnit test files alongside their command classes in the Commands folder, the command discovery mechanism autoloads these test files before PHPUnit runs. This causes PHPUnit to skip them entirely since the classes are already loaded. By excluding *Test.php files from command discovery, tests are properly executed by PHPUnit.

  2. Extensibility - Developers can now override commandFileFinder() in their application's Kernel to customize which files are discovered (e.g., exclude additional patterns, include specific directories, etc.)

@taylorotwell taylorotwell merged commit d03f650 into laravel:12.x Dec 4, 2025
74 checks passed
@streamingsystems
Copy link

streamingsystems commented Dec 10, 2025

Hi All,

I upgraded to the latest version (12.42.0) and my "development:test" command is no longer found. When I reverted back to 12.41.1 it worked fine. I am wondering if this new feature is causing the issue?

ERROR Command "development:test" is not defined. Did you mean one of these?

(my thought would be that this would have been backwards compatible as it took me a while after my upgrade to figure out why my commands were not working)

Thanks for all you do.

-Rob

@macropay-solutions
Copy link

@streamingsystems see #58106 (comment) for a solution

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.

4 participants