PHPUnit Essentials by Zdenek Machek – a book review

(Disclosure: I received an advance copy of this book from Packt Publishing for review purposes.)

The more complex a software development project becomes, the harder it becomes to ensure that every single component keeps working as it should throughout the whole development process. As each passing year the average complexity of software goes up, automated testing is slowly becoming the most cost effective way to reign in some of that complexity. By providing reassurance that the latest changes to the code did not break existing functionality, it allows for quicker iterations, higher code quality, and less time wasted in debugging. As the de-facto standard in unit and functional testing for PHP, PHPUnit is increasingly becoming an indispensable part of the web developer’s toolkit, and PHPUnit Essentials by Zdenek Machek is a pretty solid introduction to it for intermediate-level PHP developers.

The book is effectively about 300 comfortably spaced pages, divided into 14 chapters. It has a rather broad scope, covering not only basic PHPUnit installation and usage, but also related interoperable technologies such as advanced test doubles extensions, Selenium (for web browser testing), XDebug (for code coverage analysis), Continuous Integration services, and even IDE support for some popular PHP IDEs. For me this wide scope is one of the two great strengths of this book; since web developers never work in a vacuum, chances are that if you’re learning to use PHPUnit, sooner or later you will also need to learn how to use some of the complementary technologies described in this book. While it might not go into the greatest detail with most of them, it will at least teach you to set them up, integrate them with PHPUnit, and their basic usage.

The other great strength of this book is that it explains, in an easy to understand manner, some more advanced concepts such as different types of test doubles, database testing, and how to test legacy (a.k.a. “untestable”) code. The chapter on legacy code stands out as it provides some very useful approaches to introduce automated testing to the type of code that needs it the most.

As for weaknesses, my main complaint would be that the book sometimes fails to go into enough depth in some topics. The biggest omission would be an overview of all, or at least most, of the PHPUnit annotations and assertion methods. I know the official PHPUnit documentation already includes that as an appendix, but it would be nice to have it here at least in a table with short descriptions as a reference. Also, running PHPUnit on a remote server, as opposed to localhost, is not really explored outside of Continuous Integration services (which basically do that for you), and BDD is only explored through other testing frameworks or extensions. Finally, as far as complaints go, mentioning how “Codeception is really awesome… but we’re not going to write about it”, at the summary of the very last chapter, made me feel a little bit cheated.

Overall, the writing style is easily understandable, though at times it can feel a little bit redundant. The good thing is that it doesn’t make you backtrack to look at previous code like some other very frustrating books out there (I swear, it’s as if their authors have never used a tablet or eReader to read an ebook in their entire lives). It may fail to go into enough detail in a couple of places, but the simple explanations of advanced testing concepts, along with the discussion of useful related technologies, make PHPUnit Essentials a quite solid introduction to not only PHPUnit, but the world of TDD as a whole.

Leave a Reply

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