mirror of
https://github.com/vlucas/valitron.git
synced 2025-12-30 23:01:52 +00:00
Made the BC Math extension optional
This commit is contained in:
parent
c984bc100e
commit
f52df87b56
@ -301,7 +301,11 @@ class Validator
|
||||
*/
|
||||
protected function validateMin($field, $value, $params)
|
||||
{
|
||||
if (function_exists('bccomp')) {
|
||||
return !(bccomp($params[0], $value, 14) == 1);
|
||||
} else {
|
||||
return $params[0] <= $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -315,7 +319,11 @@ class Validator
|
||||
*/
|
||||
protected function validateMax($field, $value, $params)
|
||||
{
|
||||
if (function_exists('bccomp')) {
|
||||
return !(bccomp($value, $params[0], 14) == 1);
|
||||
} else {
|
||||
return $params[0] >= $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -188,6 +188,10 @@ class ValidateTest extends BaseTestCase
|
||||
|
||||
public function testMinValidFloat()
|
||||
{
|
||||
if (!function_exists('bccomp')) {
|
||||
$this->markTestSkipped("Floating point comparison requires the BC Math extension to be installed");
|
||||
}
|
||||
|
||||
$v = new Validator(array('num' => 0.9));
|
||||
$v->rule('min', 'num', 0.5);
|
||||
$this->assertTrue($v->validate());
|
||||
@ -224,6 +228,10 @@ class ValidateTest extends BaseTestCase
|
||||
|
||||
public function testMaxValidFloat()
|
||||
{
|
||||
if (!function_exists('bccomp')) {
|
||||
$this->markTestSkipped("Accurate floating point comparison requires the BC Math extension to be installed");
|
||||
}
|
||||
|
||||
$v = new Validator(array('num' => 0.4));
|
||||
$v->rule('max', 'num', 0.5);
|
||||
$this->assertTrue($v->validate());
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user