mirror of
https://github.com/php-flasher/php-flasher.git
synced 2026-03-31 15:07:47 +01:00
fix: add validation to HopsStamp and DelayStamp
HopsStamp: - Validate hops amount must be >= 1 (positive integer) - Negative or zero hops don't make logical sense DelayStamp: - Validate delay must be >= 0 (non-negative integer) - Negative delays don't make logical sense Both now throw InvalidArgumentException for invalid values, making configuration errors fail fast with clear messages.
This commit is contained in:
@@ -26,4 +26,19 @@ final class DelayStampTest extends TestCase
|
||||
|
||||
$this->assertSame($this->testDelay, $delay);
|
||||
}
|
||||
|
||||
public function testZeroDelayIsValid(): void
|
||||
{
|
||||
$stamp = new DelayStamp(0);
|
||||
|
||||
$this->assertSame(0, $stamp->getDelay());
|
||||
}
|
||||
|
||||
public function testNegativeDelayThrowsException(): void
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('Delay must be a non-negative integer (>= 0).');
|
||||
|
||||
new DelayStamp(-100);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,4 +20,27 @@ final class HopsStampTest extends TestCase
|
||||
|
||||
$this->assertSame($initialAmount, $hopsStamp->getAmount());
|
||||
}
|
||||
|
||||
public function testZeroHopsThrowsException(): void
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('Hops amount must be a positive integer (>= 1).');
|
||||
|
||||
new HopsStamp(0);
|
||||
}
|
||||
|
||||
public function testNegativeHopsThrowsException(): void
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('Hops amount must be a positive integer (>= 1).');
|
||||
|
||||
new HopsStamp(-5);
|
||||
}
|
||||
|
||||
public function testMinimumValidHops(): void
|
||||
{
|
||||
$stamp = new HopsStamp(1);
|
||||
|
||||
$this->assertSame(1, $stamp->getAmount());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user