Preface

For a very long time my answer to the question "When will you write documentation for PHPUnit?" has been "You do not need documentation for PHPUnit. Just read the documentation for JUnit or a buy a book on JUnit and adapt the code examples from Java and JUnit to PHP and PHPUnit." When I mentioned this to Barbara Weiss and Alexandra Follenius from the O'Reilly Germany office, they encouraged me to think it over and write a book that would serve as the documentation for PHPUnit.

Requirements

The topic of this book is PHPUnit, an open source framework for test-driven development with the PHP programming language. This edition covers Version 3.1 of PHPUnit. Most of the examples should work, however, with PHPUnit versions 2.0-3.0. The "PHPUnit for PHP 4" section, later in this book, covers the older, no longer actively developed version of PHPUnit for PHP 4.

The reader should have a good understanding of object-oriented programming with PHP 5. To German readers I can recommend my own book on PHP 5, [Bergmann2005], as an introduction to object-oriented programming with PHP 5. A good English book on the subject is [GuBaRe2005] by Andi Gutmans, Stig Bakken, and Derick Rethans.

This Book Is Free

This book is available under the Creative Commons license. You will always find the latest version of this book on its website at http://www.phpunit.de/pocket_guide/. You may distribute and make changes to this book however you wish. Of course, rather than distribute your own private version of the book, I would prefer you send feedback and patches to .

Conventions Used in This Book

The following is a list of typographical conventions used in this book:

Italic

Indicates new terms, URLs, email addresses, filenames, file extensions, pathnames, directories, and Unix utilities.

Constant width

Indicates commands, options, switches, variables, functions, classes, namespaces, methods, modules, parameters, values, objects, the contents of files, or the output from commands.

Constant width bold

Shows commands or other text that should be typed literally by the user.

Constant width italic

Shows text that should be replaced with user-supplied values.

You should pay special attention to notes set apart from the text with the following styles:

Note

This is a tip, suggestion, or general note. It contains useful supplementary information about the topic at hand.

Warning

This is a warning or note of caution.

Acknowledgements

I would like to thank Kent Beck and Erich Gamma for JUnit and the inspiration to write PHPUnit. I would also like to thank Kent Beck for his "JUnit Pocket Guide" [Beck2004], which sparked the idea for this book. I would like to thank Allison Randal, Alexandra Follenius, and Barbara Weiss for sponsoring this book at O'Reilly.

I would like to thank Andi Gutmans, Zeev Suraski, and Marcus Börger for their work on the Zend Engine 2, the core of PHP 5. I would like to thank Derick Rethans for Xdebug, the PHP extension that makes PHPUnit's Code Coverage functionality possible. Finally, I would like to thank Jan Borsodi, who is the initial developer of the Mock Objects system, Michael Lively Jr. and Jan Kneschke who helped with the Code Coverage report generator, as well as and Michiel Rook, who wrote the PHPUnit tasks for Phing.