Sharath
Sharath

Reputation: 969

PHPUnit coverage in Cobertura format

I have a small PHP project that uses PHPUnit for unit tests and coverage. I would like to generate the coverage reports in cobertura XML format.

Is there any tool or plugin that I can use to achieve this?

Any help is appreciated..

Upvotes: 20

Views: 7955

Answers (3)

jawira
jawira

Reputation: 4598

You can configure cobertura support in config file phpunit.xml.

Here an example, put the following code inside <phpunit/> tag:

  <coverage cacheDirectory=".phpunit.cache/code-coverage"
            processUncoveredFiles="true">
    <include>
      <directory suffix=".php">src</directory>
    </include>
    <report>
      <cobertura outputFile="cobertura.xml"/>
      <html outputDirectory="phpunit-html"/>
      <text outputFile="php://stdout"/>
    </report>
  </coverage>

Note the <cobertura/> tag in the example.

Upvotes: 4

Svemir Brkic
Svemir Brkic

Reputation: 520

Support for Cobertura format has just been merged to phpunit and phpcov, and it is available in phpunit 9.4

The report can be generated by invoking phpunit with this flag:

phpunit --coverage-cobertura=my-cobertura-coverage.xml

Upvotes: 26

The XML format for code coverage information logging produced by PHPUnit is loosely based upon the one used by Clover.

Upvotes: -3

Related Questions