phpunit - 在 php 8.1.0 上使用 phpunit 9.4 捕获警告、通知和弃用

引用 https://phpunit.readthedocs.io/en/9.5/writing-tests-for-phpunit.html#testing-php-errors-warnings-and-notices , "默认情况下,PHPUnit 将在执行测试期间触发的 PHP 错误、警告和通知转换为异常"。牢记这一点,这是我的单元测试:

<?php

class DemoTest extends PHPUnit\Framework\TestCase
{
    public function testDemo()
    {
        try {
            trigger_error('zzz', E_USER_DEPRECATED);
        } catch (\Throwable $e) {}
    }
}

当我在 PHP 8.0.9 上使用 PHPUnit 9.4.0 运行 vendor/bin/phpunit 时,我得到以下信息(输出的不相关部分已被删除):

PHPUnit 9.4.0 by Sebastian Bergmann and contributors.

R                                                                   1 / 1 (100%)

当我在 PHPUnit 9.4.0 和 PHP 8.1.0 上运行 vendor/bin/phpunit 时,我得到以下信息:

Deprecated: PHPUnit\Runner\DefaultTestResultCache implements the Serializable interface, which is deprecated. Implement __serialize() and __unserialize() instead (or in addition, if support for old PHP versions is necessary) in C:\path\to\code\vendor\phpunit\phpunit\src\Runner\DefaultTestResultCache.php on line 34
PHPUnit 9.4.0 by Sebastian Bergmann and contributors.

R                                                                   1 / 1 (100%)

即。在 PHP 8.1 中,我得到了 Throwable 的完整转储,包括堆栈跟踪,而在 PHP 8.0 中我没有得到它。

有什么想法吗?我不想在输出中看到错误,如果没有抛出异常,则 $this->expectException('PHPUnit\\Framework\\Error\\Deprecated')也不适合我

最佳答案

这是 PHPUnit 与 PHP 8.1 的不兼容性,并且已经在 9.5.5 中得到修复。 , 所以你需要更新。

9.4 不再是受支持的版本。

https://stackoverflow.com/questions/70321515/

相关文章:

microsoft-graph-api - MS Graph Mail 在商店中找不到指定的对象

python - 字典理解 Python

python - 过滤列,指定区分大小写

rust - 在 ".map(|x| *x)"之前是否有更好的 ".collect()"替代品?

go - 为什么 DefaultMask() 方法在 Golang 中有一个 IP 类型的接收者?

python - 使用正则表达式 python 删除德语中的女性结尾

spring - 摆脱 spring-boot-starter-data-mongodb 对易受攻击

kotlin - 在 kotlin 中更改变量内部参数的值

javascript - 如何使用顺风向表格添加间距

amazon-web-services - Docker 推送错误保存凭据 : error stor