Skip to content

Commit

Permalink
Add a note and more tests for Validation::isScalar()
Browse files Browse the repository at this point in the history
  • Loading branch information
chinpei215 committed Jul 26, 2017
1 parent 21415a2 commit 60e082b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/Validation/Validation.php
Expand Up @@ -1426,6 +1426,9 @@ public static function isArray($value)
/**
* Check that the input value is a scalar.
*
* This method will accept integers, floats, strings and booleans, but
* not accept arrays, objects, resources and nulls.
*
* @param mixed $value The value to check
* @return bool
*/
Expand Down
7 changes: 6 additions & 1 deletion tests/TestCase/Validation/ValidationTest.php
Expand Up @@ -2886,8 +2886,13 @@ public function testIsArray()
public function testIsScalar()
{
$this->assertTrue(Validation::isScalar(1));
$this->assertTrue(Validation::isScalar(0.0));
$this->assertTrue(Validation::isScalar(''));
$this->assertTrue(Validation::isScalar(true));
$this->assertFalse(Validation::isScalar([1]));
$this->assertFalse(Validation::isScalar(new stdClass()));
$this->assertFalse(Validation::isScalar(STDOUT));
$this->assertFalse(Validation::isScalar(null));
}

/**
Expand Down Expand Up @@ -3009,7 +3014,7 @@ public function testNumElements()
};

$this->assertFalse(Validation::numElements(null, '==', 0));
$this->assertFalse(Validation::numElements(new \stdClass(), '==', 0));
$this->assertFalse(Validation::numElements(new stdClass(), '==', 0));
$this->assertFalse(Validation::numElements($callable, '==', 0));
$this->assertFalse(Validation::numElements(false, '==', 0));
$this->assertFalse(Validation::numElements(true, '==', 0));
Expand Down

0 comments on commit 60e082b

Please sign in to comment.