Features Releases

PHPUnit composite configuration scope

PhpStorm 2018.2 comes with an extra level of flexibility for working with PHPUnit tests. Previously, you could run either a single method in a class, or all methods at once. Now, PhpStorm also lets you run an arbitrary selection of tests.

To get started, right-click your test target, that is, a class or a method being tested, and invoke Go To | Test or press Control+Shift+T (⇧⌘T for macOS). Then, select several tests to be executed by using Ctrl ( for macOS) and Shift keys.

To run your selection, use the provided keyboard shortcut (Control+Shift+F10 for Windows and ⌃⇧R for macOS):

selecting_tests_to_run

As always, when a test session is over, PhpStorm will automatically create a temporary run/debug configuration.

run_debug_config_created

Let’s take a look at what’s inside. On the Run/Debug Configuration screen, notice a new Composite option under Test scope. Having chosen it, we can make the test runner execute the tests based on the arbitrarily provided tests patterns, that is, classes, methods, or datasets:

composite_run_debug_config_screen

The patterns that we’ve initially run are already in place. To modify the selection, for example, to add some new test patterns to it, click +. Then, simply search for desired tests or locate them within your project files. PhpStorm is smart enough to detect the test patterns base directory path automatically based on your project structure. But if necessary, simply select the Use alternative patterns base path checkbox and provide the directory to search for test patterns in.

If the chosen test method uses a data provider, you can refer to it in the Data set field. Note that in the case of several data sets, you need to create a separate pattern entry for each of them. Both numbered and named data sets are supported.

To refer to a numbered data set, simply provide its index. You can freely omit the preceding number sign (#), in which case PhpStorm will insert it automatically in the resulting pattern:

Add a named data set

Similarly, to refer to a named data set, provide its name in the Data set field. There’s no need to enclose the name in quotes: PhpStorm will add them automatically. If you do provide the quotes, though, the unnecessary extra ones will be trimmed. Moreover, if the data set’s name itself contains quotes, they will be escaped properly:

Add a numbered data set

Speaking of data sets, composite test scopes will also save you a lot of time and effort when you need to rerun some failed data sets. Previously, your only option was to rerun either a single failed dataset, or the entire test.

In PhpStorm 2018.2, you can simply click Rerun failed tests in the Run tool window: this will do the trick and only run the failed data sets:

Add a named data set

Your JetBrains PhpStorm Team
The Drive to Develop

image description