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):
As always, when a test session is over, PhpStorm will automatically create a temporary run/debug configuration.
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:
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:
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:
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:
Your JetBrains PhpStorm Team
The Drive to Develop
Subscribe to Blog updates
Thanks, we've got you!
Qodana Clone Finder: Early Access Program
In December 2020, we announced the EAP for Qodana, which is rapidly evolving into a comprehensive platform that allows companies to perform multi-level evaluations of the quality of code they own, contract, or purchase. Qodana helps you detect bugs without relying on an IDE, either on a local machi…
PhpStorm 2020.2 EAP #3
The Early Access Program for PhpStorm 2020.2 is in full swing and today we’ve got the third build of the 2020.2 EAP for you. In this blog post, you can read about improvements for Git installed in WSL2 and Search Everywhere. Download PhpStorm 2020.2 EAP (more…)…
PhpStorm 2019.3.3 Preview
We’ve just rolled out a preview for the third minor update for PhpStorm 2019.3. Please give the PhpStorm 2019.3.3 Preview build 193.6494.5 a try and share your feedback with us. (more…)…
How to Upgrade to PHP 7.4 with PhpStorm
Check out our fresh video with a few nice tips and tricks on how to update your codebase to PHP 7.4. It combines materials from the PhpStorm 2019.2 and PhpStorm 2019.3 releases, with a few cool bonuses to boot. Nikita drew our attention to the fact that setters are slower than assigning prop…