Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Warning BC Break: `util\Validator::isInRange()` is now inclusive. close #84 #735

Merged
merged 1 commit into from

2 participants

@jails
Collaborator

No description provided.

@nateabele nateabele merged commit d0acd17 into UnionOfRAD:dev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 21 additions and 6 deletions.
  1. +18 −3 tests/cases/util/ValidatorTest.php
  2. +3 −3 util/Validator.php
View
21 tests/cases/util/ValidatorTest.php
@@ -1069,16 +1069,25 @@ public function testCheckMultiplePasses() {
}
public function testIsInRange() {
- $value = 5;
$lower = 1;
$upper = 10;
- $result = Validator::isInRange($value, null, compact('lower', 'upper'));
- $this->assertTrue($result);
$value = 0;
$result = Validator::isInRange($value, null, compact('lower', 'upper'));
$this->assertFalse($result);
+ $value = 1;
+ $result = Validator::isInRange($value, null, compact('lower', 'upper'));
+ $this->assertTrue($result);
+
+ $value = 5;
+ $result = Validator::isInRange($value, null, compact('lower', 'upper'));
+ $this->assertTrue($result);
+
+ $value = 10;
+ $result = Validator::isInRange($value, null, compact('lower', 'upper'));
+ $this->assertTrue($result);
+
$value = 11;
$result = Validator::isInRange($value, null, compact('lower', 'upper'));
$this->assertFalse($result);
@@ -1086,6 +1095,9 @@ public function testIsInRange() {
$result = Validator::isInRange(-1, null, array('upper' => 1));
$this->assertTrue($result);
+ $result = Validator::isInRange(1, null, array('upper' => 1));
+ $this->assertTrue($result);
+
$result = Validator::isInRange(2, null, array('upper' => 1));
$this->assertFalse($result);
@@ -1093,6 +1105,9 @@ public function testIsInRange() {
$this->assertTrue($result);
$result = Validator::isInRange(1, null, array('lower' => 1));
+ $this->assertTrue($result);
+
+ $result = Validator::isInRange(0, null, array('lower' => 1));
$this->assertFalse($result);
$this->assertTrue(Validator::isInRange(0));
View
6 util/Validator.php
@@ -308,11 +308,11 @@ public static function __init() {
}
switch (true) {
case (!is_null($options['upper']) && !is_null($options['lower'])):
- return ($value > $options['lower'] && $value < $options['upper']);
+ return ($value >= $options['lower'] && $value <= $options['upper']);
case (!is_null($options['upper'])):
- return ($value < $options['upper']);
+ return ($value <= $options['upper']);
case (!is_null($options['lower'])):
- return ($value > $options['lower']);
+ return ($value >= $options['lower']);
}
return is_finite($value);
},
Something went wrong with that request. Please try again.