Member-only story

My PHPUnit configuration for my Drupal projects

Matt Glaman
5 min readSep 7, 2020

The other week, I was asked about how I maintain my PHPUnit config file for my Drupal projects. When running Drupal’s PHPUnit test suites, you typically copy and modify the distribution phpunit.xml.dist file which lives in the web/core subdirectory. There is just one problem. This directory is technically a vendor directory and is replaced during any updates to the drupal/core dependency of your Drupal project. Every minor version will cause your file to reset, or anytime you install dependencies if Drupal core is patched.

One thing I noticed is that since I first followed your tuts a while back, my phpunit.xml is gone. I’m guessing it gets overwritten when core is updated. Do you just keep a copy of the file and paste it in when that happens? Is there a better solution?

I didn’t have time to answer in Slack, so now I’m writing a blog about a better solution. I’ll also share some of my settings that I use — specifically for the database and running a local webserver for functional testing.

If you want the tl;dr, here’s my XML file: https://gist.github.com/mglaman/0baf5ccd7b13b844de105286a04e43d3. If you want to learn about what gets changed and why, read on!

The Automated Testing documentation on Drupal.org says that you should copy the web/core/phpunit.xml.dist to web/core/phpunit.xml. From there you can modify environment variables that PHPUnit will initiate that the tests expect to exist – such as the database connection string and host to access…

--

--

Matt Glaman
Matt Glaman

Written by Matt Glaman

PHP software engineer, open source contributor, and speaker

No responses yet