diff --git a/src/Illuminate/Support/Lottery.php b/src/Illuminate/Support/Lottery.php index 1f8c80588345..183cf957c578 100644 --- a/src/Illuminate/Support/Lottery.php +++ b/src/Illuminate/Support/Lottery.php @@ -45,7 +45,7 @@ class Lottery * Create a new Lottery instance. * * @param int|float $chances - * @param int|null $outOf + * @param int<1, max>|null $outOf */ public function __construct($chances, $outOf = null) { @@ -53,6 +53,10 @@ public function __construct($chances, $outOf = null) throw new RuntimeException('Float must not be greater than 1.'); } + if ($outOf !== null && $outOf < 1) { + throw new RuntimeException('Lottery "out of" value must be greater than or equal to 1.'); + } + $this->chances = $chances; $this->outOf = $outOf; diff --git a/tests/Support/LotteryTest.php b/tests/Support/LotteryTest.php index 7dc3a31d856f..e81bb8fe136f 100644 --- a/tests/Support/LotteryTest.php +++ b/tests/Support/LotteryTest.php @@ -154,6 +154,13 @@ public function testItThrowsForFloatsOverOne() new Lottery(1.1); } + public function testItThrowsForOutOfLessThanOne() + { + $this->expectException(RuntimeException::class); + + new Lottery(1, 0); + } + public function testItCanWinWithFloat() { $wins = false;