Setting up PhpStorm, Xdebug to work with WordPress PHPUnit Testing

I’m a huge fan of using Xdebug and recently I ran into some issues with writing PHPUnit tests for my WordPress theme.  It took me longer to debug than usual because I couldn’t get PhpStorm to stop at my debug breakpoint.  Actually, I couldn’t get Xdebug to work at all — if I had Xdebug enabled, PHPUnit wouldn’t even run — it would just hang.

I tracked the issue down to this line in tests/bootstrap.php

system( WP_PHP_BINARY . ' ' . escapeshellarg( dirname( __FILE__ ) . '/install.php' ) . ' ' . escapeshellarg( $config_file_path ) . ' ' . $multisite );

A Google search brought me to this closed WP Core trac ticket.

That ticket has a helpful suggestion, which I hope to immortalize here, as it is the solution to this problem.

Max. Simultaneous Connections Setting

The solution is to change the Max. simultaneous connections setting, which can be found in Default preferences -> Languages and Frameworks -> PHP -> Debug.

Increase the phpStorm max connections setting to get xdebug to work.

“Configure Php Include Paths”

The default setting is 1, change it to 3 or more!

Tada!!

If that doesn’t solve your problem instantly, then I shall ask, did you Configure php include paths so that the phpunit files are included?  Also, depending on your development environment, you may need to set up path mappings so that PhpStorm knows how the server files are mapped to your local ones.

Happy testing!

Leave a Reply

Your email address will not be published. Required fields are marked *