PHPUnit - Fatal error: Method PHPUnit_Framework_AssertionFailedError::__toString() must not throw an exception in... when a test class is empty?

PHPUnit - Fatal error: Method PHPUnit_Framework_AssertionFailedError::__toString() must not throw an exception in... when a test class is empty?

我刚开始学习 PHPUnit,当我创建一个像这样的空 class 时:

<?php

namespace some\ns;

use some\ns\AClass;

/**
 * Test class for the some\ns\AClass class
 */
class AClassTest extends \PHPUnit_Framework_TestCase {

}

当我运行测试时:

$ phpunit -c .
PHPUnit 4.3.5 by Sebastian Bergmann.

Configuration read from path/to/phpunit.xml.dist

F

Time: 281 ms, Memory: 3.50Mb

There was 1 failure:

1) Warning

Fatal error: Method PHPUnit_Framework_AssertionFailedError::__toString() must not throw an exception in phar:///usr/local/bin/phpunit/phpunit/TextUI/ResultPrinter.php on line 0

Call Stack:
    0.0329     339512   1. {main}() /usr/local/bin/phpunit:0
    0.0330     339512   2. {main}() /usr/local/bin/phpunit:0
    0.1409     779176   3. PHPUnit_TextUI_Command::main() /usr/local/bin/phpunit:605
    0.1409     779424   4. PHPUnit_TextUI_Command::main() /usr/local/bin/phpunit:605
    0.1409     780048   5. PHPUnit_TextUI_Command->run() phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php:138
    0.1410     780544   6. PHPUnit_TextUI_Command->run() phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php:138
    0.2650    2779792   7. PHPUnit_TextUI_TestRunner->doRun() phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php:186
    0.2650    2780016   8. PHPUnit_TextUI_TestRunner->doRun() phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php:186
    0.2806    3526000   9. PHPUnit_TextUI_ResultPrinter->printResult() phar:///usr/local/bin/phpunit/phpunit/TextUI/TestRunner.php:429
    0.2806    3526360  10. PHPUnit_TextUI_ResultPrinter->printResult() phar:///usr/local/bin/phpunit/phpunit/TextUI/TestRunner.php:429
    0.2808    3529928  11. PHPUnit_TextUI_ResultPrinter->printFailures() phar:///usr/local/bin/phpunit/phpunit/TextUI/ResultPrinter.php:177
    0.2808    3530160  12. PHPUnit_TextUI_ResultPrinter->printFailures() phar:///usr/local/bin/phpunit/phpunit/TextUI/ResultPrinter.php:177
    0.2808    3530464  13. PHPUnit_TextUI_ResultPrinter->printDefects() phar:///usr/local/bin/phpunit/phpunit/TextUI/ResultPrinter.php:288
    0.2808    3530464  14. PHPUnit_TextUI_ResultPrinter->printDefects() phar:///usr/local/bin/phpunit/phpunit/TextUI/ResultPrinter.php:288
    0.2808    3530960  15. PHPUnit_TextUI_ResultPrinter->printDefect() phar:///usr/local/bin/phpunit/phpunit/TextUI/ResultPrinter.php:233
    0.2808    3531192  16. PHPUnit_TextUI_ResultPrinter->printDefect() phar:///usr/local/bin/phpunit/phpunit/TextUI/ResultPrinter.php:233
    0.2809    3532280  17. PHPUnit_TextUI_ResultPrinter->printDefectTrace() phar:///usr/local/bin/phpunit/phpunit/TextUI/ResultPrinter.php:244
    0.2809    3532512  18. PHPUnit_TextUI_ResultPrinter->printDefectTrace() phar:///usr/local/bin/phpunit/phpunit/TextUI/ResultPrinter.php:244

引发此异常。出于好奇,有人能告诉我为什么吗?

感谢 Sebastian Bergmann 在 GitHub 上的回答:

https://github.com/sebastianbergmann/phpunit/issues/1598#issuecomment-72880416

似乎用 PHPUnit 配置 XML 文件的 bootstrap 参数指定的自动加载器在找不到 class 的文件时不能抛出任何异常。

这也是 PSR-4 规范规定的内容:

Autoloader implementations MUST NOT throw exceptions, MUST NOT raise errors of any level, and SHOULD NOT return a value.

我不得不更换自动装带器。现在它不会抛出任何类型的异常并且一切正常!

无论如何,只是想知道,为什么在错误 PHPUnit_Framework_AssertionFailedError 中没有提及我的自动加载器过去抛出的异常?