phpdox icon indicating copy to clipboard operation
phpdox copied to clipboard

Error when trying to add phpunit coverage to docs

Open Nayjest opened this issue 10 years ago • 6 comments

PHP Version: 5.6.6 (WINNT) PHPDox Version: 0.8.1.1 ErrorException: E_ERROR Location: phar://C:/Users/user/Dropbox/!CODE/lib/collection/phpdox.phar/phpdox/generator/enricher/phpunit/PHPUnit.php (Line 223)

Call to a member function getAttribute() on null

My config:

<?xml version="1.0" encoding="utf-8" ?>
<phpdox xmlns="http://xml.phpdox.net/config">
    <project name="MyProject" source="${basedir}/src" workdir="${basedir}/build/phpdox/xml">
        <collector publiconly="false" backend="parser" encoding="auto"/>
        <generator output="${basedir}/build/phpdox">
            <build engine="html" output="html"/>
            <enrich base="${basedir}">
                <source type="git">
                    <history enabled="true" limit="15" cache="${phpDox.project.workdir}/gitlog.xml" />
                </source>
                <source type="phpunit">
                    <coverage path="build/phpunit-coverage" />
                </source>
            </enrich>
            <build engine="html" enabled="true" output="html">
                <template dir="${phpDox.home}/templates/html" />
            </build>
        </generator>
    </project>
</phpdox>

Nayjest avatar Sep 29 '15 13:09 Nayjest

I got the same error when the XML specified in was not in the phpunits own coverage XML format, but the clover format. Maybe that is your problem as well.

Looking at the code, the Enricher relies on the correct format and does not give any hint, if there is no baseDir found. A more descriptive exception could help here, I guess.

carstenwindler avatar Oct 28 '15 14:10 carstenwindler

Sorry for keeping this bug uncommented for so long but I'm rather busy with many things these days and have not the time to work on phpDox as much as I'd wish. The enricher code is indeed not very fault tolerant and its error handling capabilities leave much to be desired. (Pull requests welcome ;) )

To address your issue though, I'd say @carstenwindler 's comment is likely to be the correct reason for this problem. I'll leave this bug open as a reminder to myself to add better error checking to it.

theseer avatar Oct 28 '15 16:10 theseer

I had the same issue. Use --coverage-xml instead of --coverage-clover

alwar avatar Jan 19 '16 11:01 alwar

Just to add some additional information (as i was also fighting with this issue):

i've most of the build configurations inside a build folder. However, both ant build.xml and phpdox.xml had to be moved to the route of the project (filepath issues otherwise).

The relevant line on the PHPUnit configuration is:

<logging>
    <log type="coverage-xml" target="../build/logs/coverage"/>
</logging>

When you run PHPUnit it will create on the logs/coverage folder and inside it all the xml coverage files.

Ensure that there are no other files there (i had some leftovers from clover, and it just gives the stated error).

Another issue that i found was that PHPDox is expecting the xml coverage files inside a coverage folder somewhere, in my case i used on PHPDox config (which is on the root of the project):

        <enrich base="${basedir}/build/logs">
            <source type="phpunit">
                <coverage path="${basedir}/build/logs" />
                <!-- @path - the directory where the xml code coverage report can be found -->
                <filter directory="${basedir}/build" />
                <!-- @directory - path of the phpunit config whitelist filter directory -->
            </source>

This makes the PHPDox find most of the configurations for sub-modules in the build/logs folder, and the coverage on the build/logs/coverage folder (where now there should exist an index.xml file, if you runned PHPUnit as stated before).

Definitivelly, phpdox doesn't like either the clover or junit coverage files.

Hope this helps with the issue for others.

Tested with: $>php -v PHP 5.6.18 (cli) (built: Feb 6 2016 06:53:53) Copyright (c) 1997-2016 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies with Xdebug v2.3.3, Copyright (c) 2002-2015, by Derick Rethans

$>phpdox --version phpDox 0.8.1.1 - Copyright (C) 2010 - 2016 by Arne Blankerts

$>phpunit --version
PHPUnit 5.2.9 by Sebastian Bergmann and contributors.

lferro9000 avatar Feb 24 '16 16:02 lferro9000

I seriously have to make phpDox be more verbose on this condition. I'll try to have that included in the next release.

theseer avatar Feb 25 '16 19:02 theseer

I just pushed a few changes that should fix this issue.

Please verify and report back.

theseer avatar Sep 22 '16 22:09 theseer