7-2. Performance Regressions
You can extend your test class from PHPUnit2_Extensions_ PerformanceTestCase to test whether the execution of a function or a method call, for instance, exceeds a specified time limit.
Example 8 shows how to subclass PHPUnit2_Extensions_ PerformanceTestCase and use its setMaxRunningTime( ) method to set the maximum running time for the test. If the test is not executed within this time limit, it will be counted as a failure.
Example 8. Using PHPUnit2_Extensions_PerformanceTestCase
<?php
require_once 'PHPUnit2/Extensions/PerformanceTestCase.php';
class PerformanceTest extends PHPUnit2_Extensions_
PerformanceTestCase {
public function testPerformance( ) {
$this->setMaxRunningTime(2);
sleep(1);
}
}
?>
Table 2 shows the external protocol implemented by PHPUnit2_Extensions_PerformanceTestCase.
Table 2. Performance TestCase external protocolsMethod | Description |
|---|
void setMaxRunningTime(integer $maxRunningTime) | Sets the maximum running time for the test to $maxRunningTime (in seconds).. | integer getMaxRunningTime( ) | Returns the maximum running time allowed for the test. |
|