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:
Younes ENNAJI
2026-03-01 20:07:54 +00:00
parent ad5c0f56dd
commit 6d314dbc07
4 changed files with 50 additions and 0 deletions
+15
View File
@@ -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);
}
}
+23
View File
@@ -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());
}
}