Skip to content

feat(discovery): add support for dynamic path exlusion#2045

Open
innocenzi wants to merge 4 commits into3.xfrom
fix/discovery/pest
Open

feat(discovery): add support for dynamic path exlusion#2045
innocenzi wants to merge 4 commits into3.xfrom
fix/discovery/pest

Conversation

@innocenzi
Copy link
Member

@innocenzi innocenzi commented Mar 13, 2026

This pull request adds support for dynamically excluding paths from being discovered:

new DiscoveryConfig(
    locations: [
        new DiscoveryLocation('Module\\', base_path('src/Modules')),
        new DiscoveryLocation('Infrastructure\\', base_path('src/Infrastructure')),
        new DiscoveryLocation('Integrations\\', base_path('src/Integrations')),
    ],
)->skipUsing(static function (string $input) {
    if (str_ends_with($input, needle: 'Test.php')) {
        return true;
    }

    if (str_ends_with($input, needle: 'Pest.php')) {
        return true;
    }

    return false;
});

It also includes another fix for when Tempest scans a Pest test file:

CleanShot 2026-03-13 at 16 19 47

When encountering a test or Pest.php file, class_exists or new ClassReflector throws because it autoloads the file.

@github-actions
Copy link

github-actions bot commented Mar 13, 2026

Benchmark Results

Comparison of fix/discovery/pest against 3.x (d53cd8d4a1c4d1c816e3b27db88a1cfa433e4ea6).

Open to see the benchmark results
Benchmark Set Mem. Peak Time Variability
QueryExecutionBench(benchExecuteInsert) - 4.239mb -0.81% 7.797μs -27.33% ±1.18% -32.44%
QueryExecutionBench(benchFetchAll) - 4.239mb -0.81% 41.144μs -8.71% ±0.70% -47.41%
QueryExecutionBench(benchFetchWithBindings) - 4.239mb -0.81% 14.162μs -20.68% ±1.06% -63.96%

Generated by phpbench against commit fc05662

@aidan-casey
Copy link
Member

@innocenzi - why don't we just add exclusion rules and include a couple smart defaults?

@innocenzi
Copy link
Member Author

The discovery config already has something similar, but nothing dynamic, I assume for performance.

I think adding static closure support would be fine too, but in this specific case, we already have a workaround for Pest within Tempest, and I'm extending it for outside of Tempest, I don't think all Pest users should manually have to debug that weird error

@innocenzi innocenzi changed the title fix(discovery): discard Pest exceptions during discovery feat(discovery): add support for dynamic path exlusion Mar 13, 2026
@innocenzi
Copy link
Member Author

@aidan-casey I added the functionality anyway because it's useful!

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.

2 participants