Skip to main content

Native PHPStorm Drupal Test Runner

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.

by Jibran Ijaz /

Introduction

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.

My @phpstorm run configs to run PhantomJS, PHP built-in server, and PHPUnit with a click of a button https://t.co/2hPGPr78QN

— Matt Glaman (@nmdmatt) May 28, 2016

After our conversation Matt created a PHPStorm plugin which executes Drupal's test runner. PHPStorm Drupal's test runner allows to run Simpletest, Unit, Kernel, Functional, and FunctionalJavascript tests with just one single click.

Installation

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.

 

Configuration

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.

 

Execution

Now you can run this class and when the test is finished you can view the results inside the PHPStrom.

 

Debugging

Yes, you can also debug tests by enabling PHP CLI scripts debugging with PhpStorm.

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.

What's next?

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.

Posted by Jibran Ijaz
Senior Drupal Developer

Dated

Comments

Comment by Matt Glaman

Dated

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.

Comment by Jibran Ijaz

Dated

Thanks for the feedback much appreciated.

Comment by Justin Winter

Dated

Wow - I've been trying to get this working for a while now. Great post and great plugin! thank you sir.

Pagination

Add new comment

Restricted HTML

  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <h2> <h3> <h4> <h5> <h6>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
Not sure where to start? Try typing "hello" or "help" if you get stuck.