2017-04-06 64 views
10

这似乎只发生在我的系统上。没有人可以重现它。如果错误消息太大(在我的情况下大约为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.

你有什么想法可能会导致这种情况?先谢谢你。

+0

PHP记忆似乎要被罚款。你会得到不同的错误。您是否尝试将测试的输出重定向到文件?也许你的命令行没有足够的内存来显示这么长的字符串。如果您可以发布完整的工作示例而不是伪代码,这将会很有帮助,因此其他人可以尝试复制它。 –

+0

那不是伪代码。这只会导致错误 – Wes

回答

9

的东西在你的配置是通过phpdbg

我重建这个问题,试图复制使用Windows 7虚拟机环境尽可能地运行PHPUnit测试。

线索是您的转储中的Runtime: PHPDBG行。显然,有关phpdbg运行时的一些情况会阻止大缓冲区正常工作。见下面我的输出,无论何时通过的php.exe运行时通过phpdbg.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 ----- 
相关问题