Excluded Tests directory not being excluded from parent folder search
I have a Laravel 5.x project that has a "tests" folder (directory) for PHPUnit that I'm assuming should be marked as a Test Sources directory, but unfortunately the files in this folder are showing up in project or parent directory file searches, bloating the results, often pushing them above 100+ results or files, and because PHPStorm orders the results randomly when it's over 100 results, this means a bunch of relevant non-test files may not show on the list, and regardless, including test results when I don't need them makes it difficult to find anything.
I'm pretty sure Find in Files is supposed to work by searching everything recursively in the selected scope (like In Project searches from the top-level folder, and Directory searches starting with the directory that you're in), except that it'll ignore "excluded" folders...
Well, the Tests folder is always being included in search when the scope is above the folder (I rarely need to search in the folder), even when it's marked as Excluded.

In my tests, I've found that Find in Files works in Excluded folders when the scope starts at that folder, but not above it, except when searching from above the Tests folder.
I think the issue is that one of the Tests sub-folders is green, meaning marked as a test folder, so the exclusion is overridden...
This is kind of insane; I don't want to unmark my Tests folder or sub-folders as Test Sources, but I need them excluded from search above the Tests folder. I'm going to go crazy if I can't find a solution to this. Actually nothing I do prevents Find in Files from search the Tests folder in any search starting above it.
Please sign in to leave a comment.
Why not? In general, yes, it's a valid concern, there's no way around it - setting a folder as a test root overrides the excluded state inherited from the parent.
I haven't been able to find an exact duplicate of this on the tracker, only slightly related ones:
https://youtrack.jetbrains.com/issue/IDEA-231421
https://youtrack.jetbrains.com/issue/IDEA-198503
Probably, it makes sense to submit a new one: https://youtrack.jetbrains.com/newIssue?project=IDEA
I just made my own search scope to exclude the Tests folder.
I assumed that it's not going to be a viable option for you because according to the description, it was my understanding that you want to limit the search to certain directories dynamically.
Thank you for sharing your findings!
I'm not sure what you mean by dynamically. I want the Tests folder excluded from search starting above that folder, not from that folder. I thought that's how PHPStorm worked already, but for some reason it's just impossible to exclude the Tests folder (from a search starting above it) unless I define a custom Scope, which I have to manually select often.
I mean that you can choose a folder in the Project tool window, press
Ctrl+Shift+F, and Find in Files will be started in the Directory mode with the currently chosen folder as the filter.Creating a custom scope will not work for this approach, because scopes only work in the Scope mode, that is why I didn't offer this as a possible solution.
Please state the name of the keyboard shortcut you're referring to in Settings > Keymap rather than the keyboard keys, as my keypresses are customized to my taste and I may not know what you mean by `Ctrl+Shift+F`. I'm assuming you mean `Main Menu > Edit > Find > Find in Files`.
I do understand that I can search starting from a specific directory that I manually choose (like right-clicking it in the Project panel), and I'm supposing you're referring to that when you say "currently chosen folder" (though maybe you mean one that is automatically selected when I run the hotkey, based on the parent folder of the current file tab I have open?).
Anyway, the point is that when I search starting from a specific folder (as in, that is the Directory tab selected to that path, like Tests or Vendor), I want search to show results in that folder recursively; but, if I select above that folder to begin the search, I want those Directory Excluded folders to not be searched. This includes when I select the Scope tab during the Find in Files search. PHPStorm will still search the Test (or Tests) folder even if it's set to Excluded (in Directory settings) in a Find in Files search starting from a folder above it (like the top-level project folder). I don't see any way around it other than recursively excluding the Test/s folder in a custom Scope search where I've selected that folder to be excluded recursively.
However, I seem to have found a bug when using the Scope tab and a custom search scope... if I use Exclude Tests, now `node_modules` is included. But node_modules is not selectable in custom search scopes! This is driving me crazy. Maybe this needs to be in a new post.