Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHPUnit coverage shows "EMPTY" for all files #392

Open
knallcharge opened this issue Feb 20, 2020 · 5 comments
Open

PHPUnit coverage shows "EMPTY" for all files #392

knallcharge opened this issue Feb 20, 2020 · 5 comments

Comments

@knallcharge
Copy link

I'm using phpdox to generate the documentation for a project and I'm trying to include the PHPUnit-coverage, but it shows "EMPTY" for all files, e.g. my entities:

grafik

In issue #147 you state that "EMPTY" means that the file is "Not executable (e.g. an in interface)", but this happens for all my files. Also in the generated coverage-xml, the status for all files is "PASSED", e.g. for my User-entity:

<test name="App\Tests\Entity\UserTest::testCreateUser" size="unknown" result="0" status="PASSED"/>
<test name="App\Tests\Entity\UserTest::testGetRolesAndRolesAsString" size="unknown" result="0" status="PASSED"/>
<test name="App\Tests\Entity\UserTest::testAddAndGetStage" size="unknown" result="0" status="PASSED"/>
<test name="App\Tests\Entity\UserTest::testRemoveStage" size="unknown" result="0" status="PASSED"/>
<test name="App\Tests\Entity\UserTest::testHasStage" size="unknown" result="0" status="PASSED"/>
<test name="App\Tests\Entity\UserTest::testGetDisplayName" size="unknown" result="0" status="PASSED"/>
<test name="App\Tests\Entity\UserTest::testSerialize" size="unknown" result="0" status="PASSED"/>
<test name="App\Tests\Entity\UserTest::testUnserialize" size="unknown" result="0" status="PASSED"/>
<test name="App\Tests\Entity\UserTest::testCreateNewUser" size="unknown" result="0" status="PASSED"/>

Also in the corresponding xml for the Entity (User.php.xml) coverage is marked as "100":

<method name="serialize" signature="serialize(): string" start="310" end="319" crap="1" executable="6" executed="6" coverage="100"/>

But somehow phpdox is not able to map the information for some reason.

Here's the part of my phpunit.xml that generates the output:

<log type="coverage-html" target="../build/artifacts/coverage" lowUpperBound="35" highLowerBound="70"/>
<log type="coverage-xml" target="../build/artifacts/coveragexml" lowUpperBound="35" highLowerBound="70"/>
<log type="coverage-clover" target="../build/artifacts/index.xml"/>

This is my phpdox.xml:

<?xml version="1.0" encoding="utf-8" ?>
<phpdox xmlns="http://xml.phpdox.net/config" silent="false">
    <bootstrap/>
    <project name="phpdox" source="${basedir}/../src" workdir="${basedir}/../build/phpdox/xml">
        <collector publiconly="false" backend="parser" encoding="auto">
            <include mask="*.php"/>
            <exclude mask="*Migrations/*"/>
            <exclude mask="*Kernel.php*"/>
            <inheritance resolve="false">
            </inheritance>
        </collector>
        <generator output="${basedir}/../build">
            <enrich base="${basedir}/../build">
                <source type="phploc">
                    <file name="logs/phploc.xml"/>
                </source>
                <source type="phpcs">
                    <file name="phpcs.xml"/>
                </source>
                <source type="pmd">
                    <file name="logs/pmd.xml"/>
                </source>
                <source type="phpunit">
                    <coverage path="artifacts/coveragexml"/>
                </source>
            </enrich>
            <build engine="html" enabled="true" output="api">
                <template dir="${phpDox.home}/templates/html"/>
                <file extension="html"/>
            </build>
        </generator>
    </project>
</phpdox>

And this the output of phpdox (from Jenkins) which shows no error:

13:10:52 phpdox:
13:10:52    [phpdox] phpDox 0.12.0 - Copyright (C) 2010 - 2020 by Arne Blankerts and Contributors
13:10:52    [phpdox] 
13:10:52    [phpdox] [20.02.2020 - 13:10:52] Using config file './phpdox.xml'
13:10:52    [phpdox] [20.02.2020 - 13:10:52] Registered collector backend 'parser'
13:10:52    [phpdox] [20.02.2020 - 13:10:52] Registered enricher 'build'
13:10:52    [phpdox] [20.02.2020 - 13:10:52] Registered enricher 'git'
13:10:52    [phpdox] [20.02.2020 - 13:10:52] Registered enricher 'checkstyle'
13:10:52    [phpdox] [20.02.2020 - 13:10:52] Registered enricher 'phpcs'
13:10:52    [phpdox] [20.02.2020 - 13:10:52] Registered enricher 'pmd'
13:10:52    [phpdox] [20.02.2020 - 13:10:52] Registered enricher 'phpunit'
13:10:52    [phpdox] [20.02.2020 - 13:10:52] Registered enricher 'phploc'
13:10:52    [phpdox] [20.02.2020 - 13:10:52] Registered output engine 'xml'
13:10:52    [phpdox] [20.02.2020 - 13:10:52] Registered output engine 'html'
13:10:52    [phpdox] [20.02.2020 - 13:10:52] Starting to process project 'phpdox'
13:10:52    [phpdox] [20.02.2020 - 13:10:52] Starting collector
13:10:52    [phpdox] [20.02.2020 - 13:10:52] Scanning directory '<PATH_REMOVED>/workspace/build/../src' for files to process
13:10:52    [phpdox] 
13:10:53    [phpdox] ..................................................	[50]
13:10:53    [phpdox] ................................................  	[98]
13:10:53    [phpdox] 
13:10:53    [phpdox] [20.02.2020 - 13:10:53] Saving results to directory '<PATH_REMOVED>/workspace/build/../build/phpdox/xml'
13:10:56    [phpdox] [20.02.2020 - 13:10:56] Collector process completed
13:10:56    [phpdox] 
13:10:56    [phpdox] [20.02.2020 - 13:10:56] Starting generator
13:10:56    [phpdox] [20.02.2020 - 13:10:56] Loading enrichers
13:10:56    [phpdox] [20.02.2020 - 13:10:56] Enricher PHPLoc xml initialized successfully
13:10:56    [phpdox] [20.02.2020 - 13:10:56] Enricher PHPCS XML initialized successfully
13:10:56    [phpdox] [20.02.2020 - 13:10:56] Enricher PHPMessDetector XML initialized successfully
13:10:56    [phpdox] [20.02.2020 - 13:10:56] Enricher PHPUnit Coverage XML initialized successfully
13:10:56    [phpdox] [20.02.2020 - 13:10:56] Enricher Build Information initialized successfully
13:10:56    [phpdox] [20.02.2020 - 13:10:56] Starting event loop.
13:10:56    [phpdox] 
13:10:56    [phpdox] ..................................................	[50]
[cut]
13:11:11    [phpdox] ..................................................	[1400]
13:11:12    [phpdox] ......................                            	[1422]
13:11:12    [phpdox] 
13:11:12    [phpdox] [20.02.2020 - 13:11:12] Generator process completed
13:11:12    [phpdox] [20.02.2020 - 13:11:12] Processing project 'phpdox' completed.
13:11:12    [phpdox] 
13:11:12    [phpdox] 
13:11:12    [phpdox] Time: 19.67 seconds, Memory: 14.00 MB

Using phpdox 0.12.0 and PHPUnit 8.5.2 running on Jenkins 2.220 on Windows.

@theseer
Copy link
Owner

theseer commented Feb 20, 2020

Sigh. You wrote Windows....

I'll try to have a look but i'm assuming it's a path mapping issue - again. Why do people in 2020 still use windows and drive letters...?

Again, I'll try to have a look as soon as I can but since I don't usually use windows I'll have to resurrect my Windows 10 VM and see if i can debug this somehow.

Any chance you can provide me with a simple sample project that exhibts the problem?

@knallcharge
Copy link
Author

Thanks for getting back. Can't change company policy, so also Sigh for having to use Windows.
I have setup a sample project here: https://github.com/Knallcharge/phpdox-test
When building the project on Jenkins (using the same build-files as in the original project), phpdox returns "Enricher PHPUnit Coverage XML initialized successfully", also in the report it displays "Used Enrichers: build, phpcs, phploc, phpunit, pmd".
The class is claimed "EMPTY":
grafik
There a little difference to the original project which I couldn't track: clicking on the classname shows no coverage at all (maybe because the file is too small?) while in the original project it displayed "coverage 0%". But as the class is said to be "EMPTY" while it should not, I guess the origin of the problem is illustrated.
Hope this helps.

@theseer
Copy link
Owner

theseer commented Feb 21, 2020

Thanks for the sample project. I'll try to have a look over the weekend!

@MacFJA
Copy link
Contributor

MacFJA commented Mar 25, 2020

I found what cause the issue.

And it had nothing to do with Windows 😅

They are in fact 2 issues.

PHPUnit coverage XML

The coverage xml generated by phpunit change with the value of addUncoveredFilesFromWhitelist

With addUncoveredFilesFromWhitelist set to false

<phpunit xmlns="https://schema.phpunit.de/coverage/1.0">
  <!-- [...] -->
  <project source="${projectRoot}/phpdox-test-master/src/Service">
    <!-- [...] -->
    <directory name="/">
      <!-- [...] -->
      <file name="Math.php" href="Math.php.xml">

With addUncoveredFilesFromWhitelist set to true

<phpunit xmlns="https://schema.phpunit.de/coverage/1.0">
  <!-- [...] -->
  <project source="${projectRoot}/phpdox-test-master/src">
    <!-- [...] -->
    <directory name="/">
      <!-- [...] -->
      <directory name="Service">
        <!-- [...] -->
        <file name="Math.php" href="Service/Math.php.xml">

Note that the project source is not the same. And phpDox use the XPath query //pu:project/pu:directory/pu:directory[@name = "Service"]/pu:file[@name = "Math.php"] (TheSeer\phpDox\Generator\Enricher\PHPUnit::loadCoverageInformation)

So in the first version (which is used in the sample project), phpDox can't find the node as directories are merged in the project source.

Namespace in HTML template

The second issue is that PHPUnit coverage change its namespace from http://schema.phpunit.de/coverage/1.0 to https://schema.phpunit.de/coverage/1.0 (HTTP to HTTPS).

And in the xsl templates, the namespace is referenced with HTTP, so the namespace alias (pu) don't match the actual namespace.

Which cause, for example, <xsl:when test="$class//pu:coverage/@coverage != 0 or $class//pu:coverage/@executable != 0"> to always failing (in units.xsl)

@theseer
Copy link
Owner

theseer commented Mar 28, 2020

Wow. Thanks for the in-depth analysis and for figuring this out.
I'll try to have a look at it as soon as possible and provide a fixed version.

@sebastianbergmann Does the difference in output from PHPUnit qualify as a bug or as "works as intended"? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants