【问题标题】:How can I test the require function in PHPUnit? Expect E_COMPILE_ERROR如何在 PHPUnit 中测试 require 函数?期望 E_COMPILE_ERROR
【发布时间】:2020-02-22 17:33:18
【问题描述】:

我在文档中发现错误测试:

$this->expectError();
$this->expectErrorMessage('foo');
\trigger_error('foo', \E_USER_ERROR);

但这不适用于我的示例:

$this->expectError();
$this->expectErrorMessageMatches( '/test/' );
require 'test.php';

因为需要它是 E_COMPILE_ERROR。我在文档中没有找到如何测试这一点?

【问题讨论】:

  • 但是如果连代码都编译不出来,为什么还要测试呢?

标签: php unit-testing phpunit


【解决方案1】:

这对我有用。在错误之前添加此代码:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-02-10
    • 2011-10-23
    • 2021-07-25
    • 2012-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多