Unit Tests: PHP 5.2, I Hate You and You Are Bringing Me Down.
#YOLOFriday See #30017, #33968. git-svn-id: https://develop.svn.wordpress.org/trunk@35226 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
e70ebea219
commit
61edcd5021
@ -4,7 +4,7 @@
|
|||||||
* A PHPUnit TestListener that exposes your slowest running tests by outputting
|
* A PHPUnit TestListener that exposes your slowest running tests by outputting
|
||||||
* results directly to the console.
|
* results directly to the console.
|
||||||
*/
|
*/
|
||||||
class SpeedTrapListener implements \PHPUnit_Framework_TestListener
|
class SpeedTrapListener implements PHPUnit_Framework_TestListener
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Internal tracking for test suites.
|
* Internal tracking for test suites.
|
||||||
@ -51,77 +51,77 @@ class SpeedTrapListener implements \PHPUnit_Framework_TestListener
|
|||||||
/**
|
/**
|
||||||
* An error occurred.
|
* An error occurred.
|
||||||
*
|
*
|
||||||
* @param \PHPUnit_Framework_Test $test
|
* @param PHPUnit_Framework_Test $test
|
||||||
* @param \Exception $e
|
* @param Exception $e
|
||||||
* @param float $time
|
* @param float $time
|
||||||
*/
|
*/
|
||||||
public function addError(\PHPUnit_Framework_Test $test, \Exception $e, $time)
|
public function addError(PHPUnit_Framework_Test $test, Exception $e, $time)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A failure occurred.
|
* A failure occurred.
|
||||||
*
|
*
|
||||||
* @param \PHPUnit_Framework_Test $test
|
* @param PHPUnit_Framework_Test $test
|
||||||
* @param \PHPUnit_Framework_AssertionFailedError $e
|
* @param PHPUnit_Framework_AssertionFailedError $e
|
||||||
* @param float $time
|
* @param float $time
|
||||||
*/
|
*/
|
||||||
public function addFailure(\PHPUnit_Framework_Test $test, \PHPUnit_Framework_AssertionFailedError $e, $time)
|
public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Incomplete test.
|
* Incomplete test.
|
||||||
*
|
*
|
||||||
* @param \PHPUnit_Framework_Test $test
|
* @param PHPUnit_Framework_Test $test
|
||||||
* @param \Exception $e
|
* @param Exception $e
|
||||||
* @param float $time
|
* @param float $time
|
||||||
*/
|
*/
|
||||||
public function addIncompleteTest(\PHPUnit_Framework_Test $test, \Exception $e, $time)
|
public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Risky test.
|
* Risky test.
|
||||||
*
|
*
|
||||||
* @param \PHPUnit_Framework_Test $test
|
* @param PHPUnit_Framework_Test $test
|
||||||
* @param \Exception $e
|
* @param Exception $e
|
||||||
* @param float $time
|
* @param float $time
|
||||||
* @since Method available since Release 4.0.0
|
* @since Method available since Release 4.0.0
|
||||||
*/
|
*/
|
||||||
public function addRiskyTest(\PHPUnit_Framework_Test $test, \Exception $e, $time)
|
public function addRiskyTest(PHPUnit_Framework_Test $test, Exception $e, $time)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Skipped test.
|
* Skipped test.
|
||||||
*
|
*
|
||||||
* @param \PHPUnit_Framework_Test $test
|
* @param PHPUnit_Framework_Test $test
|
||||||
* @param \Exception $e
|
* @param Exception $e
|
||||||
* @param float $time
|
* @param float $time
|
||||||
*/
|
*/
|
||||||
public function addSkippedTest(\PHPUnit_Framework_Test $test, \Exception $e, $time)
|
public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A test started.
|
* A test started.
|
||||||
*
|
*
|
||||||
* @param \PHPUnit_Framework_Test $test
|
* @param PHPUnit_Framework_Test $test
|
||||||
*/
|
*/
|
||||||
public function startTest(\PHPUnit_Framework_Test $test)
|
public function startTest(PHPUnit_Framework_Test $test)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A test ended.
|
* A test ended.
|
||||||
*
|
*
|
||||||
* @param \PHPUnit_Framework_Test $test
|
* @param PHPUnit_Framework_Test $test
|
||||||
* @param float $time
|
* @param float $time
|
||||||
*/
|
*/
|
||||||
public function endTest(\PHPUnit_Framework_Test $test, $time)
|
public function endTest(PHPUnit_Framework_Test $test, $time)
|
||||||
{
|
{
|
||||||
if (!$test instanceof \PHPUnit_Framework_TestCase) return;
|
if (!$test instanceof PHPUnit_Framework_TestCase) return;
|
||||||
|
|
||||||
$time = $this->toMilliseconds($time);
|
$time = $this->toMilliseconds($time);
|
||||||
$threshold = $this->getSlowThreshold($test);
|
$threshold = $this->getSlowThreshold($test);
|
||||||
@ -134,9 +134,9 @@ class SpeedTrapListener implements \PHPUnit_Framework_TestListener
|
|||||||
/**
|
/**
|
||||||
* A test suite started.
|
* A test suite started.
|
||||||
*
|
*
|
||||||
* @param \PHPUnit_Framework_TestSuite $suite
|
* @param PHPUnit_Framework_TestSuite $suite
|
||||||
*/
|
*/
|
||||||
public function startTestSuite(\PHPUnit_Framework_TestSuite $suite)
|
public function startTestSuite(PHPUnit_Framework_TestSuite $suite)
|
||||||
{
|
{
|
||||||
$this->suites++;
|
$this->suites++;
|
||||||
}
|
}
|
||||||
@ -144,9 +144,9 @@ class SpeedTrapListener implements \PHPUnit_Framework_TestListener
|
|||||||
/**
|
/**
|
||||||
* A test suite ended.
|
* A test suite ended.
|
||||||
*
|
*
|
||||||
* @param \PHPUnit_Framework_TestSuite $suite
|
* @param PHPUnit_Framework_TestSuite $suite
|
||||||
*/
|
*/
|
||||||
public function endTestSuite(\PHPUnit_Framework_TestSuite $suite)
|
public function endTestSuite(PHPUnit_Framework_TestSuite $suite)
|
||||||
{
|
{
|
||||||
$this->suites--;
|
$this->suites--;
|
||||||
|
|
||||||
@ -174,10 +174,10 @@ class SpeedTrapListener implements \PHPUnit_Framework_TestListener
|
|||||||
/**
|
/**
|
||||||
* Stores a test as slow.
|
* Stores a test as slow.
|
||||||
*
|
*
|
||||||
* @param \PHPUnit_Framework_TestCase $test
|
* @param PHPUnit_Framework_TestCase $test
|
||||||
* @param int $time Test execution time in milliseconds
|
* @param int $time Test execution time in milliseconds
|
||||||
*/
|
*/
|
||||||
protected function addSlowTest(\PHPUnit_Framework_TestCase $test, $time)
|
protected function addSlowTest(PHPUnit_Framework_TestCase $test, $time)
|
||||||
{
|
{
|
||||||
$label = $this->makeLabel($test);
|
$label = $this->makeLabel($test);
|
||||||
|
|
||||||
@ -208,10 +208,10 @@ class SpeedTrapListener implements \PHPUnit_Framework_TestListener
|
|||||||
/**
|
/**
|
||||||
* Label for describing a test.
|
* Label for describing a test.
|
||||||
*
|
*
|
||||||
* @param \PHPUnit_Framework_TestCase $test
|
* @param PHPUnit_Framework_TestCase $test
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function makeLabel(\PHPUnit_Framework_TestCase $test)
|
protected function makeLabel(PHPUnit_Framework_TestCase $test)
|
||||||
{
|
{
|
||||||
return sprintf('%s:%s', get_class($test), $test->getName());
|
return sprintf('%s:%s', get_class($test), $test->getName());
|
||||||
}
|
}
|
||||||
@ -298,14 +298,14 @@ class SpeedTrapListener implements \PHPUnit_Framework_TestListener
|
|||||||
* reaches 5000ms (5 seconds):
|
* reaches 5000ms (5 seconds):
|
||||||
*
|
*
|
||||||
* <code>
|
* <code>
|
||||||
* \@slowThreshold 5000
|
* @slowThreshold 5000
|
||||||
* public function testLongRunningProcess() {}
|
* public function testLongRunningProcess() {}
|
||||||
* </code>
|
* </code>
|
||||||
*
|
*
|
||||||
* @param \PHPUnit_Framework_TestCase $test
|
* @param PHPUnit_Framework_TestCase $test
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
protected function getSlowThreshold(\PHPUnit_Framework_TestCase $test)
|
protected function getSlowThreshold(PHPUnit_Framework_TestCase $test)
|
||||||
{
|
{
|
||||||
$ann = $test->getAnnotations();
|
$ann = $test->getAnnotations();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user