phpunit-testingphpunitcode-coverageclover

PHPUnit - one coverage report from multiple project folders?


I have a project that is structured like so:

project
├── app
│   ├── phpunit.xml
│   ├── src
│   └── tests
│       └── unit
└── modules
    ├── module1
    │   ├── phpunit.xml
    │   ├── src
    │   └── tests
    │       └── unit
    └── module2
        ├── phpunit.xml
        ├── src
        └── tests
            └── unit

All of the core interfaces/classes are in app/src, and all of the extensions/implementations are in modules/**. Thus, the src folders contain all the Controllers, Models, etc., and the adjacent tests/unit folder contains all of the unit tests for these objects.

I'm trying to generate one coverage.xml report (and more importantly an HTML report) that contains the coverage results from all of the tests across both app/ and modules/. Can anyone suggest the best way to accomplish this?


Solution

  • You could create one phpunit.xml in your project root folder.

    When running PHP Unit just point to your project root and PHPUnit will run over every test files he can find.

    The same goes with the generated coverage.xml that now includes all results from every testfile.

    If you like to seperate test runs then look at the PHPunit Option testsuite.

    Example:

    project
    ├── phpunit.xml
    ├── app (testsuite app)
    └── modules
        ├── module1 (testsuite module2)
        └── module2 (testsuite module1)
    

    Insert into your phpunit.xml

    <testsuites>
      <testsuite name="app">
        <directory>app</directory>
      </testsuite>
      <testsuite name="module1">
        <directory>modules/module1</directory>
      </testsuite>
      <testsuite name="module2">
        <directory>modules/module1</directory>
      </testsuite>
    </testsuites>
    

    And calling with

    phpunit --configuration phpunit.xml --testsuite module1