Search code examples
phpphpstorm

How to set filename mask in PhpStorm search to exclude *test* files (PHPUnit)


In The PhpStorm you can search to text in all files in the whole project -- just click Schift+F. And you can set the filename mask there, like *.php

The test/phpunit folder is located in the project as well and is indexed for search. This is good and useful.

But sometimes you need to search in source code only, not in the test files.

It means that you should not disable those files from search index -- you need them.

PHPStorm exclude files by mask from indexing

WebStorm/PhpStorm exclude file from search everywhere

You just need some ability to filter them out sometimes.

I supposed to use the mask like "*[~^test]*.php" but it seems is not supported.

Any idea?


Solution

  • Considering that the test files would normally be named like SomethingTest.php .. then exclusion mask would be !*Test.php.

    To combine multiple extensions just list them using comma ,, e.g. *.php,!*test.php (search in .php files only but excluding test files)


    P.S. If you need to make such search often, it may be more convenient to create and use custom Scope (it can also be used in many other places: Navigate To File/Class/Symbol; Project View panel, File Watchers etc.)

    Scope is more flexible as it allows to select specific folders and have more complex include or exclude patterns in general (as it can work with folder names as well).