Adding another compatibility test method: assertWithinMargin

This commit is contained in:
José Lorenzo Rodríguez 2010-05-09 18:16:42 -04:30
parent 88d21fbea4
commit 508d707a7a

View file

@ -480,5 +480,19 @@ class CakeTestCase extends PHPUnit_Framework_TestCase {
protected function assertReference(&$first, &$second, $message = '') {
return $this->assertSame($first, $second, $message);
}
/**
* Compatibility function to test if value is between an acceptable range
* @param mixed $value
* @param mixed $expected
* @param mixed $margin the rage of acceptation
* @param string $message the text to display if the assertion is not correct
* @return void
*/
protected function assertWithinMargin($value, $expected, $margin, $message = '') {
$upper = $value + $margin;
$lower = $value - $margin;
$this->assertTrue((($expected <= $upper) && ($expected >= $lower)), $message);
}
}
?>