|
|
|
@ -122,7 +122,9 @@ class EventSystemTest extends TestCase
|
|
|
|
Flight::map('onEvent', function ($event, $callback) use (&$called) {
|
|
|
|
Flight::map('onEvent', function ($event, $callback) use (&$called) {
|
|
|
|
$called = true;
|
|
|
|
$called = true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
Flight::onEvent('test.event', function () {});
|
|
|
|
Flight::onEvent('test.event', function () {
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
});
|
|
|
|
$this->assertTrue($called, 'Overridden onEvent method should be called.');
|
|
|
|
$this->assertTrue($called, 'Overridden onEvent method should be called.');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -232,7 +234,9 @@ class EventSystemTest extends TestCase
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$this->assertFalse(Flight::eventDispatcher()->hasListeners('test.event'), 'Event should not have listeners before registration');
|
|
|
|
$this->assertFalse(Flight::eventDispatcher()->hasListeners('test.event'), 'Event should not have listeners before registration');
|
|
|
|
|
|
|
|
|
|
|
|
Flight::onEvent('test.event', function () {});
|
|
|
|
Flight::onEvent('test.event', function () {
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
$this->assertTrue(Flight::eventDispatcher()->hasListeners('test.event'), 'Event should have listeners after registration');
|
|
|
|
$this->assertTrue(Flight::eventDispatcher()->hasListeners('test.event'), 'Event should have listeners after registration');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -242,8 +246,12 @@ class EventSystemTest extends TestCase
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function testGetListeners(): void
|
|
|
|
public function testGetListeners(): void
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$callback1 = function () {};
|
|
|
|
$callback1 = function () {
|
|
|
|
$callback2 = function () {};
|
|
|
|
//
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
$callback2 = function () {
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
$this->assertEmpty(Flight::eventDispatcher()->getListeners('test.event'), 'Event should have no listeners before registration');
|
|
|
|
$this->assertEmpty(Flight::eventDispatcher()->getListeners('test.event'), 'Event should have no listeners before registration');
|
|
|
|
|
|
|
|
|
|
|
|
@ -273,8 +281,12 @@ class EventSystemTest extends TestCase
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$this->assertEmpty(Flight::eventDispatcher()->getAllRegisteredEvents(), 'No events should be registered initially');
|
|
|
|
$this->assertEmpty(Flight::eventDispatcher()->getAllRegisteredEvents(), 'No events should be registered initially');
|
|
|
|
|
|
|
|
|
|
|
|
Flight::onEvent('test.event1', function () {});
|
|
|
|
Flight::onEvent('test.event1', function () {
|
|
|
|
Flight::onEvent('test.event2', function () {});
|
|
|
|
//
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
Flight::onEvent('test.event2', function () {
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
$events = Flight::eventDispatcher()->getAllRegisteredEvents();
|
|
|
|
$events = Flight::eventDispatcher()->getAllRegisteredEvents();
|
|
|
|
$this->assertCount(2, $events, 'Should return all registered event names');
|
|
|
|
$this->assertCount(2, $events, 'Should return all registered event names');
|
|
|
|
@ -311,9 +323,15 @@ class EventSystemTest extends TestCase
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function testRemoveAllListeners(): void
|
|
|
|
public function testRemoveAllListeners(): void
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Flight::onEvent('test.event', function () {});
|
|
|
|
Flight::onEvent('test.event', function () {
|
|
|
|
Flight::onEvent('test.event', function () {});
|
|
|
|
//
|
|
|
|
Flight::onEvent('another.event', function () {});
|
|
|
|
});
|
|
|
|
|
|
|
|
Flight::onEvent('test.event', function () {
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
Flight::onEvent('another.event', function () {
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
$this->assertTrue(Flight::eventDispatcher()->hasListeners('test.event'), 'Event should have listeners before removal');
|
|
|
|
$this->assertTrue(Flight::eventDispatcher()->hasListeners('test.event'), 'Event should have listeners before removal');
|
|
|
|
$this->assertTrue(Flight::eventDispatcher()->hasListeners('another.event'), 'Another event should have listeners');
|
|
|
|
$this->assertTrue(Flight::eventDispatcher()->hasListeners('another.event'), 'Another event should have listeners');
|
|
|
|
@ -330,7 +348,9 @@ class EventSystemTest extends TestCase
|
|
|
|
public function testRemoveListenersForNonexistentEvent(): void
|
|
|
|
public function testRemoveListenersForNonexistentEvent(): void
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Should not throw any errors
|
|
|
|
// Should not throw any errors
|
|
|
|
Flight::eventDispatcher()->removeListener('nonexistent.event', function () {});
|
|
|
|
Flight::eventDispatcher()->removeListener('nonexistent.event', function () {
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
});
|
|
|
|
Flight::eventDispatcher()->removeAllListeners('nonexistent.event');
|
|
|
|
Flight::eventDispatcher()->removeAllListeners('nonexistent.event');
|
|
|
|
|
|
|
|
|
|
|
|
$this->assertTrue(true, 'Removing listeners for nonexistent events should not throw errors');
|
|
|
|
$this->assertTrue(true, 'Removing listeners for nonexistent events should not throw errors');
|
|
|
|
|