1
0
mirror of https://github.com/fzaninotto/Faker.git synced 2025-03-25 17:59:47 +01:00

Fix numberBetween max default value handling

Closes #305
This commit is contained in:
Francois Zaninotto 2014-04-21 22:03:38 +02:00
parent 470033ae8e
commit d022072b5a
2 changed files with 9 additions and 4 deletions

View File

@ -102,15 +102,15 @@ class Base
/**
* Returns a random number between $from and $to
*
* @param integer $from
* @param integer $to
* @param integer $from default to 0
* @param integer $to defaults to 32 bit max integer, ie 2147483647
* @example 79907610
*
* @return integer
*/
public static function numberBetween($from = null, $to = null)
public static function numberBetween($from = 0, $to = 2147483647)
{
return mt_rand($from ?: 0, $to ?: 2147483647); // 32bit compat default
return mt_rand($from, $to);
}
/**

View File

@ -52,6 +52,11 @@ class BaseTest extends \PHPUnit_Framework_TestCase
$this->assertGreaterThanOrEqual(BaseProvider::numberBetween($min, $max), $max);
}
public function testNumberBetweenAcceptsZeroAsMax()
{
$this->assertEquals(0, BaseProvider::numberBetween(0, 0));
}
public function testRandomFloat()
{
$min = 4;