Introducing PHPSpec in PhpStorm 2016.3
You asked, and we delivered! Brand new in PhpStorm 2016.3 is extended support for the behavior-driven design framework PHPSpec.
PHPSpec has been gaining more and more traction, and with the releases of version 3 in July took a huge leap forward regarding functionality and developer experience. We’ve had a lot of support on YouTrack (JetBrains patented issue tracking system) asking for PHPSpec support in PhpStorm, and now it’s here.
PHPSpec is, at its heart, a unit testing framework like PHPUnit with the focus shifted from defining input and output to defining behaviors. It’s a very different way to work, but an interesting concept, and one I’ve been using more and more when working on PHP projects. PhpStorm 2016.3 introduces numerous improvements which mean that PhpStorm understands the magic that allows PHPSpec to work.
Because PHPSpec’s `spec` (test) files act as a proxy around the original class, PhpStorm has never before been able to resolve the methods of the class you’re testing. Because PhpStorm now understands PHPSpec’s internal wiring, you get full code completion on your classes, complete with the ability to navigate right to the implementation as you would in any other class. This is very useful.
You can see from the above screenshot that PHPSpec allows you to chain calls from the methods of the class you’re testing to the expected return of that method. While this makes for very readable tests, it’s internal magic means that PhpStorm was never able to provide code completion for the expected result (what PHPSpec calls a `matcher`), as it would assume the return to be whatever the method all returned. The new PHPSpec plugin understands what comes after a class method call could be a matcher, and gives you code completion making writing your examples that much easier.
Finally, we’ve added a PHPSpec runner in a similar way to the PHPUnit runner that’s been widely used for many versions of PhpStorm. You can add the run configuration for PHPSpec in a similar way to PHPUnit — by selecting Edit Configurations from the Run drop-down menu, and then adding a new PHPSpec configuration. You’ll need to configure the location of your PHPSpec executable from the PHPSpec configuration pane under Languages & Frameworks.
Once set, you can quickly run your test suite using the green Run arrow as you would PHPUnit. At the moment the test runner is not interactive, and so you’ll need to run PHPSpec from the terminal if you want to take advantage of the code generation features of PHPSpec which are, after all, one of the most useful parts of PHPSpec. Expect improvements around this and describing classes to come in the future.
We’d love to hear what you think of the new PHPSpec integrations in PhpStorm 2016.3. Drop me a Tweet @GeeH and let me know what you think.
– Gary and the PhpStorm Team
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…