自从我在 Windows 7 机器上升级到 php 5.4 / phpunit 3.7.24 后,我遇到了同样的问题。我调试并发现 PHPUnit_Util_GlobalState#phpunitFiles() 是罪魁祸首,它花了大约 7 秒的时间找到 PHPUnit 和 PEAR 文件以从堆栈跟踪中过滤掉。
我提出了一个问题:https ://github.com/sebastianbergmann/phpunit/issues/1007
目前作为一种解决方法,我将尝试在磁盘上缓存文件数组
public static function phpunitFiles()
{
if (self::$phpunitFiles === NULL) {
$phpunitFilesCache = '/path/to/my/file/phpunitFiles'; // CHANGED
if (is_file($phpunitFilesCache)) { // CHANGED
self::$phpunitFiles = unserialize(file_get_contents($phpunitFilesCache)); // CHANGED
return self::$phpunitFiles; // CHANGED
} // CHANGED
self::addDirectoryContainingClassToPHPUnitFilesList('File_Iterator');
self::addDirectoryContainingClassToPHPUnitFilesList('PHP_CodeCoverage');
self::addDirectoryContainingClassToPHPUnitFilesList('PHP_Invoker');
self::addDirectoryContainingClassToPHPUnitFilesList('PHP_Timer');
self::addDirectoryContainingClassToPHPUnitFilesList('PHP_Token');
self::addDirectoryContainingClassToPHPUnitFilesList('PHPUnit_Framework_TestCase', 2);
self::addDirectoryContainingClassToPHPUnitFilesList('PHPUnit_Extensions_Database_TestCase', 2);
self::addDirectoryContainingClassToPHPUnitFilesList('PHPUnit_Framework_MockObject_Generator', 2);
self::addDirectoryContainingClassToPHPUnitFilesList('PHPUnit_Extensions_SeleniumTestCase', 2);
self::addDirectoryContainingClassToPHPUnitFilesList('PHPUnit_Extensions_Story_TestCase', 2);
self::addDirectoryContainingClassToPHPUnitFilesList('Text_Template');
file_put_contents($phpunitFilesCache, serialize(self::$phpunitFiles)); // CHANGED
}
return self::$phpunitFiles;
}