0

How can I debug a custom module in Drupal 7 using Xdebug and PHPUnit? That is, I would like to debug and perhaps write some unit tests to eliminate some basic potential problems.

This is a code I inherited that is misbehaving. I am relatively new to Drupal but have some PHP skills.

Any advice is appreciated.

closed as too broad by Kevin, Shawn Conn, Adrian Cid Almaguer, Clive Oct 4 '16 at 19:09

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • I'd look for tutorials using PHPUnit & XDebug with Drupal as a first step, try those out, and ask a question if you have during following those tutorials. Right now, this question is too broad to have any answer that would be off topic (we don't do tutorials on Drupal answers). – Shawn Conn Oct 4 '16 at 18:37
  • Thanks. I am literally just starting out with this so am probably asking for setup and possible tools to use. – ArtforLife Oct 4 '16 at 18:38
4

xdebug must be added in the PHP env. Acquia Dev Desktop, DrupalVM, Vlad and other VMs come with it out of the box. As for setting the connection up, IDEs like PHPStorm, Atom and VSCode have walkthroughs on how to do that.

For PHPUnit in Drupal 7, it is doable, but not easy. There are a few articles out there that can show you how, but they may be dated. There are two paths, using SimpleTest, and using PHPUnit on it's own.

See:

To be honest, I got going with the articles from 2008 and 2012 respectively. It requires a bootstrap file (that requires and bootstraps Drupal) that you can require in your unit test classes - this allows you to use PHPUnit bare metal.

However, you should really evaluate the tests you are doing. If they truly are unit tests and you're familiar and comfortable with PHPUnit, go for it. But if you can achieve it via SimpleTest, that may be an easier road in Drupal 7. DrupalUnitTestCase is meant for that.

  • Can't upvote yet, but much appteciated :-) – ArtforLife Oct 4 '16 at 18:40
  • Also, are you saying that it is possible to debug a remote server using proper IDE? Or is it always the local environment that gets debugged? – ArtforLife Oct 4 '16 at 19:17
  • I always use remote php interpreter and xdebug via DrupalVM w PHPStorm. So, yes. – Kevin Oct 4 '16 at 19:23

Not the answer you're looking for? Browse other questions tagged or ask your own question.