T
T
tvolf2013-09-08 19:03:30
PHP
tvolf, 2013-09-08 19:03:30

Code coverage calculation not working when using phpUnit from under Netbeans

Hello.
Such a problem. There is a machine under Windows 7 64bit, the latest PHP 5.5.3 is installed, PEAR is installed to it and phpUnit version 3.7.24 is installed from under it. I created an empty project in Netbeans 7.3.1, it contains an example file
Calculator.php of the form:

==

<?php
class Calculator {
    /**
     * assert (0,0) == 0
     * assert (0,1) == 1
     * assert (1,0) == 1
     * assert (1,1) == 2
     * assert (1, 2) == 3
     *
     */
    public function sum($a, $b) {
        return $a + $b;
    }
}

==
In the Netbeans settings, I added the paths to phpUnit.bat and phpunit-skelgen.bat. For the project, I specified the directory where the tests are located. First, I generate tests for the specified file. The CalculatorTest.php file appears in the test directory. At first I noticed that this file does not contain the Calculator.php class connection string, without which the launch of the tests gave an error that the Calculator class was not found. In general, I connected it manually via require_once (although, in general, it’s strange - do you constantly need to manually write the path to the classes under test? ...) Well, okay. Tests, at the very least, earned.

Then it became interesting to see how the code coverage calculation works. I set 2 checkboxes in the project menu: “Code coverage” -> “Collection and display of code coverage” + “Show editor panel”. A line appears that says "Code Coverage: 0.00%". I run the same tests for Calculator.php, but the content of this line does not change. Constantly outputs zeros. There are no unusual messages in the Output window.
That is, phpUnit normally starts and exports to XML. XDebug is installed and registered in php.ini.
When I click on the "Report" button in order to view the results of the calculation of the coverage code, I see one line: "No data - was the code run?".
Maybe someone has experienced something similar? How can the problem be solved?
Thank you in advance for your help.

ps. If you simply execute 2 commands from the command line with your hands:
>phpunit-skelgen --test calculator
>phpunit --coverage-clover report.xml calculatortest
, then a normal report.xml report is generated with non-zero data inside.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
nikosias, 2013-11-30
@tvolf

Same error.
The problem occurs if the project directory is set to a different drive.
The solution
is simple:
Move the project to the disk where netbeans is installed.
complex:
in the directory we create a file with the following content:

<?php
class NetBeansSuite extends PHPUnit_Framework_TestSuite {
    public static function suite() {
        $suite = new NetBeansSuite();
        $array=self::rglob("*[Tt]est.php", getcwd());
        foreach ($array as $file) {
            $suite->addTestFile($file);
        }
        return $suite;
    }
    private static function rglob($pattern = '*', $path = '', $flags = 0) {
        $paths = glob($path.'*', GLOB_MARK | GLOB_ONLYDIR | GLOB_NOSORT) or array();
        $files = glob($path.$pattern, $flags) or array();
        foreach ($paths as $path) {
            $files = array_merge($files, self::rglob($pattern, $path, $flags));
        }
        return $files;
    }
}
?>

This is an artistically cut file:
C:\Users\%username%\AppData\Roaming\NetBeans\7.3\phpunit\NetBeansSuite.php
In project properties -> PHPUnit-> use custom test suite set a file link to this file.
After that code coverage starts working.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question