Skip to content

Commit e7f9a7f

Browse files
authored
Ensure that randomNumber holds a default nullable option (#291)
Co-authored-by: Pim Jansen <[email protected]>
1 parent 1c31e25 commit e7f9a7f

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/Faker/Generator.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,10 @@ public function randomFloat($nbMaxDecimals = null, $min = 0, $max = null): float
470470
*/
471471
public function randomNumber($nbDigits = null, $strict = false): int
472472
{
473-
return $this->ext(Extension\NumberExtension::class)->randomNumber((int) $nbDigits, (bool) $strict);
473+
return $this->ext(Extension\NumberExtension::class)->randomNumber(
474+
$nbDigits !== null ? (int) $nbDigits : null,
475+
(bool) $strict
476+
);
474477
}
475478

476479
protected function callFormatWithMatches($matches)

test/Faker/Core/NumberTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ public function testRandomNumberThrowsExceptionWhenCalledWithATooHighNumberOfDig
4040
$this->faker->randomNumber(10);
4141
}
4242

43+
public function testRandomNumberHasValidNullableAutogenerate()
44+
{
45+
self::assertGreaterThan(0, $this->faker->randomNumber());
46+
}
47+
4348
public function testRandomNumberReturnsInteger()
4449
{
4550
self::assertIsInt($this->faker->randomNumber());

0 commit comments

Comments
 (0)