mirror of
https://github.com/php-flasher/php-flasher.git
synced 2026-03-31 15:07:47 +01:00
Update filter criteria and CHANGELOG
This commit is contained in:
@@ -248,4 +248,52 @@ final class DelayCriteriaTest extends TestCase
|
||||
|
||||
$this->assertCount(3, $result);
|
||||
}
|
||||
|
||||
public function testMatchWithOnlyMaxAndNullMin(): void
|
||||
{
|
||||
// This test verifies explicit null handling for min
|
||||
// Previously relied on PHP's implicit null-to-0 coercion
|
||||
$envelope = new Envelope(new Notification(), [new DelayStamp(3)]);
|
||||
|
||||
$criteria = new DelayCriteria(['max' => 5]);
|
||||
|
||||
// With min=null and max=5, delay=3 should match
|
||||
$this->assertTrue($criteria->match($envelope));
|
||||
}
|
||||
|
||||
public function testMatchWithOnlyMaxRejectsHigherDelay(): void
|
||||
{
|
||||
$envelope = new Envelope(new Notification(), [new DelayStamp(10)]);
|
||||
|
||||
$criteria = new DelayCriteria(['max' => 5]);
|
||||
|
||||
// With min=null and max=5, delay=10 should NOT match
|
||||
$this->assertFalse($criteria->match($envelope));
|
||||
}
|
||||
|
||||
public function testMatchWithBothNullMinAndMax(): void
|
||||
{
|
||||
// When both min and max are null, all envelopes with delay stamp should match
|
||||
$envelope = new Envelope(new Notification(), [new DelayStamp(100)]);
|
||||
|
||||
$criteria = new DelayCriteria([]);
|
||||
|
||||
$this->assertTrue($criteria->match($envelope));
|
||||
}
|
||||
|
||||
public function testApplyWithNullMinAndMaxMatchesAll(): void
|
||||
{
|
||||
$envelopes = [
|
||||
new Envelope(new Notification(), [new DelayStamp(0)]),
|
||||
new Envelope(new Notification(), [new DelayStamp(50)]),
|
||||
new Envelope(new Notification(), [new DelayStamp(100)]),
|
||||
];
|
||||
|
||||
$criteria = new DelayCriteria([]);
|
||||
|
||||
$result = $criteria->apply($envelopes);
|
||||
|
||||
// All envelopes with delay stamp should match when no constraints
|
||||
$this->assertCount(3, $result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,4 +166,32 @@ final class FilterCriteriaTest extends TestCase
|
||||
$this->assertSame(['first', 'second'], $order);
|
||||
$this->assertCount(2, $result);
|
||||
}
|
||||
|
||||
public function testConstructorWithEmptyArrayDoesNotThrow(): void
|
||||
{
|
||||
// This test verifies the fix for uninitialized $callbacks property
|
||||
// Previously, new FilterCriteria([]) would leave $callbacks uninitialized
|
||||
// causing "must not be accessed before initialization" error on apply()
|
||||
$criteria = new FilterCriteria([]);
|
||||
|
||||
$envelopes = [new Envelope(new Notification())];
|
||||
$result = $criteria->apply($envelopes);
|
||||
|
||||
// With no callbacks, envelopes should pass through unchanged
|
||||
$this->assertSame($envelopes, $result);
|
||||
}
|
||||
|
||||
public function testApplyWithEmptyCallbacksReturnsEnvelopesUnchanged(): void
|
||||
{
|
||||
$criteria = new FilterCriteria([]);
|
||||
|
||||
$notification = new Notification();
|
||||
$notification->setMessage('test');
|
||||
$envelopes = [new Envelope($notification)];
|
||||
|
||||
$result = $criteria->apply($envelopes);
|
||||
|
||||
$this->assertCount(1, $result);
|
||||
$this->assertSame('test', $result[0]->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -229,4 +229,52 @@ final class HopsCriteriaTest extends TestCase
|
||||
|
||||
$this->assertCount(1, $result);
|
||||
}
|
||||
|
||||
public function testMatchWithOnlyMaxAndNullMin(): void
|
||||
{
|
||||
// This test verifies explicit null handling for min
|
||||
// Previously relied on PHP's implicit null-to-0 coercion
|
||||
$envelope = new Envelope(new Notification(), [new HopsStamp(2)]);
|
||||
|
||||
$criteria = new HopsCriteria(['max' => 5]);
|
||||
|
||||
// With min=null and max=5, hops=2 should match
|
||||
$this->assertTrue($criteria->match($envelope));
|
||||
}
|
||||
|
||||
public function testMatchWithOnlyMaxRejectsHigherHops(): void
|
||||
{
|
||||
$envelope = new Envelope(new Notification(), [new HopsStamp(10)]);
|
||||
|
||||
$criteria = new HopsCriteria(['max' => 5]);
|
||||
|
||||
// With min=null and max=5, hops=10 should NOT match
|
||||
$this->assertFalse($criteria->match($envelope));
|
||||
}
|
||||
|
||||
public function testMatchWithBothNullMinAndMax(): void
|
||||
{
|
||||
// When both min and max are null, all envelopes with hops stamp should match
|
||||
$envelope = new Envelope(new Notification(), [new HopsStamp(100)]);
|
||||
|
||||
$criteria = new HopsCriteria([]);
|
||||
|
||||
$this->assertTrue($criteria->match($envelope));
|
||||
}
|
||||
|
||||
public function testApplyWithNullMinAndMaxMatchesAll(): void
|
||||
{
|
||||
$envelopes = [
|
||||
new Envelope(new Notification(), [new HopsStamp(1)]),
|
||||
new Envelope(new Notification(), [new HopsStamp(50)]),
|
||||
new Envelope(new Notification(), [new HopsStamp(100)]),
|
||||
];
|
||||
|
||||
$criteria = new HopsCriteria([]);
|
||||
|
||||
$result = $criteria->apply($envelopes);
|
||||
|
||||
// All envelopes with hops stamp should match when no constraints
|
||||
$this->assertCount(3, $result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -245,4 +245,52 @@ final class PriorityCriteriaTest extends TestCase
|
||||
|
||||
$this->assertCount(1, $result);
|
||||
}
|
||||
|
||||
public function testMatchWithOnlyMaxAndNullMin(): void
|
||||
{
|
||||
// This test verifies explicit null handling for min
|
||||
// Previously relied on PHP's implicit null-to-0 coercion
|
||||
$envelope = new Envelope(new Notification(), [new PriorityStamp(3)]);
|
||||
|
||||
$criteria = new PriorityCriteria(['max' => 5]);
|
||||
|
||||
// With min=null and max=5, priority 3 should match
|
||||
$this->assertTrue($criteria->match($envelope));
|
||||
}
|
||||
|
||||
public function testMatchWithOnlyMaxRejectsHigherPriority(): void
|
||||
{
|
||||
$envelope = new Envelope(new Notification(), [new PriorityStamp(10)]);
|
||||
|
||||
$criteria = new PriorityCriteria(['max' => 5]);
|
||||
|
||||
// With min=null and max=5, priority 10 should NOT match
|
||||
$this->assertFalse($criteria->match($envelope));
|
||||
}
|
||||
|
||||
public function testMatchWithBothNullMinAndMax(): void
|
||||
{
|
||||
// When both min and max are null, all envelopes with priority stamp should match
|
||||
$envelope = new Envelope(new Notification(), [new PriorityStamp(100)]);
|
||||
|
||||
$criteria = new PriorityCriteria([]);
|
||||
|
||||
$this->assertTrue($criteria->match($envelope));
|
||||
}
|
||||
|
||||
public function testApplyWithNullMinAndMaxMatchesAll(): void
|
||||
{
|
||||
$envelopes = [
|
||||
new Envelope(new Notification(), [new PriorityStamp(-100)]),
|
||||
new Envelope(new Notification(), [new PriorityStamp(0)]),
|
||||
new Envelope(new Notification(), [new PriorityStamp(100)]),
|
||||
];
|
||||
|
||||
$criteria = new PriorityCriteria([]);
|
||||
|
||||
$result = $criteria->apply($envelopes);
|
||||
|
||||
// All envelopes with priority stamp should match when no constraints
|
||||
$this->assertCount(3, $result);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user