PHPUnit with Clover code coverage reports: tests are not executed and commands exit

857 Views Asked by At

I "inherited" a very old PHP project compatible only with PHP 5.6 and written without any framework, and I'm trying to "modernize" it for PHP 7.x and adding some unit tests and some code inspection tools like SonarQube with Jenkins.

The project has some executable scripts which needs some arguments to be executed correctly and when I execute phpunit with the generation of the Clover coverage enabled it tries to execute them and they fail because required arguments are missing:

⋊> ~/P/myproject on mybranch ⨯ ./phpunit tests/
PHPUnit 5.7.27 by Sebastian Bergmann and contributors.

Runtime:       PHP 7.4.5 with Xdebug 2.9.5
Configuration: /Users/me/Projects/myproject/phpunit.xml


You must specify a source (--source)!

This is the output of the files-index.php command from the root folder of the project which need a --source parameter to run:

[...]

if (!$args['source']) {
    exit("You must specify a source (--source)!\n");
}

[...]

What I don't understand is why if I execute PHPUnit without coverage report enabled the (few) tests present into the project are executed with no error (anyway the file files-index.php has no tests at the moment):

⋊> ~/P/myproject on mybranch ⨯ ./phpunit --no-config tests/
PHPUnit 5.7.27 by Sebastian Bergmann and contributors.

........                                                            8 / 8 (100%)

Time: 194 ms, Memory: 4.00MB

OK (8 tests, 8 assertions)

This is my phpunit.xml file:

⋊> ~/P/myproject on mybranch ⨯ cat phpunit.xml                                                                                               22:10:25
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="phpunit.xsd"
         backupGlobals="false"
         verbose="true">

    <testsuites>
        <testsuite name="My Project">
            <directory>./tests</directory>
        </testsuite>
    </testsuites>

    <filter>
        <whitelist processUncoveredFilesFromWhitelist="true">
            <directory suffix=".php">.</directory>
            <exclude>
                <directory suffix=".php">./vendor</directory>
                <directory suffix=".php">./_classes</directory>
            </exclude>
        </whitelist>
    </filter>

    <logging>
        <log type="junit" target="./reports/logfile.xml"/>
        <log type="coverage-clover" target="./reports/coverage.xml"/>
    </logging>

    <php>
        <const name="PHPUNIT_TESTSUITE" value="true"/>
    </php>
</phpunit>

Where I'm wrong?

0

There are 0 best solutions below