Testing improvements in PhpStorm 2018.1
PhpStorm 2018.1 brings several improvements to streamline and simplify your work with PHPUnit tests. You can now create target classes from tests, annotate your tests easily, and run the tests using the code editor gutter icons. Let’s take a closer look at the new features.
Creating a class and class methods from a test
In PhpStorm, creating a test from a class is as simple as pressing Ctrl+Shift+T (Cmd+Shift+T on macOS). With TDD becoming more and more popular, it may happen that the test is already in place, but the class being tested does not exist yet.
To handle such situations, PhpStorm 2018.1 introduces the Missing target element for PHPUnit test inspection and the corresponding quick-fix. The inspection will detect if a class or a method being tested is not yet created. To fix this, simply position the caret on an element, invoke the quick-fix by pressing Alt-Enter, and execute the required command:
PhpStorm will generate the missing elements in their respective locations, taking your PSR-0/PSR-4 structure into account.
As with other inspections, the Missing target element for PHPUnit test inspection can be used for applying changes in bulk. Simply invoke Run inspection by name and select the inspection:
Improved @covers support
In PhpStorm 2018.1, we’ve significantly enhanced the support for the PHPUnit @covers and @coversDefaultClass annotations.
As soon as you provide the @coversDefaultClass annotation for a test class, name completion will become available:
With the covered class in place, PhpStorm will pick out the relevant class methods to annotate with @covers and suggest auto-completion for them. The new inspection will also detect all usages of @covers with methods and functions not prepended with :: (the scope resolution operator).
By invoking code completion (CMD/CTRL+Space) twice, you can also complete visibility modifiers, which will allow you to specify what the annotated test method covers, for example, all the non-public methods of a class.
Navigating to tests
Since both the target methods and the @covers annotations are in place, it has become possible to navigate from a method to all test methods that cover it. Simply position the caret on a method and invoke the Navigate to Test action. This way, you can create new tests, too:
Test method names auto-completion
PhpStorm 2018.1 also provides automatic completion of test method names. If, say, methodC has been added to the above example class, it will be detected from within the test class. As a result, you can create the corresponding test method stub with a conventional name in a matter of seconds:
Gutter icons for running tests
In earlier PhpStorm versions, running tests from the code editor was only possible with the help of the excellent PHPUnit Enhancement plugin. In PhpStorm 2018.1, this functionality is implemented natively. Using the gutter icons, you can invoke the Run, Debug, and Run with Coverage actions for PHPUnit tests:
Gutter icons work both for Local and Remote Interpreters, and reflect the previous tests execution state: passed, failed, or not started.
Stay tuned for more updates!
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…