diff --git a/src/Valitron/Validator.php b/src/Valitron/Validator.php index eb6c932..1e3bc3c 100644 --- a/src/Valitron/Validator.php +++ b/src/Valitron/Validator.php @@ -301,7 +301,11 @@ class Validator */ protected function validateMin($field, $value, $params) { - return !(bccomp($params[0], $value, 14) == 1); + 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) { - return !(bccomp($value, $params[0], 14) == 1); + if (function_exists('bccomp')) { + return !(bccomp($value, $params[0], 14) == 1); + } else { + return $params[0] >= $value; + } } /** diff --git a/tests/Valitron/ValidateTest.php b/tests/Valitron/ValidateTest.php index ebd4fc9..a05bd7d 100644 --- a/tests/Valitron/ValidateTest.php +++ b/tests/Valitron/ValidateTest.php @@ -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());