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

Code coverage problem: Fatal error: Class 'PHP_Token_Stream' not found #353

Closed
davidkuridza opened this issue Sep 26, 2011 · 22 comments
Closed

Comments

@davidkuridza
Copy link

I am running PHPUnit 3.5.15 on a freshly installed Ubuntu 11.04 64bit. Tests are running fine, however, when trying to run code coverage as well, an error is thrown:

$ phpunit --coverage-html build/coverage/ Tests/SomeTest.php 
PHPUnit 3.5.15 by Sebastian Bergmann.

...

Time: 1 second, Memory: 6.00Mb

OK (3 tests, 30 assertions)

Generating code coverage report, this may take a moment.
Fatal error: Class 'PHP_Token_Stream' not found in /usr/share/php/PHP/Token/Stream/CachingFactory.php on line 68

Call Stack:
    0.0002     639560   1. {main}() /usr/bin/phpunit:0
    0.0132    1151288   2. PHPUnit_TextUI_Command::main() /usr/bin/phpunit:49
    0.0132    1152160   3. PHPUnit_TextUI_Command->run() /usr/share/php/PHPUnit/TextUI/Command.php:129
    0.0300    4052112   4. PHPUnit_TextUI_TestRunner->doRun() /usr/share/php/PHPUnit/TextUI/Command.php:188
    1.5055    5682376   5. PHP_CodeCoverage_Report_HTML->process() /usr/share/php/PHPUnit/TextUI/TestRunner.php:363
    1.5059    5733328   6. PHP_CodeCoverage_Report_HTML->addItems() /usr/share/php/PHP/CodeCoverage/Report/HTML.php:135
    1.5059    5734064   7. PHP_CodeCoverage_Report_HTML_Node_Directory->addFile() /usr/share/php/PHP/CodeCoverage/Report/HTML.php:213
    1.5059    5737416   8. PHP_CodeCoverage_Report_HTML_Node_File->__construct() /usr/share/php/PHP/CodeCoverage/Report/HTML/Node/Directory.php:156
    1.5062    5801152   9. PHP_CodeCoverage_Util::getLinesToBeIgnored() /usr/share/php/PHP/CodeCoverage/Report/HTML/Node/File.php:169
    1.5063    5801792  10. PHP_Token_Stream_CachingFactory::get() /usr/share/php/PHP/CodeCoverage/Util.php:271

I have manually included missing file in /usr/share/php/PHP/Token/Stream/CachingFactory.php for debugging purposes, the diff is

68d67
<             include_once '/usr/share/php/PHP/Token/Stream.php';

Running the same test again results in following error:

Generating code coverage report, this may take a moment.
Fatal error: Class 'PHP_Token_OPEN_TAG' not found in /usr/share/php/PHP/Token/Stream.php on line 205

Call Stack:
    0.0002     639560   1. {main}() /usr/bin/phpunit:0
    0.0132    1151288   2. PHPUnit_TextUI_Command::main() /usr/bin/phpunit:49
    0.0132    1152160   3. PHPUnit_TextUI_Command->run() /usr/share/php/PHPUnit/TextUI/Command.php:129
    0.0302    4052608   4. PHPUnit_TextUI_TestRunner->doRun() /usr/share/php/PHPUnit/TextUI/Command.php:188
    1.5091    5682912   5. PHP_CodeCoverage_Report_HTML->process() /usr/share/php/PHPUnit/TextUI/TestRunner.php:363
    1.5095    5733840   6. PHP_CodeCoverage_Report_HTML->addItems() /usr/share/php/PHP/CodeCoverage/Report/HTML.php:135
    1.5095    5734576   7. PHP_CodeCoverage_Report_HTML_Node_Directory->addFile() /usr/share/php/PHP/CodeCoverage/Report/HTML.php:213
    1.5095    5737928   8. PHP_CodeCoverage_Report_HTML_Node_File->__construct() /usr/share/php/PHP/CodeCoverage/Report/HTML/Node/Directory.php:156
    1.5099    5801688   9. PHP_CodeCoverage_Util::getLinesToBeIgnored() /usr/share/php/PHP/CodeCoverage/Report/HTML/Node/File.php:169
    1.5099    5802328  10. PHP_Token_Stream_CachingFactory::get() /usr/share/php/PHP/CodeCoverage/Util.php:271
    1.5106    5953392  11. PHP_Token_Stream->__construct() /usr/share/php/PHP/Token/Stream/CachingFactory.php:69
    1.5106    5957656  12. PHP_Token_Stream->scan() /usr/share/php/PHP/Token/Stream.php:147

Has anyone experienced this behaviour? I'll try looking into it more closely in the upcoming days.

@sebastianbergmann
Copy link
Owner

I cannot reproduce this.

@danielhunt
Copy link

I have just come up against this exact bug under OSX Lion

@cebe
Copy link

cebe commented Nov 6, 2011

Can you post your php include path? Is /usr/share/php/ in it?

@danielhunt
Copy link

That path actually doesn't exist on my system ...
My current include path is: '.:/usr/local/Cellar/php/5.3.8/lib/php'

As is clear from this path, I used homebrew to install php

@cebe
Copy link

cebe commented Nov 6, 2011

Okay, then where have you installed PHPUnit and where is your PHP/Token/Stream directory located? Make sure all these are under the php include path(adjust that path in php.ini if necessary) so that autoloader can find them.

If class name is PHP_Token_Stream autoloader will try do include("PHP/Token/Stream.php");

@danielhunt
Copy link

My response to your first question actually got me thinking - it didn't make sense that my include_path was missing the normal paths, so I went digging - it looks like I'm having problems with autoloading class files.
I'll need to look into this a bit more I think

Thanks for the responses though

@davidkuridza
Copy link
Author

@gpkamp figured the problem is resolved by manually including Token/Stream/Autoload.php, can you try it to see if it works for you as well?

My problem was gone by re-installing everything, I blame PEAR for original issue :)

@danielhunt
Copy link

I've tried reinstalling alright, but it made no difference.
Note that this was working perfectly for me until this morning when I did something. God knows what that was though :/

Anyway, after figuring out I needed this line: '''require 'PHPUnit/Autoload.php';''' (but I didn't need it before this morning ...), I now have another error:

Generating code coverage report, this may take a moment.PHP Fatal error: Class 'PHP_Token_OPEN_TAG' not found in /usr/local/share/pear/PHP/Token/Stream.php on line 205

Things are getting awfully strange here...

@danielhunt
Copy link

Just to note - adding:
require_once('PHP/Token/Stream/Autoload.php');
solved my issues.

@mateusz
Copy link

mateusz commented Dec 2, 2011

Hey Daniel, same problem here.
PHPUnit 3.5.15 on OSX + XAMPP.
PEAR Version: 1.9.4
PHP Version: 5.3.1
Zend Engine Version: 2.3.0

What's your PEAR and PHP version? And yes, adding your require_once to the top of PHP/Token/Stream/CachingFactory.php hacks that into submission.

@danielhunt
Copy link

PHPUnit 3.5.15 on OSX + nginx/php-fpm/mysql/mongo ;)
PEAR Version: 1.9.4
PHP Version: 5.3.8
Zend Engine Version: 2.3.0

A colleague, who is having no problems at all, reports this:
PHPUnit 3.5.5 on Ubuntu 11.04 + nginx/php-fpm/mysql/mongo
PEAR Version: 1.9.1
PHP Version: 5.3.5-1ubuntu7.3
Zend Engine Version: 2.3.0

@anroots
Copy link

anroots commented Dec 18, 2011

@danielhunt Can confirm, adding require_once('PHP/Token/Stream/Autoload.php'); solved the issue for me, too (thanks!).

@danielhunt
Copy link

Nothing from @sebastianbergmann on this? :)

@sebastianbergmann
Copy link
Owner

I cannot reproduce this, sorry. And PHPUnit 3.5 is no longer supported, also sorry.

@danielhunt
Copy link

... that's so odd :/
I'll try reinstalling the whole lot and see what happens

(cheers for the quick response)

@ssmusoke
Copy link

Used the steps at http://dustyreagan.com/downgrade-phpunit-3-6-to-3-5-15/ to get the correct versions and dependencies for installing PHPUnit 3.5.15

@ghost
Copy link

ghost commented Apr 18, 2012

Adding the snippet of code also worked for me.

@apinheiro
Copy link

I managed to reproduce your error in parts.
The ideal is that PHPUnit is installed inside the PEAR folder, but gives problem.

I corrected the problem by deleting the directories and PHP and PHPUnit downloading again through the pear command.

@amitchhajer
Copy link

Downgraded the version of PHP_TokenStream to 1.0.1 and worked for me.
sudo pear install --force phpunit/PHP_TokenStream-1.0.1

@JellyBellyDev
Copy link

Thanks a lot @amitchhajer! Work for me! ;)

@gilbertoalbino
Copy link

gilbertoalbino commented May 27, 2016

5 years later and I am running accross the very same problem. The Class does exist!
PHPUnit version 5.3.4:

Generating code coverage report in HTML format ...PHP Fatal error: Class 'Acme\Controllers\BaseController' not found in /var/www/html/src/Controllers/
AdminController.php on line 11
PHP Stack trace:
PHP 1. {main}() /usr/local/bin/phpunit:0
PHP 2. PHPUnit_TextUI_Command::main() /usr/local/bin/phpunit:525
PHP 3. PHPUnit_TextUI_Command->run() phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php:110
PHP 4. PHPUnit_TextUI_TestRunner->doRun() phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php:159
PHP 5. PHP_CodeCoverage_Report_HTML->process() phar:///usr/local/bin/phpunit/phpunit/TextUI/TestRunner.php:501
PHP 6. PHP_CodeCoverage->getReport() phar:///usr/local/bin/phpunit/php-code-coverage/CodeCoverage/Report/HTML.php:68
PHP 7. PHP_CodeCoverage_Report_Factory->create() phar:///usr/local/bin/phpunit/php-code-coverage/CodeCoverage.php:146
PHP 8. PHP_CodeCoverage->getData() phar:///usr/local/bin/phpunit/php-code-coverage/CodeCoverage/Report/Factory.php:25
PHP 9. PHP_CodeCoverage->addUncoveredFilesFromWhitelist() phar:///usr/local/bin/phpunit/php-code-coverage/CodeCoverage.php:182
PHP 10. PHP_CodeCoverage->processUncoveredFileFromWhitelist() phar:///usr/local/bin/phpunit/php-code-coverage/CodeCoverage.php:708
PHP 11. include_once() phar:///usr/local/bin/phpunit/php-code-coverage/CodeCoverage.php:735

@gilbertoalbino
Copy link

Found the solution. Adding the composer autoload.php to PHPUnit xml config file, as is:

<phpunit colors="true" bootstrap="vendor/autoload.php">

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