这似乎只发生在我的系统上。没有人可以重现它。如果错误消息太大(在我的情况下大约为65k字节),则屏幕上不会打印任何内容。我在Windows 7上使用PHP 7.1.3,默认的php.ini(内存限制设置为8GB)和默认的PHPUnit 6.0.13配置。错误不会出现在提示和PowerShell中。什么可能导致PHPUnit不能打印非常大的错误消息?
<?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塞巴斯蒂安·伯格曼和贡献者。
运行时:7.1.3 PHPDBG配置:..............
f 1的/ 1(100%)
时间:361毫秒,内存:6.00 MB
有1次失败:
1)SomeTest :: testBigDump
<------- Notice no error description here
FAILURES!测试:1,断言:1,失败:1.
你有什么想法可能会导致这种情况?先谢谢你。
PHP记忆似乎要被罚款。你会得到不同的错误。您是否尝试将测试的输出重定向到文件?也许你的命令行没有足够的内存来显示这么长的字符串。如果您可以发布完整的工作示例而不是伪代码,这将会很有帮助,因此其他人可以尝试复制它。 –
那不是伪代码。这只会导致错误 – Wes