public function testParseInteger()
 {
     $this->assertEquals(Validation::parseInteger(1), 1);
     $this->assertEquals(Validation::parseInteger(0), 0);
     $this->assertEquals(Validation::parseInteger(-1), -1);
     $this->assertEquals(Validation::parseInteger("1"), 1);
     $this->assertEquals(Validation::parseInteger("0"), 0);
     $this->assertEquals(Validation::parseInteger("-1"), -1);
     $this->assertNull(Validation::parseInteger("-"));
     $this->assertNull(Validation::parseInteger("true"));
     $this->assertNull(Validation::parseInteger("false"));
     $this->assertNull(Validation::parseInteger(true));
     $this->assertNull(Validation::parseInteger(false));
     $this->assertNull(Validation::parseInteger(4.5));
     $this->assertNull(Validation::parseInteger('4.5'));
     $this->assertNull(Validation::parseInteger(null));
 }
示例#2
0
 /**
  * Returns request variable as explicit integer value, or null if the request variable is not set or does not
  * represent a float value.
  * @param string $key Key in the collection storing the value to look up.
  * @param int $index Index of the array to look up, if the variable's value is an array.
  * @param array $src Array to search for $key, e.g. $_GET or $_POST
  * @return int|null|string
  */
 public static function collectIntegerRequestVar($key, $index = null, $src = null)
 {
     $value = Validation::_parseInput(FILTER_VALIDATE_INT, $key, $index, $src);
     return Validation::parseInteger($value);
 }