Get started with PHPUnit and learn how to write and test code using advanced technologies This book is a practical guide featuring a step-by-step approach that aims to help PHP developers who want to learn or improve their software testing skills. It also takes you through many real-life examples encountered by PHP developers to help you avoid common pitfalls. The ability to write unit tests and software testing have become skills that every PHP developer should master. This book is a practical guide to PHPUnit and unit testing, covering all aspects of writing PHPUnit tests and using them. The book shows why testable code is better code and how to write good tests with the help of simple and easy-to-understand examples. With this book, you will learn how to write, organize, and execute effective tests. Step-by-step techniques of how to write testable code, how to refactor the code, and how to run your tests are shown. You will also learn about advanced testing techniques, including how to test databases, APIs, and legacy code. PHPUnit Essentials is a guide for PHP developers who want to learn or improve their software testing skills. It is a book for developers who begin with testing but is also a good source of information for developers who are already familiar with PHPUnit.
PHPUnit Essentials by Zdenek Machek is a modern and complete book about PHPUnit usage. I've been sent an electronic copy by Packt Publishing and am now reviewing it here.
The first thing that struck me about the book was the breadth of subjects: you start from mocks and command line options, to get even to Selenium usage. You have to know your tools and given PHPUnit being a standard, this is all knowledge that will accompany you for several years.
Every book on PHPUnit must be compared with the wonderful manual, to see what it adds to the picture with respect to the documentation. PHPUnit Essentials, in this respect, looks also at 3rd party libraries such as mocking libraries or "competitors" such as PHPSpec to enlarge the picture to the whole open source PHP landscape. This is something the documentations of single projects cannot do, and where a bit of opinionated advice can be taken.
There is a bit of what may seem outdated information in the book such as how to perform a PEAR-based installation, but it's identified as such (PEAR being deprecated and dismissed by the end of the year.) Another seemingly outdated tool is Selenium IDE, but once upgraded with a formatter for Selenium2TestCase like explained in this book it becomes usable again. This kind of advice demonstrates the real world experience of the author and makes you trust the content.
On the whole by reading this book you go in as a naive tester and you come out with lots of skills on using PHPUnit in different scenarios; so I would recommended it to programmers wanting to dive into testing PHP applications. Probably it's not worth a read for the medium-to-advanced users, for which most of the content is already known from PHPUnit manual or personal experience. After all the book's named Essentials, so it delivers all that you expect from the title in a convenient single package.
In the past few years I have worked on many projects that involved implementing a testing infrastructure, I have spoken at conferences on the important of and theories of testing, and I have led workshops training beginners in testing. In all that time I have looked for a good concise and easy to read resource to share with people. PHPUnit Essentials by Zdenek Machek meets and exceeds my expectations.
Machek starts the book out by walking through the available installation methods and then moves into tools, in particular IDEs. Several popular open source and commercial IDEs are reviewed including: NetBeans, Zend Studio, Eclipse, and PhpStorm. Machek walks through the process of setting up PHPUnit in each IDE and running simple tests to get you started.
Machek goes into the basics of testing but the real power of this book lies in the thorough review of the more advanced testing concepts that many resources shy away from. Starting with theory on how to write good testable code all the way to testing databases, the following topics are covered: dependencies, in depth command line usage, test isolation, dealing with globals and data providers, test organization, test doubles (fakes, stubs, mocks, expectations, and proxies), database testing, API testing, and testing legacy (spaghetti) code. As a bonus Machek tossed in chapters on functional tests in the web browser, continuous integration, behavior-driven testing, and even a section on PHPUnit alternatives.
This is a small book but it is packed with a powerful amount of information and excellent code examples. It is a must have on any PHP developers bookshelf.