You've already forked php-flasher
mirror of
https://github.com/php-flasher/php-flasher.git
synced 2026-04-05 12:32:55 +01:00
fix: validate limit criteria must be positive integer
Previously, negative limits caused array_slice() to return unexpected results (all except last N elements) and zero returned an empty array without clear intent. Now throws InvalidArgumentException for values < 1, making invalid configurations fail fast with a clear error message.
This commit is contained in:
@@ -59,18 +59,12 @@ final class LimitCriteriaTest extends TestCase
|
||||
$this->assertCount(2, $result);
|
||||
}
|
||||
|
||||
public function testLimitZeroReturnsEmptyArray(): void
|
||||
public function testLimitZeroThrowsException(): void
|
||||
{
|
||||
$envelopes = [
|
||||
new Envelope(new Notification()),
|
||||
new Envelope(new Notification()),
|
||||
];
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage("Criteria 'limit' must be a positive integer (>= 1).");
|
||||
|
||||
$criteria = new LimitCriteria(0);
|
||||
|
||||
$result = $criteria->apply($envelopes);
|
||||
|
||||
$this->assertCount(0, $result);
|
||||
new LimitCriteria(0);
|
||||
}
|
||||
|
||||
public function testEmptyArrayReturnsEmpty(): void
|
||||
@@ -121,17 +115,11 @@ final class LimitCriteriaTest extends TestCase
|
||||
$this->assertCount(1, $result);
|
||||
}
|
||||
|
||||
public function testNegativeLimitReturnsEmptyArray(): void
|
||||
public function testNegativeLimitThrowsException(): void
|
||||
{
|
||||
$envelopes = [
|
||||
new Envelope(new Notification()),
|
||||
new Envelope(new Notification()),
|
||||
];
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage("Criteria 'limit' must be a positive integer (>= 1).");
|
||||
|
||||
$criteria = new LimitCriteria(-5);
|
||||
|
||||
$result = $criteria->apply($envelopes);
|
||||
|
||||
$this->assertCount(0, $result);
|
||||
new LimitCriteria(-5);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user