O'Reilly logo

PHPUnit Pocket Guide by Sebastian Bergmann

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 13. PHPUnit and Phing

Phing (PHing Is Not GNU make) [7] is a project-build system based on Apache Ant.[8] In the context of PHP, you do not need to build and compile your sources; the intention of Phing is to ease the packaging, deployment, and testing of applications. For these tasks, Phing provides numerous out-of-the-box operation modules ("tasks") and an easy-to-use, object-oriented model for adding your own custom tasks.

Phing can be installed using the PEAR Installer, as shown in the following command line:

	pear install http://phing.info/pear/phing-2.1.0-pear.tgz

Phing uses simple XML build files that specify a target tree where various tasks are executed. One out-of-the-box task that comes with Phing is the <phpunit2> task that runs test cases using the PHPUnit framework. It is a functional port of Apache Ant's JUnit task.

Example 15 shows a Phing build.xml file that specifies a <project> named BankAccount. The project's default <target> is called test. Using the <phpunit2> task, this target runs all test cases that can be found in source files that match the *Test.php condition. This is done by using a <batchtest> element that collects the included files from any number of nested <fileset> elements. In this example, the tests declared in the class BankAccountTest in the source file BankAccountTest.php will be run.

Example 15. Phing build.xml file for the BankAccount tests

<?xml version="1.0"?> <project name="BankAccount" basedir="." default="test"> <target name="test"> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required