Skip to content

Commit

Permalink
[GH-18-TimestampableTrait] Use raw phpunit to track cc on traits.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrishalbert committed Aug 23, 2018
1 parent 0d9341b commit f87c9bd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 45 deletions.
56 changes: 14 additions & 42 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,57 +19,29 @@

<!-- Run phpunit with code coverage and generate reports -->
<target name="phpunit" description="Run phpunit tests">
<!-- Specify coverage and path to save coverage stats -->
<coverage-setup database="${reports.dir}/coverage.db">
<fileset dir="src">
<include name="**/*.php"/>
</fileset>
</coverage-setup>

<!-- Run phpunit saving data -->
<phpunit printsummary="true"
codecoverage="true"
errorproperty="phpuniterror"
failureproperty="phpunitfailure"
bootstrap="${project.basedir}/tests/bootstrap.php">
<formatter type="xml" todir="${reports.dir}" outfile="phpunit.log"/>
<formatter type="clover" todir="${reports.dir}"/>
<batchtest>
<fileset dir="${project.basedir}/tests">
<include name="**/*Test.php"/>
</fileset>
</batchtest>
</phpunit>

<!-- Generate the reports using phing -->
<phpunitreport infile="${project.basedir}/phpunit.xml" format="frames" todir="${reports.dir}"/>
<coverage-report outfile="${reports.dir}/coverage.xml">
<report toDir="${reports.dir}"/>
</coverage-report>
</target>

<!-- Make sure tests didnt fail and code coverage standards are met -->
<target name="assert" description="Assert project standards met.">
<!-- Verify that phpunit error or fail -->
<exec command="cat ${reports.dir}/phpunit.log" outputProperty="phpunitoutput"/>
<exec command="${project.basedir}/vendor/bin/phpunit -c ${project.basedir}/phpunit.xml"
returnProperty="phpunitreturn" outputProperty="phpunitoutput"/>
<if>
<or>
<equals arg1="${phpuniterror}" arg2="true"/>
<equals arg1="${phpunitfailure}" arg2="true"/>
</or>
<not>
<equals arg1="${phpunitreturn}" arg2="0"/>
</not>
<then>
<fail msg="!${line.separator}${line.separator}${phpunitoutput}" />

<fail msg="${phpunitoutput}"/>
</then>
</if>
</target>

<!-- Verify 90% Code Coverage -->
<!-- Make sure tests didnt fail and code coverage standards are met -->
<target name="assert" description="Assert project standards met.">
<!-- Verify 100% Code Coverage -->
<xmlproperty file="${reports.dir}/coverage.xml" collapseAttributes="true"/>
<php expression="floor(${snapshot.totalcovered}/${snapshot.totalcount})" returnProperty="belowCoverage" />
<php expression="floor(${coverage.project.metrics.coveredelements}/${coverage.project.metrics.elements})" returnProperty="belowCoverage" />
<if>
<equals arg1="${belowCoverage}" arg2="0"/>
<then>
<fail msg="!${line.separator}${line.separator}Code Coverage needs to be increased 90% still: file://${reports.dir}/index.html" />
<php expression="round(${coverage.project.metrics.coveredelements}/${coverage.project.metrics.elements}*100, 2)" returnProperty="codecoverage"/>
<warn>Code Coverage: ${codecoverage} %</warn>
<fail msg="!${line.separator}${line.separator}Code Coverage needs to be increased 100% still: file://${reports.dir}/index.html" />
</then>
</if>
</target>
Expand Down
14 changes: 11 additions & 3 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,16 @@
</testsuite>
</testsuites>

<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>

<logging>
<log type="coverage-html" target="reports/"/>
<log type="coverage-clover" target="reports/coverage.xml"/>
<log type="coverage-text" target="php://stdout" showUncoveredFiles="false"/>
</logging>

</phpunit>

0 comments on commit f87c9bd

Please sign in to comment.