Skip to content
This repository has been archived by the owner on Jul 26, 2021. It is now read-only.

Code Coverage - Arrow functions + PHP 7.4.0alpha2 throws a Fatal error: Uncaught Error: Class 'PHP_Token_FN' not found #83

Closed
xthiago opened this issue Jul 25, 2019 · 5 comments
Assignees

Comments

@xthiago
Copy link

xthiago commented Jul 25, 2019

Q A
PHPUnit version 8.2.5
PHP version PHP 7.4.0alpha2 (cli) (built: Jul 12 2019 01:56:19) ( NTS )
Xdebug version 2.8.0alpha1
Installation Method Composer

I'm testing PHP 7.4.0alpha2 that comes with the ability to create arrow functions.

I got a fatal error when trying to generate a code coverage report with a codebase that uses arrows function like that:

$getPrice = fn(int $total, InventoryItem $item) => $total + $item->price();

The fatal error:

$ phpunit --coverage-text
PHPUnit 8.2.5 by Sebastian Bergmann and contributors.

Fatal error: Uncaught Error: Class 'PHP_Token_FN' not found in /var/www/app/vendor/phpunit/php-token-stream/src/Token/Stream.php on line 182

Error: Class 'PHP_Token_FN' not found in /var/www/app/vendor/phpunit/php-token-stream/src/Token/Stream.php on line 182

Call Stack:
    0.0076     396696   1. {main}() /var/www/app/vendor/phpunit/phpunit/phpunit:0
    0.0874    1167520   2. PHPUnit\TextUI\Command::main() /var/www/app/vendor/phpunit/phpunit/phpunit:61
    0.0875    1167632   3. PHPUnit\TextUI\Command->run() /var/www/app/vendor/phpunit/phpunit/src/TextUI/Command.php:160
    0.3718    3777800   4. PHPUnit\TextUI\TestRunner->doRun() /var/www/app/vendor/phpunit/phpunit/src/TextUI/Command.php:201
    0.5352    4508032   5. PHPUnit\Framework\TestSuite->run() /var/www/app/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:619
    0.5477    4508224   6. PHPUnit\Framework\TestSuite->run() /var/www/app/vendor/phpunit/phpunit/src/Framework/TestSuite.php:568
    0.5617    4509688   7. PHPUnit\Framework\DataProviderTestSuite->run() /var/www/app/vendor/phpunit/phpunit/src/Framework/TestSuite.php:568
    0.5624    4509880   8. Xthiago\FooTest->run() /var/www/app/vendor/phpunit/phpunit/src/Framework/TestSuite.php:568
    0.5626    4509880   9. PHPUnit\Framework\TestResult->run() /var/www/app/vendor/phpunit/phpunit/src/Framework/TestCase.php:677
    0.6384    4716408  10. SebastianBergmann\CodeCoverage\CodeCoverage->stop() /var/www/app/vendor/phpunit/phpunit/src/Framework/TestResult.php:795
    0.9747    5306424  11. SebastianBergmann\CodeCoverage\CodeCoverage->append() /var/www/app/vendor/phpunit/php-code-coverage/src/CodeCoverage.php:268
    0.9765    5314704  12. SebastianBergmann\CodeCoverage\CodeCoverage->applyIgnoredLinesFilter() /var/www/app/vendor/phpunit/php-code-coverage/src/CodeCoverage.php:299
    1.0183    5677792  13. SebastianBergmann\CodeCoverage\CodeCoverage->getLinesToBeIgnored() /var/www/app/vendor/phpunit/php-code-coverage/src/CodeCoverage.php:556
    1.0183    5677792  14. SebastianBergmann\CodeCoverage\CodeCoverage->getLinesToBeIgnoredInner() /var/www/app/vendor/phpunit/php-code-coverage/src/CodeCoverage.php:615
    1.0241    5700960  15. PHP_Token_Stream->__construct() /var/www/app/vendor/phpunit/php-code-coverage/src/CodeCoverage.php:638
    1.0269    5709152  16. PHP_Token_Stream->scan() /var/www/app/vendor/phpunit/php-token-stream/src/Token/Stream.php:112

The code coverage report generation works fine after refactoring the arrows functions to old-style anonymous functions:

$getPrice = function (int $total, InventoryItem $item) { return $total + $item->price(); };

I'm not sure it must be reported here or in sebastianbergmann/php-token-stream.

@sebastianbergmann sebastianbergmann transferred this issue from sebastianbergmann/phpunit Jul 25, 2019
@sebastianbergmann
Copy link
Owner

Should be taken care of by e899757.

@xthiago
Copy link
Author

xthiago commented Jul 25, 2019

Yes, it works. Thank you!

@NicklasWallgren
Copy link

@sebastianbergmann We have encountered this issue with PHP 7.4, on phpunit/phpunit ^6.1

It might be a good idea to port this to earlier versions of the library, for example the 2.0 branch. Would you accept a PR?

@sebastianbergmann
Copy link
Owner

PHPUnit 6 is not supported on PHP 7.4: https://phpunit.de/supported-versions.html

@NicklasWallgren
Copy link

Okey, thanks for the clarification.

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

No branches or pull requests

3 participants