Chapter 8. Testing

Hacks 79–85: Introduction

Application testing—and squeezing that testing into what are almost always strenuous development cycles—has been a hot topic in recent years. This chapter starts with unit tests, which test an application’s individual functions and classes. Then we’ll move on and cover automatic generation of unit tests, as well as the testing of an application through alternate means. You’ll code up robots that make HTTP requests to a server and tests that use Internet Explorer automation for checking a web interface for problems.

Test Your Code with Unit Tests

Use PHPUnit and PHPUnit2 to test your code continuously.

PHP is quietly becoming a force in enterprise application development. With larger applications come more complexity and requirements for testing in an attempt to make sure that the application is stable. It’s a truism that stable applications are built by creating a multitiered structure, with each layer well tested on its own. For example, you might have a self-contained database layer (that is tested) that sits underneath a business logic layer (that is tested), which in turn is used by the user interface layer (that is also tested). Starting to get the idea?

To test each layer, it has become common practice to create unit tests. These are tests that are run after any code change and before any code is checked in (you are using version control on your enterprise projects, aren’t you?). In fact, it’s common to insist that ...

Get PHP Hacks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.