sebastianbergmann / php-token-stream

Wrapper around PHP's tokenizer extension.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Class undefined: PHP_Token_ASYNC

doublecompile opened this issue · comments

I have unit tests for Hack classes that use the async keyword. For example:

<?hh
class Foobar
{
    public async function something(Foo $foo) : Awaitable<Bar>
    {
        await SleepWaitHandle::create(1000);
        return new Bar();
    }
}

When generating code coverage information for classes with the async keyword, an exception is thrown:

Fatal error: Class undefined: PHP_Token_ASYNC in /home/…/vendor/phpunit/php-token-stream/src/Token/Stream.php on line 184

Version Info

  • HHVM 3.7.2
  • PHPUnit 4.7.5
  • PHP_TokenStream 1.4.3

Suggested Fix

My guess is all that's needed is to add the following to src/Token.php.

class PHP_Token_ASYNC extends PHP_Token {}
class PHP_Token_AWAIT extends PHP_Token {}

@sebastianbergmann Hey, thanks for the quick reply, Sebastian.

I'm not sure why there aren't constants for these two keywords. I do know that when I manually added…

class PHP_Token_ASYNC extends PHP_Token {}
class PHP_Token_AWAIT extends PHP_Token {}

…everything works as expected!

I'd be glad to send a pull request if it makes things easier.