Search code examples
antbuildphpunitbuild.xml

Ant build.xml phpunit


I have a ant build.xml (below). I am able to run phpunit fine from the command line as follows:

D:> phpunit --verbose --testdox-html logs\today.html runtest

This runs all my phpunit tests within the folder d:\runtest.

My problem is when I run my build.xml as 'ant build' it tries to execute a file called runtest.php the output from ant is below:

D:\>ant build
Buildfile: D:\build.xml

check_os:

if_windows:

if_unix:

prepare:

phpunit:
     [exec] PHPUnit 3.6.11 by Sebastian Bergmann.
     [exec]
     [exec] Cannot open file "runtest.php".

BUILD FAILED
D:\build.xml:48: exec returned: 1

Total time: 2 seconds

My Build.xml is as follows:

<!-- This project launches the test generator and execute all phpunit selenium tests -->
<project name="proj" default="build" basedir="">
<!--Get environment variables -->
<property environment="env" />
<property name="logFolder" value="${basedir}\logs"/>
<property name="testFolder" value="${basedir}\runtest"/>

<property name="test" value="**" />
<condition property="pattern" value="runtest/*.php">
<os family="windows" />
</condition>

<tstamp/>

<!-- Check Operating system to set phpunit path-->
<target name="check_os">
<condition property="isWindows">
<os family="windows" />
</condition>
<condition property="isLinux">
<os family="unix" />
</condition>
</target>

<target name="if_windows" depends="check_os" if="isWindows">
<property name="exe.phpunit" value="C:\\Program Files\\PHP\\phpunit.bat"/>
</target>

<target name="if_unix" depends="check_os" if="isLinux">
<property name="exe.phpunit" value="${env.PHP_HOME}/includes/PHPUnit-3.2.0/PHPUnit" />
</target>

<target name="prepare" depends="if_windows, if_unix">
<mkdir dir="${logFolder}"/>
</target>

<target name="phpunit">
<!-- Check if folder empty -->
<fileset id="fileset.test" dir="${testFolder}">
<include name="*.*"/>
</fileset>
<fail message="Files not found">
<condition>
<resourcecount refid="fileset.test" when="less" count="1"></resourcecount>
</condition>
</fail>
<!-- Execute phpunit tests -->
<exec executable="${exe.phpunit}" failonerror="true" dir="runtest">
<arg line="--verbose --testdox-html '${logFolder}\phpunit-report-${TODAY}.html' runtest" />
</exec>
</target>

<target name="build" depends="prepare,phpunit"/>
</project>

Solution

  • The problem was I specified dir="runtest" once I removed this from the Execute line it worked.