Prev | Next |
This chapter provides an overview of build automation tools that are commonly used with PHPUnit.
Apache Ant is a Java-based build tool. In theory, it is kind of like make, without make's wrinkles. Build files for Apache Ant are XML-based, calling out a target tree where various tasks get executed.
Example 20.1 shows an
Apache Ant build.xml file that invokes PHPUnit using the built-in
<exec>
task. The build process is aborted
if a test fails (failonerror="true"
).
Example 20.1: Apache Ant build.xml file that invokes PHPUnit
<project name="Money" default="build">
<target name="clean">
<delete dir="${basedir}/build"/>
</target>
<target name="prepare">
<mkdir dir="${basedir}/build/logs"/>
</target>
<target name="phpunit">
<exec dir="${basedir}" executable="phpunit" failonerror="true">
<arg line="--log-xml ${basedir}/build/logs/phpunit.xml MoneyTest" />
</exec>
</target>
<target name="build" depends="clean,prepare,phpunit"/>
</project>
ant
Buildfile: build.xml
clean:
prepare:
[mkdir] Created dir: /home/sb/Money/build/logs
phpunit:
[exec] PHPUnit 3.4.2 by Sebastian Bergmann.
[exec]
[exec] ......................
[exec]
[exec] Time: 0 seconds
[exec]
[exec] OK (22 tests, 34 assertions)
build:
BUILD SUCCESSFUL
Total time: 0 seconds
The XML logfile for test results produced by PHPUnit (see the section called “Test Results (XML)”) is based upon the one used by the <junit>
task that comes with Apache Ant.
Apache Maven is a software project management and comprehension tool. Based on the concept of a Project Object Model (POM), Apache Maven can manage a project's build, reporting and documentation from a central place of information. Maven for PHP uses the power of Maven for building, testing, and documenting PHP projects.
Phing (PHing Is Not GNU make) is a project build system based on Apache Ant. You can do anything with it that you could do with a traditional build system such as GNU make, and its use of simple XML build files and extensible PHP "task" classes make it an easy-to-use and highly flexible build framework. Features include file transformations (e.g. token replacement, XSLT transformation, Smarty template transformations), file system operations, interactive build support, SQL execution, CVS operations, tools for creating PEAR packages, and much more.
Example 20.2 shows a Phing
build.xml file that invokes PHPUnit using the built-in
<phpunit>
task. The build process is
aborted if a test fails (haltonfailure="true"
).
Example 20.2: Phing build.xml file that invokes PHPUnit
<project name="Money" default="build">
<target name="clean">
<delete dir="build"/>
</target>
<target name="prepare">
<mkdir dir="build/logs"/>
</target>
<target name="phpunit">
<phpunit printsummary="true" haltonfailure="true">
<formatter todir="build/logs" type="xml"/>
<batchtest>
<fileset dir=".">
<include name="*Test.php"/>
</fileset>
</batchtest>
</phpunit>
</target>
<target name="build" depends="clean,prepare,phpunit"/>
</project>
phing
Buildfile: /home/sb/Money/build.xml
Money > clean:
Money > prepare:
[mkdir] Created dir: /home/sb/Money/build/logs
Money > phpunit:
[phpunit] Test: MoneyTest, Run: 22, Failures: 0, Errors: 0,
Incomplete: 0, Skipped: 0, Time elapsed: 0.06887 s
Money > build:
BUILD FINISHED
Total time: 0.2632 seconds
Prev | Next |
assertArrayHasKey()
assertClassHasAttribute()
assertClassHasStaticAttribute()
assertContains()
assertContainsOnly()
assertEqualXMLStructure()
assertEquals()
assertFalse()
assertFileEquals()
assertFileExists()
assertGreaterThan()
assertGreaterThanOrEqual()
assertLessThan()
assertLessThanOrEqual()
assertNull()
assertObjectHasAttribute()
assertRegExp()
assertSame()
assertSelectCount()
assertSelectEquals()
assertSelectRegExp()
assertStringEndsWith()
assertStringEqualsFile()
assertStringStartsWith()
assertTag()
assertThat()
assertTrue()
assertType()
assertXmlFileEqualsXmlFile()
assertXmlStringEqualsXmlFile()
assertXmlStringEqualsXmlString()
Copyright © 2005-2010 Sebastian Bergmann.