sebastianbergmann / php-code-coverage

Library that provides collection, processing, and rendering functionality for PHP code coverage information.
BSD 3-Clause "New" or "Revised" License
8.81k stars 373 forks source link

Tests in subdirectories are run, but are missing from the coverage report #690

Closed deyvisonrocha closed 5 years ago

deyvisonrocha commented 5 years ago
Q A
php-code-coverage version 6.1.4
PHP version 7.1.31
Driver pcov
Pcov version 1.0.6
Xdebug version (if used) 0
Installation Method Composer
Usage Method PHPUnit
PHPUnit version (if used) 7.5.13

Hi. I have the same problem.

See my phpunit.xml:

<phpunit backupGlobals="false"
  backupStaticAttributes="false"
  bootstrap="vendor/autoload.php"
  colors="true"
  convertErrorsToExceptions="true"
  convertNoticesToExceptions="true"
  convertWarningsToExceptions="true"
  processIsolation="false"
  stopOnFailure="false">
<testsuites>
    ...
</testsuites>
<filter>
    <whitelist>
      <directory suffix=".php">./app</directory>
      <directory suffix=".php">./src</directory>
    </whitelist>
  </filter>
  <php>
    <server name="APP_ENV" value="testing"/>
    <server name="BCRYPT_ROUNDS" value="4"/>
    <server name="CACHE_DRIVER" value="array"/>
    <server name="MAIL_DRIVER" value="array"/>
    <server name="QUEUE_CONNECTION" value="sync"/>
    <server name="QUEUE_DRIVER" value="sync"/>
    <server name="SESSION_DRIVER" value="array"/>
  </php>
  <logging>
    <log type="coverage-clover" target="./report/coverage.xml"/>
    <log type="testdox-text" target="./report/log.txt"/>
    <log type="junit" target="./report/tests-junit.xml"/>
    <log type="coverage-html" target="./report" lowUpperBound="50" highLowerBound="80"/>
  </logging>
</phpunit>

The folder './src' has coverage but the './app' doesn't has coverage. See the screenshot:

image

sebastianbergmann commented 5 years ago

Thank you for your report.

Please provide a minimal, self-contained, reproducing test case that shows the problem you are reporting.

Without such a minimal, self-contained, reproducing test case I will not be able to investigate this issue.

deyvisonrocha commented 5 years ago

Let's go:

In app/MyClass.php

<?php

namespace App;

class MyClass
{
    public function sayHello($name) 
    {
        return "Hello $name";
    }
}

In src/AnotherClass.php

<?php

namespace MyPackage;

class AnotherClass
{
    public function sayHello()
    {
            return "Hello";
    }
}

My tests:

In tests/app/MyClassTest.php

<?php

namespace Tests;

use PHPUnit\Framework\TestCase;

class MyClassTest extends TestCase
{
    public function testSayHello()
    {
        $myClass = new \App\MyClass('Deyvison');
        $this->assertEquals('Hello Deyvison', $myClass->sayHello());
    }
}

In tests/src/AnotherClassTest.php

<?php

namespace Tests;

use PHPUnit\Framework\TestCase;

class AnotherClassTest extends TestCase
{
    public function testSayHello()
    {
        $myClass = new \MyPackage\AnotherClass(');
        $this->assertEquals('Hello', $myClass->sayHello());
    }
}
sebastianbergmann commented 5 years ago

Where is the phpunit.xml? How do you invoke PHPUnit?

deyvisonrocha commented 5 years ago

In the root folder. I use vendor/bin/phpunit to execute the tests.

image

It is a large project. Last week this started to happen after installing pcov and pcov/clobber to run faster coverage.

deyvisonrocha commented 5 years ago

I run vendor/bin/pcov clobber after run vendor/bin/phpunit.

sebastianbergmann commented 5 years ago

I asked for a minimal, self-contained, reproducing test case. This includes the phpunit.xml. Without this I am not able to investigate this issue.

deyvisonrocha commented 5 years ago

I solved the problem.

By default, pcov-clobber find the folders in the order: src, lib or app.

For multi-folder operation I used the @krakjoe tip itself at the link below: https://github.com/krakjoe/pcov/issues/17#issuecomment-498041469

No have problem with php-code-coverage. Issue closed.