0

I am using phing to build my CakePHP web application.

I want to have a phing target that goes along these lines:

  1. Run the test suite
  2. if there is even 1 failure, end the phing target
  3. if all okay, run the command "git commit -a"

For my test suite, I follow the CakePHP convention which uses PHPUnit

${cake} testsuite ${runinworkspaceapp} app AllTests --log-junit ${builddir}/logs/junit.xml

where

  • ${cake} simply means ${appdir}/Console/cake
  • ${runinworkspaceapp} means -app ${appdir}

I will generate a junit.xml file. Below is a snippet of the junit.xml

<testsuites>
  <testsuite name="All Tests" tests="44" assertions="373" failures="0" errors="0" time="4.634020">
    <testsuite name="All Model related class tests" tests="42" assertions="370" failures="0" errors="0" time="4.478717">

I suspect that I need to evaluate the junit.xml file in order to tell whether there is any error. I could be wrong and there is a better way.

How do I write the phing target?

cweiske
  • 30,033
  • 14
  • 133
  • 194
Kim Stacks
  • 10,202
  • 35
  • 151
  • 282

1 Answers1

1

Cake should exit with an exit code != 0 when at least one test failed, so using <exec> with checkreturn="true" should suffice.


junit.xml can be converted to HTML with a phing task (also see http://cweiske.de/tagebuch/visualizing-phpunit-runs.htm):

<?xml version="1.0" encoding="utf-8"?>
<project name="testreport" default="gen-report" basedir=".">
 <target name="gen-report">
  <phpunitreport infile="log.junit.xml"
                 format="frames"
                 todir="html"
                 styledir="/usr/share/php/data/phing/etc/"
                 />
 </target>
</project>
cweiske
  • 30,033
  • 14
  • 133
  • 194