这似乎只发生在我的系统上。没有其他人可以复制它。如果错误消息太大(在我的例子中大约 65k 字节),屏幕上不会打印任何内容。我在 Windows 7 上使用 PHP 7.1.3,默认的 php.ini(内存限制设置为 8gb)和默认的 PHPUnit 6.0.13 配置。该错误不会出现在提示符和 powershell 中。
<?php
use PHPUnit\Framework\Constraint\Constraint;
use PHPUnit\Framework\TestCase;
class MyConstraint extends Constraint
{
protected $expected;
function __construct($expected){
parent::__construct();
$this->expected = $expected;
}
protected function matches($actual){
return false;
}
function failureDescription($other): string{
return "desc";
}
function toString(){
return "description";
}
function additionalFailureDescription($other): string{
return str_repeat("x", 100000);
// If set to a smaller dump, error will appear
// some people I asked to try could dump one million
// bytes without problems, while I can't print more
// than about 50k
}
}
class SomeTest extends TestCase
{
function testBigDump(){
TestCase::assertThat("irrelevant", new MyConstraint("irrelevant"));
}
}
?>
这是我在屏幕上看到的:
PHPUnit 6.0.13 by Sebastian Bergmann and contributors.
Runtime: PHPDBG 7.1.3 Configuration: ..............
F 1 / 1 (100%)
Time: 361 ms, Memory: 6.00MB
There was 1 failure:
1) SomeTest::testBigDump
<------- Notice no error description here
FAILURES! Tests: 1, Assertions: 1, Failures: 1.
您知道是什么原因造成的吗?提前谢谢你。
最佳答案
您的配置中的某些东西正在通过 phpdbg 运行 phpunit 测试
我重现了这个问题,尝试使用 Windows 7 VM 尽可能多地复制环境。
线索是转储中的 Runtime: PHPDBG
行。显然,关于 phpdbg 运行时的一些事情会阻止大缓冲区正常工作。请参阅下面的输出,包括通过 phpdbg.exe 运行时的初始输出(缺少测试描述)以及通过 php.exe 运行时的初始输出(显然被截断了):
C:\project>phpdbg -r phpunit-6.1.0.phar -v test.php
[Welcome to phpdbg, the interactive PHP debugger, v0.5.0]
To get help using phpdbg type "help" and press enter
[Please report bugs to <http://bugs.php.net/report.php>]
PHPUnit 6.1.0 by Sebastian Bergmann and contributors.
Runtime: PHPDBG 7.1.4
F 1 / 1 (100%)
Time: 99 ms, Memory: 22.00MB
There was 1 failure:
1) SomeTest::testBigDump
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
[Script ended normally]
C:\project>php phpunit-6.1.0.phar test.php
PHPUnit 6.1.0 by Sebastian Bergmann and contributors.
F 1 / 1 (100%)
Time: 109 ms, Memory: 8.00MB
There was 1 failure:
1) SomeTest::testBigDump
Failed asserting that desc.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
----- Snip -----
关于php - 什么会导致 PHPUnit 不打印非常大的错误消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43245240/