Skip to content

Commit

Permalink
[2.0] Refactoring of build.xml to generate coverage xml optionally vi…
Browse files Browse the repository at this point in the history
…a build.properties. Also added option to set the phpunit xml configuration file.
  • Loading branch information
beberlei committed Feb 7, 2010
1 parent 724ae31 commit 4585c8f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
4 changes: 3 additions & 1 deletion build.properties.dev
Expand Up @@ -5,4 +5,6 @@ build.dir=build
dist.dir=dist
report.dir=reports
log.archive.dir=logs
svn.path=/usr/bin/svn
svn.path=/usr/bin/svn
test.phpunit_configuration_file=
test.phpunit_generate_coverage=0
24 changes: 13 additions & 11 deletions build.xml
Expand Up @@ -63,6 +63,9 @@
</fileset>

<target name="clean">
<available file="./build.properties" property="build_properties_exist" value="true"/>
<fail unless="build_properties_exist" message="The build.properties file is missing." />

<delete dir="${build.dir}" includeemptydirs="true" />
<delete dir="${dist.dir}" includeemptydirs="true" />
<delete dir="${report.dir}" includeemptydirs="true" />
Expand Down Expand Up @@ -122,19 +125,18 @@
Runs the full test suite.
-->
<target name="test" depends="prepare">
<!--<phpunit printsummary="true" haltonfailure="true" haltonskipped="false" haltonincomplete="false" haltonerror="true">
<formatter todir="${build.dir}/logs" type="xml"/>
<batchtest classpath="tests">
<fileset dir="tests">
<include name="**/*Test.php" />
<exclude name="**/*Performance*.php" />
</fileset>
</batchtest>
</phpunit>
-->
<if><equals arg1="${test.phpunit_generate_coverage}" arg2="1" />
<then>
<property name="test.phpunit_coverage_file" value="${build.dir}/logs/clover.xml" />
</then>
<else>
<property name="test.phpunit_coverage_file" value="false" />
</else>
</if>

<nativephpunit
testfile="./tests/Doctrine/Tests/AllTests.php" junitlogfile="${build.dir}/logs/testsuites.xml"
testdirectory="./tests" coverageclover="${build.dir}/logs/clover.xml"
testdirectory="./tests" coverageclover="${test.phpunit_coverage_file}" configuration="${test.phpunit_configuration_file}"
/>
<phpunitreport infile="${build.dir}/logs/testsuites.xml" format="frames" todir="${report.dir}/tests" />

Expand Down
16 changes: 15 additions & 1 deletion tools/NativePhpunitTask.php
Expand Up @@ -44,14 +44,26 @@ public function setTestfile($testfile) {
}

public function setJunitlogfile($junitlogfile) {
if (strlen($junitlogfile) == 0) {
$junitlogfile = NULL;
}

$this->junitlogfile = $junitlogfile;
}

public function setConfiguration($configuration) {
if (strlen($configuration) == 0) {
$configuration = NULL;
}

$this->configuration = $configuration;
}

public function setCoverageClover($coverageClover) {
if (strlen($coverageClover) == 0) {
$coverageClover = NULL;
}

$this->coverageClover = $coverageClover;
}

Expand Down Expand Up @@ -92,7 +104,7 @@ public function main()
$printer = new NativePhpunitPrinter();

$arguments = array(
'configuration' => $this->configurationFile,
'configuration' => $this->configuration,
'coverageClover' => $this->coverageClover,
'junitLogfile' => $this->junitlogfile,
'printer' => $printer,
Expand All @@ -114,7 +126,9 @@ public function main()
$this->log("PHPUnit Success: ".count($result->passed())." tests passed, no ".
"failures (".$result->skippedCount()." skipped, ".$result->notImplementedCount()." not implemented)");

// Hudson for example doesn't like the backslash in class names
if (file_exists($this->coverageClover)) {
$this->log("Generated Clover Coverage XML to: ".$this->coverageClover);
$content = file_get_contents($this->coverageClover);
$content = str_replace("\\", ".", $content);
file_put_contents($this->coverageClover, $content);
Expand Down

0 comments on commit 4585c8f

Please sign in to comment.