Writing Unit Tests with PHPUnit, Part 3: XML Configuration A foundational guide to understanding the PHPUnit XML Configuration file and how to tie it into easier unit testing.

In the past posts in this series, I’ve covered the following two topics:

  1. Writing Unit Tests with PHPUnit, Part 1: The Set-Up. A guide to getting started with writing PHPUnit tests through the use of a basic cache and using the setUp method of the framework.
  2. Writing Unit Tests with PHPUnit, Part 2: The Tear Down. A tutorial on how to write unit tests that properly leverage the setUp and tearDown methods of PHPUnit.

Each of the above is meant to provide a primer for how to get started with writing very basic unit tests. Things can get more complex especially as an application or project grows (but that’s always true, right?).

But to make sure one is prepared for that, there’s one final component to unit testing that I believe we should focus on and that’s understanding the PHPUnit XML Configuration File (which you may have seen in other projects as phpunit.xml).

PHPUnit XML Configuration

So in this post, I’m going to setup a simple project that uses PHPUnit, writes a few tests like the ones we’ve already seen, and leverages a configuration file to automate testing.

Furthermore, I’m going to do what I can to best explain the necessary parts of the configuration file so you can include one in your next project.

For Members Only

Thanks for your interest in this article; however, it's available to members only. If you'd like to review this (and have access to all previous and future articles), check out the sign-up page.

Further, it gives you something to build upon as your testing chops grow stronger.

Is There More? (Always, Right?)

Finally, if you’re eager to really dive into the configuration file, you can read the manual’s in-depth explanation of it.

Note, however, everything that’s outlined above aims to be what you need to get started with setting up your own PHPUnit XML Configuration file.