PHPunit code coverage error

PHPunit works, but I get this code coverage error and not get the code coverage report.

Does anyone know how to fix this?

Thanks,

Demian.

demian@dimbo-TP :/var/www/z2d2/tests$ phpunit PHPUnit 3.5.15 by Sebastian Bergmann. ... Time: 1 second, Memory: 13.00Mb OK (3 tests, 4 assertions) Generating code coverage report, this may take a moment.PHP Fatal error: Class 'PHP_Token_Stream' not found in /usr/share/php/PHP/Token/Stream/CachingFactory.php on line 68 PHP Stack trace: PHP 1. {main}() /usr/bin/phpunit:0 PHP 2. PHPUnit_TextUI_Command::main() /usr/bin/phpunit:49 PHP 3. PHPUnit_TextUI_Command->run() /usr/share/php/PHPUnit/TextUI/Command.php:129 PHP 4. PHPUnit_TextUI_TestRunner->doRun() /usr/share/php/PHPUnit/TextUI/Command.php:188 PHP 5. PHP_CodeCoverage_Report_HTML->process() /usr/share/php/PHPUnit/TextUI/TestRunner.php:363 PHP 6. PHP_CodeCoverage_Report_HTML->addItems() /usr/share/php/PHP/CodeCoverage/Report/HTML.php:135 PHP 7. PHP_CodeCoverage_Report_HTML_Node_Directory->addFile() /usr/share/php/PHP/CodeCoverage/Report/HTML.php:214 PHP 8. PHP_CodeCoverage_Report_HTML_Node_File->__construct() /usr/share/php/PHP/CodeCoverage/Report/HTML/Node/Directory.php:156 PHP 9. PHP_CodeCoverage_Util::getLinesToBeIgnored() /usr/share/php/PHP/CodeCoverage/Report/HTML/Node/File.php:169 PHP 10. PHP_Token_Stream_CachingFactory::get() /usr/share/php/PHP/CodeCoverage/Util.php:271 Fatal error: Class 'PHP_Token_Stream' not found in /usr/share/php/PHP/Token/Stream/CachingFactory.php on line 68 Call Stack: 0.0002 326940 1. {main}() /usr/bin/phpunit:0 0.0434 666604 2. PHPUnit_TextUI_Command::main() /usr/bin/phpunit:49 0.0435 667084 3. PHPUnit_TextUI_Command->run() /usr/share/php/PHPUnit/TextUI/Command.php:129 0.0943 4312004 4. PHPUnit_TextUI_TestRunner->doRun() /usr/share/php/PHPUnit/TextUI/Command.php:188 1.1150 13272196 5. PHP_CodeCoverage_Report_HTML->process() /usr/share/php/PHPUnit/TextUI/TestRunner.php:363 1.1521 14100768 6. PHP_CodeCoverage_Report_HTML->addItems() /usr/share/php/PHP/CodeCoverage/Report/HTML.php:135 1.1521 14101320 7. PHP_CodeCoverage_Report_HTML_Node_Directory->addFile() /usr/share/php/PHP/CodeCoverage/Report/HTML.php:214 1.1521 14103132 8. PHP_CodeCoverage_Report_HTML_Node_File->__construct() /usr/share/php/PHP/CodeCoverage/Report/HTML/Node/Directory.php:156 1.1595 14122724 9. PHP_CodeCoverage_Util::getLinesToBeIgnored() /usr/share/php/PHP/CodeCoverage/Report/HTML/Node/File.php:169 1.1595 14123076 10. PHP_Token_Stream_CachingFactory::get() /usr/share/php/PHP/CodeCoverage/Util.php:271 
+7
source share
5 answers

You are using PHPUnit 3.5.x, so you need to install the token stream version using:

 sudo pear install --force --alldeps phpunit/PHP_CodeCoverage-1.0.2 

If you want to upgrade to the current phpunit version one thing, the lines

 sudo pear install --force --alldeps phpunit/phpunit 

will do the job, but if I remember correctly, you are trying to use the Zend Framework testing environment and only works with PHPUnit 3.5.15


If both options do not work or do not fit, go to

 sudo pear install --force phpunit/PHP_TokenStream 

What definitely will give you working PHPUnit 3.5.15

http://dustyreagan.com/downgrade-phpunit-3-6-to-3-5-15/

Important note : if you install PHPUnit via PEAR. This installation method is no longer used. Supported and http://pear.phpunit.de/ will be disabled no later than December 31, 2014.

Please read http://phpunit.de/manual/current/en/installation.html and learn how to use PHPUnit from PHAR or install it through Composer.

+10
source

If all efforts to downgrade phpunit from 3.6 to 3.5 are not successful. You can fix this problem by adding the following code to /usr/share/php/PHP/Token/Stream/CachingFactory.php to fix the "class" PHP_Token_Stream "not found ..."

 require_once('PHP/Token/Stream/Autoload.php'); 
+2
source

Try fixing phpunit by reinstalling:

 $ pear upgrade -f phpunit 
+1
source

Installing phpunit with a pear didn't work for me at all.

What I finally did (in some directory, for example / home / USERNAME / phpunit ):

 wget http://pear.phpunit.de/get/phpunit.phar chmod +x phpunit.phar 

And in .bash.rc add the end

 export PATH=${PATH}:PATH_WHERE_YOU_PUT_phpunit.phar 

In my example, PATH_WHERE_YOU_PUT_phpunit.phar will be / home / USERNAME / phpunit

After that, phpunit can be executed with the phpunit.phar command in any directory

0
source

An option for some Linux distributions may be to use yum or apt-get to install phpunit.

I use Fedora 17 and installed phpunit with yum, everything worked fine on the first try. Not sure how well Ubuntu / Mint works.

On Windows, I used a pear and it worked fine there, but since I found phpunit in yum, I thought I'd try first.

0
source

All Articles