Yesterday kore asked me about a strange behavior of phpUnderControl. The last arbit build done by phpUnderControl has failed, but when we looked over the different result pages everything looks fine.
Strange! What has happened?
After an analysis session of the 6MB XML log file I detected the following self explaining entry. The PHPUnit tests for arbit had completely failed.
<?xml version="1.0" encoding="UTF-8"?>
<cruisecontrol>
...
<build error=".../arbit/build.xml:20: exec returned: 255" time="12 minutes 56 seconds">
...
<target name="phpunit" time="1 second">
<task location=".../arbit/build.xml:20: " name="exec" time="1 second">
<message priority="debug"><![CDATA[Current OS is Linux]]></message>
<message priority="debug"><![CDATA[Executing 'phpunit' with arguments:
'--log-xml'
'build/logs/phpunit.xml'
'--log-pmd'
'build/logs/phpunit.pmd.xml'
'--log-metrics'
'build/logs/phpunit.metrics.xml'
'--coverage-xml'
'build/logs/phpunit.coverage.xml'
'--coverage-html'
'build/coverage'
'arbitTestSuite'
'source/tests/suite.php'
The ' characters around the executable and arguments are
not part of the command.]]></message>
<message priority="info"><![CDATA[Fatal error: main(): Failed opening required 'modules_tracker_suite.php' (include_path='.../arbit/source/src/:.../arbit/source/src/libraries/:.:.../php-5.3-cvs/lib/php') in .../arbit/source/tests/suite.php on line 0]]></message>
<message priority="info"><![CDATA[Call Stack:]]></message>
<message priority="info"><![CDATA[0.0005 318436 1. {main}() .../php-5.3-cvs/bin/phpunit:0]]></message>
<message priority="info"><![CDATA[0.2345 542264 2. require('.../php-5.3-cvs/lib/php/PHPUnit/TextUI/Command.php') .../php-5.3-cvs/bin/phpunit:44]]></message>
<message priority="info"><![CDATA[1.0595 5278380 3. PHPUnit_TextUI_Command::main() .../php-5.3-cvs/lib/php/PHPUnit/TextUI/Command.php:528]]></message>
<message priority="info"><![CDATA[1.0616 5294940 4. PHPUnit_Runner_BaseTestRunner->getTest() .../php-5.3-cvs/lib/php/PHPUnit/TextUI/Command.php:90]]></message>
<message priority="info"><![CDATA[1.0617 5295224 5. PHPUnit_Runner_BaseTestRunner->loadSuiteClass() .../php-5.3-cvs/lib/php/PHPUnit/Runner/BaseTestRunner.php:200]]></message>
<message priority="info"><![CDATA[1.0617 5295508 6. PHPUnit_Runner_StandardTestSuiteLoader->load() .../php-5.3-cvs/lib/php/PHPUnit/Runner/BaseTestRunner.php:269]]></message>
<message priority="info"><![CDATA[1.0828 5295792 7. PHPUnit_Util_Fileloader::checkAndLoad() .../php-5.3-cvs/lib/php/PHPUnit/Runner/StandardTestSuiteLoader.php:97]]></message>
<message priority="info"><![CDATA[1.1736 5296168 8. PHPUnit_Util_Fileloader::load() .../php-5.3-cvs/lib/php/PHPUnit/Util/Fileloader.php:105]]></message>
<message priority="info"><![CDATA[1.1746 5328364 9. include_once('.../arbit/source/tests/suite.php') .../php-5.3-cvs/lib/php/PHPUnit/Util/Fileloader.php:120]]></message>
</task>
</target>
</build>
...
</cruisecontrol>
Ok, the test run failed, but why did phpUnderControl say: All Tests passed?
The answer is really simple. Due to the fact that phpunit died, it didn't generate any log file and previous log files still reside in build/logs. Because CruiseControl cannot know anything about these outdated build artifacts, it still publishes them as result for last build.
At this moment I realized that I have never mentioned a clean-target for the ant build.xml file, neither in the example file nor in a blog post or the FAQ. So now its time to catch up on this topic.
You should add an additional target to your ant build.xml file, that removes all log files and build artifacts of previous builds, before the main build cycle starts.
<?xml version="1.0" encoding="UTF-8"?>
<project name="phpundercontrol.org" default="build" basedir=".">
...
<target name="clean">
<!-- Remove old log files -->
<delete>
<fileset dir="${basedir}/build/logs" includes="**.*" />
</delete>
<!-- Remove old api documentation -->
<delete>
<fileset dir="${basedir}/build/api" includes="**.*" />
</delete>
<!-- Remove old coverage report -->
<delete>
<fileset dir="${basedir}/build/coverage" includes="**.*" />
</delete>
</target>
<target name="build"
depends="clean,checkout,php-documentor,php-codesniffer,phpunit" />
...
</project>
That's it. Now you will get the expected(not really) result: No Tests Run - This project doesn't have any tests.