如何使 phpunit @expectedException 与 hhvm 一起工作?

How to make phpunit @expectedException work with hhvm?

我的项目中有一些PHP单元测试,其中一些使用了@expectedException 特性,如下所示。

/**
 * @expectedException League\OAuth2\Client\Provider\Exception\IdentityProviderException
 **/
public function testExceptionThrownWhenErrorObjectReceived()
{
    ...
}

/**
 * @expectedException League\OAuth2\Client\Provider\Exception\IdentityProviderException
 **/
public function testExceptionThrownWhenOAuthErrorReceived()
{
    ...
}

/**
 * @expectedException UnexpectedValueException
 **/
public function testExceptionThrownWhenAskingForResourceOwner()
{
    ...
}

我 运行 他们在 travis 的帮助下 PHP 5.6、7.0、7.1 和 7.2 没有问题,但是 HHVM 失败了:

There were 3 errors:
1) Mrjoops\OAuth2\Client\Test\Provider\JiraTest::testExceptionThrownWhenErrorObjectReceived
Mrjoops\OAuth2\Client\Provider\Exception\JiraIdentityProviderException: Validation Failed
2) Mrjoops\OAuth2\Client\Test\Provider\JiraTest::testExceptionThrownWhenOAuthErrorReceived
Mrjoops\OAuth2\Client\Provider\Exception\JiraIdentityProviderException: error_collection
3) Mrjoops\OAuth2\Client\Test\Provider\JiraTest::testExceptionThrownWhenAskingForResourceOwner
UnexpectedValueException: Invalid response received from Authorization Server. Expected JSON.

我使用最新的 PHPUnit 5.7 版本(为了 PHP 5.6 兼容性)和最新的 HHVM 3.29.1。

Travis 在他们的网站上写道:

Please note that if you want to run PHPUnit on HHVM, you have to explicitly install version 5.7 in your .travis.yml due to a compatibility issue between HHVM and PHP7

所以我想我还好。

我知道有一个已知问题 (https://github.com/sebastianbergmann/phpunit/issues/1640) which was unresolved and closed in PHPUnit, and an inconsistency documented in HHVM (https://github.com/hhvm/user-documentation/blob/master/guides/hhvm/06-inconsistencies/03-classes-and-objects.md),但我不清楚是否存在解决方法。

此处提供详细信息:

预先感谢您的帮助。

您可以尝试使用:

$this->expectException(UnexpectedValueException::class);

但我想这会引发同样的问题。或者您尝试使用解决方法:

try {
    doSomething();
} catch (Exception $ex) {
    $this->assertInstanceOf(UnexpectedValueException::class, $ex);
}
$this->fail('Exception did not occur');

但我想问的是,HHVM 是否真的 want/have 支持?许多主要框架和应用程序(composer、symfony 等)都放弃了对它的支持: https://github.com/facebook/hhvm/issues/7198