Reputation: 520
I am studying phpunit and I have noticed when my assert fails the summary takes a lot of time to show the result (but not when the test is correct).
For example if I run this test, it takes half second to show the the green bar:
<?php
class SomeTest extends PHPUnit_Framework_TestCase {
public function testSomething() {
$this->assertTrue(true);
}
}
?>
But the same test with a fail assert takes 12 seconds to show the red bar:
<?php
class SomeTest extends PHPUnit_Framework_TestCase {
public function testSomething() {
$this->assertTrue(false);
}
}
?>
Now this time is not acceptable if I need to run tests continuously during the developing. What can I do to speed up the process?
Upvotes: 2
Views: 593
Reputation: 648
I have had the same problem since I upgraded to php 5.4 / phpunit 3.7.24 on a windows 7 box. I debugged and found out that PHPUnit_Util_GlobalState#phpunitFiles() is the culprit, it spends around 7 seconds finding PHPUnit and PEAR files to filter out from the stack trace.
I filed an issue : https://github.com/sebastianbergmann/phpunit/issues/1007
For the moment as a workaround I'll try to cache the files array on disk
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;
}
Upvotes: 3