PHPUnit is a unit testing framework, written in PHP, and which is used to test PHP code. You can integrate the testing that PHPUnit does into Phing. You might want to use Phing to create a nightly build that contains the latest version of your program. The last thing you want is Phing to create a nightly build that is riddled with errors.
The way around this is to use PHPUnit to test our code whilst we are running Phing. If any tests fail then Phing will not finish the build.
Create a target at the top of your build.xml file and make sure it is run first. Then add the following code to the target, This will use PHPUnit to test your code.
- <phpunit haltonfailure="true" haltonerror="true">
- <fileset dir="tests">
- <include name="**/*Test*.php"/>
The phpunit element contains an element called batchtest, which can contain one or more fileset elements. It is the files defined by the fileset elements that define which files are to be used in the testing. The code above includes all PHP files that have the word Test in their name.
The phpunit element contains two attributes called haltonfailure and haltonerror. These attributes will cause the build to exit if any errors or failed tests are found during the testing.