|
| 1 | +# Testo. Filters |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | +Filters are needed to narrow down the set of tests to run. In other words, it's the ability to select tests before running them. |
| 6 | + |
| 7 | +Adding filters is one of the important milestones on the road to version 1.0.0 |
| 8 | + |
| 9 | +Now we can proudly say that this milestone is closed. Filters are supported at both the framework level and the plugin level. |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | +**The filtering system in** [Testo](https://github.com/php-internal/testo) **is multi-layered.** |
| 14 | + |
| 15 | +1. **Test Suite** (`--suite` flag) — global level. It's better to immediately specify that we're running **Unit** tests and don't need to go into **Acceptance**. This will cut out a large chunk of work for the next level. |
| 16 | + |
| 17 | +2. **File path** (`--path` flag) — works at the Finder level, when the folder and file structure is simply scanned. Supports wildcards (asterisks, question marks, etc.). |
| 18 | + |
| 19 | +3. Tokenization. Files that passed the previous filters begin to be read and split into tokens. |
| 20 | + |
| 21 | + These tokens are used to search for function, method, and class names. This is not yet file execution and reflection is unavailable here, but we can already understand whether there are tests in these files. |
| 22 | + |
| 23 | + At this stage, the **name filter** for a test or test case works (in CLI: `--filter` flag). |
| 24 | + |
| 25 | + You can specify a short name of a function, method, class, or together (`UserTest::testCreate`), or FQN (fully qualified name) of a function/class/method. |
| 26 | + |
| 27 | +4. After tokenization, files are executed by PHP so we can work with reflection. |
| 28 | + |
| 29 | + At the reflection level, the filter system performs its final actions: it doesn't let through tests or cases that don't match the name filter. |
| 30 | + |
| 31 | +**Filters can be combined.** |
| 32 | + |
| 33 | +Same-type filters are combined with **OR** operator, different-type filters with **AND** operator. |
| 34 | + |
| 35 | +For example: |
| 36 | + |
| 37 | +- if you specify only two files, both will be executed, since they pass the criteria (File1 OR File2) |
| 38 | + |
| 39 | +- if you specify a file path and the name `simpleTest`, only simpleTest from the specified file will be executed. |
| 40 | + |
| 41 | +**Plugin** |
| 42 | + |
| 43 | +On the [plugin](https://plugins.jetbrains.com/plugin/28842-testo) side, you can now click on a test case, a test, or a file and run only what's selected. And [@xepozz](https://boosty.to/xepozz) also added the ability to hide unnecessary stack traces under a spoiler. Looks amazing and very convenient. |
| 44 | + |
| 45 | + |
0 commit comments