From 12b492bcf1c19d353af46eb044485bcb42bd620b Mon Sep 17 00:00:00 2001 From: imanghafoori Date: Thu, 13 Feb 2020 01:49:20 +0330 Subject: [PATCH 1/2] add test that a single flush fires all queued events with same name --- tests/Events/EventsDispatcherTest.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/Events/EventsDispatcherTest.php b/tests/Events/EventsDispatcherTest.php index 85e56a9c84e3..bfc04a428320 100755 --- a/tests/Events/EventsDispatcherTest.php +++ b/tests/Events/EventsDispatcherTest.php @@ -156,6 +156,20 @@ public function testQueuedEventsCanBeForgotten() $this->assertSame('unset', $_SERVER['__event.test']); } + public function testMultiplePushedEventsWillGetFlushed() + { + $_SERVER['__event.test'] = ''; + $d = new Dispatcher; + $d->push('update', ['name' => 'taylor ']); + $d->push('update', ['name' => 'otwell']); + $d->listen('update', function ($name) { + $_SERVER['__event.test'] .= $name; + }); + + $d->flush('update'); + $this->assertSame('taylor otwell', $_SERVER['__event.test']); + } + public function testWildcardListeners() { unset($_SERVER['__event.test']); From bf100581551f199c2b96355ec6774297a573924c Mon Sep 17 00:00:00 2001 From: imanghafoori Date: Thu, 13 Feb 2020 01:51:03 +0330 Subject: [PATCH 2/2] strengthen the test that listeners can be set before and after pushed event --- tests/Events/EventsDispatcherTest.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/Events/EventsDispatcherTest.php b/tests/Events/EventsDispatcherTest.php index bfc04a428320..36232a8d2a46 100755 --- a/tests/Events/EventsDispatcherTest.php +++ b/tests/Events/EventsDispatcherTest.php @@ -132,14 +132,20 @@ public function testQueuedEventsAreFired() { unset($_SERVER['__event.test']); $d = new Dispatcher; - $d->push('update', ['name' => 'taylor']); $d->listen('update', function ($name) { $_SERVER['__event.test'] = $name; }); + $d->push('update', ['name' => 'taylor']); + $d->listen('update', function ($name) { + $_SERVER['__event.test'] .= '_'.$name; + }); $this->assertFalse(isset($_SERVER['__event.test'])); $d->flush('update'); - $this->assertSame('taylor', $_SERVER['__event.test']); + $d->listen('update', function ($name) { + $_SERVER['__event.test'] .= $name; + }); + $this->assertSame('taylor_taylor', $_SERVER['__event.test']); } public function testQueuedEventsCanBeForgotten()