public function testIsInteger() { $this->assertTrue(Validation::isInteger(1)); $this->assertTrue(Validation::isInteger(0)); $this->assertTrue(Validation::isInteger(-1)); $this->assertTrue(Validation::isInteger("1")); $this->assertTrue(Validation::isInteger("0")); $this->assertTrue(Validation::isInteger("-1")); $this->assertFalse(Validation::isInteger("-")); $this->assertFalse(Validation::isInteger("true")); $this->assertFalse(Validation::isInteger("false")); $this->assertFalse(Validation::isInteger(true)); $this->assertFalse(Validation::isInteger(false)); $this->assertFalse(Validation::isInteger(4.5)); $this->assertFalse(Validation::isInteger('4.5')); $this->assertFalse(Validation::isInteger(null)); }
/** * Tests a variable and returns its equivalent explicit integer value, or null if the variable value doesn't * represent an integer value. * @param mixed $value Value to test. * @return int|null Value explicitly converted to an integer value, or null if the value does not represent an * integer value. */ public static function parseInteger($value) { if (Validation::isInteger($value)) { return (int) $value; } return null; }