From 2e68ccb0d0a71745d9340d6fa57b57b730cb8db1 Mon Sep 17 00:00:00 2001 From: n0nag0n Date: Tue, 4 Mar 2025 07:19:13 -0700 Subject: [PATCH] and added new unit tests --- tests/EventSystemTest.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/EventSystemTest.php b/tests/EventSystemTest.php index 74ce27a..26d51e6 100644 --- a/tests/EventSystemTest.php +++ b/tests/EventSystemTest.php @@ -194,4 +194,34 @@ class EventSystemTest extends TestCase // Assuming the event system validates callables Flight::onEvent('test.event', 'not_a_callable'); } + + /** + * Test that event propagation stops if a listener returns false. + */ + public function testStopPropagation() + { + $firstCalled = false; + $secondCalled = false; + $thirdCalled = false; + + Flight::onEvent('test.event', function () use (&$firstCalled) { + $firstCalled = true; + return true; // Continue propagation + }); + + Flight::onEvent('test.event', function () use (&$secondCalled) { + $secondCalled = true; + return false; // Stop propagation + }); + + Flight::onEvent('test.event', function () use (&$thirdCalled) { + $thirdCalled = true; + }); + + Flight::triggerEvent('test.event'); + + $this->assertTrue($firstCalled, 'First listener should be called'); + $this->assertTrue($secondCalled, 'Second listener should be called'); + $this->assertFalse($thirdCalled, 'Third listener should not be called after propagation stopped'); + } }