Skip to main content
Start of main content.

Native PHPStorm Drupal Test Runner

by jibran.ijaz /

Share this post on social media

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.

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.