PHPStorm has a lot of built in test runners, but it doesn't support Drupal's Simpletest test runner. In this blog post we'll see how we can execute Drupal tests inside PHPStorm using Drupal test runner.
As a Drupal 8 core developer and a back-end developer, I have to write tests all the time. PHPStorm is very handy tool when you are writing tests, because it supports a lot native test runners.
Native PHPStorm PHPUnit Test Runner
Whenever I’m writing PHPUnit test inside or outside Drupal it is very convenient to run the tests and debug the fails with just one click. If you are not familiar with this then have a look at running PHPUnit tests within PHPStorm on drupal.org or Run/Debug Configuration: PHPUnit - JetBrains.
Drupal Test Runner
Drupal uses its own test runner located under 'core/scripts/runtest.sh'. There is no native support in PHPStrom to run Drupal tests. You can execute runtest.sh as PHP script but to get the configuration right is bit tricky.
Native PHPStorm Drupal Test Runner
I recently had a chat with Matt Glaman (mglaman) on twitter about native PHPStorm Drupal Test runner when he tweeted about his one click run test configuration for Drupal 8.
— Matt Glaman (@nmdmatt) May 28, 2016
To install the plugin go to File → Settings → Plugin → Browse repositories and search Drupal Test Runner and install
After restarting the PHPStorm a new option “Drupal run test” will be available.
After clicking “Drupal run test” you’ll see following configuration form
You can configure it to run single class.
Or you can configure it for a module/group.
Now you can run this class and when the test is finished you can view the results inside the PHPStrom.
Why use this plugin? Simpletest is deperecated in Drupal 8 anyway.
This is a fair question, since Symfony components were added to Drupal 8. There are several attempts to convert core scripts to symfony console component commands. There is also an issue in which simpletest is going to be replaced by PHPUnit. Now, all the core kernel tests are executed using PHPUnit test runner and core is focusing on converting all the web tests to browser tests, web tests are executed using runtest.sh script in core and browser tests are using PHPUnit test runner for execution. One of the pre-requisites for Drupal 9 is to remove simpletest module from core but this means simpletest module will remain a part of Drupal 8 codebase, so this plugin will be useful until then.
There is also a Drupal 7 version of this plugin.
PHPStrom Drupal Test Runner is in a beta release and we need community help for a stable release so please test the plugin and create issues.
I'd like to thank Matt Glaman for considering my idea and building this amazing plugin.
Thanks for the article! Here's a comment based on Twitter feedback :)
In order to get this working, you need to have PHPStorm's Drupal integration setup. It reads the path to Drupal from there. The plugin supports discovering the test runner script by reading the Drupal version 7 or 8. So there isn't a Drupal 7 version, it just knows to look in "scripts/run-tests.sh" or "core/scripts/run-tests.hs". However all options are based on Drupal 8 version.
Wow - I've been trying to get this working for a while now. Great post and great plugin! thank you sir.