我是Ant的新手,到目前为止,我能够在Ant构建中成功创建phplint任务。现在我正在尝试将phpunit集成到ant build中。当我运行测试时,phpunit正在自行运行。但是当我通过ant build运行它时,我会遇到异常。
的build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="php-automate-build-ant" default="full-build">
<property name="phpunit" value="phpunit"/>
<target name="composer" description="Install composer packages including require-dev.">
<get src="https://getcomposer.org/download/1.2.1/composer.phar" dest="composer.phar"/>
<exec executable="php" failonerror="true">
<arg value="${basedir}/composer.phar"/>
<arg value="install"/>
<arg value="--prefer-dist"/>
<arg value="--no-progress"/>
</exec>
</target>
<target name="lint" unless="lint.done" description="Perform syntax check of PHP sourcecode files.">
<apply executable="php" failonerror="true" taskname="lint">
<arg value="-l"/>
<fileset dir="${basedir}/application">
<include name="**/*.php"/>
<exclude name="**/tests/**" />
<!-- modified/ -->
</fileset>
</apply>
<property name="lint.done" value="true"/>
</target>
<target name="phpunit"
unless="phpunit.done"
description="Run unit tests with PHPUnit">
<exec executable="${phpunit}" resultproperty="result.phpunit" taskname="phpunit">
<arg value="--configuration"/>
<arg path="${basedir}/application/tests/phpunit.xml"/>
</exec>
<property name="phpunit.done" value="true"/>
</target>
<target name="full-build" depends="phpunit,-check-failure"
description="Perform static analysis.">
<echo message="Done"/>
</target>
<target name="-check-failure">
<fail message="PHPUnit did not finish successfully">
<condition>
<not>
<equals arg1="${result.phpunit}" arg2="0"/>
</not>
</condition>
</fail>
</target>
</project>
文件夹结构
hocamose3
--application
----tests
------phpunit.xml
例外
$ ant -v
Apache Ant(TM) version 1.10.1 compiled on February 2 2017
Trying the default build file: build.xml
Buildfile: C:\xampp\htdocs\hocamose3\build.xml
Detected Java version: 1.8 in: C:\Program Files\Java\jdk1.8.0_121\jre
Detected OS: Windows 10
parsing buildfile C:\xampp\htdocs\hocamose3\build.xml with URI = file:/C:/xampp/htdocs/hocamose3/build.xml
Project base dir set to: C:\xampp\htdocs\hocamose3
parsing buildfile jar:file:/C:/Program%20Files%20(x86)/apache-ant-1.10.1-bin/apache-ant-1.10.1/lib/ant.jar!/org/apache/tools/ant/antlib.xml with URI = jar:file:/C:/Program%20Files%20(x86)/apache-ant-1.10.1-bin/apache-ant-1.10.1/lib/ant.jar!/org/apache/tools/ant/antlib.xml from a zip file
Build sequence for target(s) `full-build' is [phpunit, -check-failure, full-build]
Complete build sequence is [phpunit, -check-failure, full-build, composer, lint, ]
phpunit:
[phpunit] Current OS is Windows 10
[phpunit] Executing 'phpunit' with arguments:
[phpunit] '--configuration'
[phpunit] 'C:\xampp\htdocs\hocamose3\application\tests\phpunit.xml'
[phpunit]
[phpunit] The ' characters around the executable and arguments are
[phpunit] not part of the command.
BUILD FAILED
C:\xampp\htdocs\hocamose3\build.xml:31: Execute failed: java.io.IOException: Cannot run program "phpunit" (in directory "C:\xampp\htdocs\hocamose3"): CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
at java.lang.Runtime.exec(Runtime.java:620)
at org.apache.tools.ant.taskdefs.launcher.Java13CommandLauncher.exec(Java13CommandLauncher.java:58)
at org.apache.tools.ant.taskdefs.Execute.launch(Execute.java:426)
at org.apache.tools.ant.taskdefs.Execute.execute(Execute.java:440)
at org.apache.tools.ant.taskdefs.ExecTask.runExecute(ExecTask.java:629)
at org.apache.tools.ant.taskdefs.ExecTask.runExec(ExecTask.java:670)
at org.apache.tools.ant.taskdefs.ExecTask.execute(ExecTask.java:496)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:435)
at org.apache.tools.ant.Target.performTasks(Target.java:456)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1405)
at org.apache.tools.ant.Project.executeTarget(Project.java:1376)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1260)
at org.apache.tools.ant.Main.runBuild(Main.java:857)
at org.apache.tools.ant.Main.startAnt(Main.java:236)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:287)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:113)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(ProcessImpl.java:386)
at java.lang.ProcessImpl.start(ProcessImpl.java:137)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
... 24 more
Total time: 0 seconds
中的说明操作