diff --git a/src/Illuminate/Support/Testing/Fakes/EventFake.php b/src/Illuminate/Support/Testing/Fakes/EventFake.php index 57e47c89f378..1fc09db0fc96 100644 --- a/src/Illuminate/Support/Testing/Fakes/EventFake.php +++ b/src/Illuminate/Support/Testing/Fakes/EventFake.php @@ -211,7 +211,7 @@ public function dispatch($event, $payload = [], $halt = false) if ($this->shouldFakeEvent($name, $payload)) { $this->events[$name][] = func_get_args(); } else { - $this->dispatcher->dispatch($event, $payload, $halt); + return $this->dispatcher->dispatch($event, $payload, $halt); } } diff --git a/tests/Integration/Events/EventFakeTest.php b/tests/Integration/Events/EventFakeTest.php index cd1c09f6a917..ae6db1600c50 100644 --- a/tests/Integration/Events/EventFakeTest.php +++ b/tests/Integration/Events/EventFakeTest.php @@ -73,6 +73,60 @@ public function testNonFakedEventGetsProperlyDispatched() Event::assertNotDispatched(NonImportantEvent::class); } + + public function testNonFakedEventGetsProperlyDispatchedAndReturnsResponses() + { + Event::fake(NonImportantEvent::class); + Event::listen('test', function () { + // one + }); + Event::listen('test', function () { + return 'two'; + }); + Event::listen('test', function () { + // + }); + + $this->assertEquals([null, 'two', null], Event::dispatch('test')); + + Event::assertNotDispatched(NonImportantEvent::class); + } + + public function testNonFakedEventGetsProperlyDispatchedAndCancelsFutureListeners() + { + Event::fake(NonImportantEvent::class); + Event::listen('test', function () { + // one + }); + Event::listen('test', function () { + return false; + }); + Event::listen('test', function () { + $this->fail('should not be called'); + }); + + $this->assertEquals([null], Event::dispatch('test')); + + Event::assertNotDispatched(NonImportantEvent::class); + } + + public function testNonFakedHaltedEventGetsProperlyDispatchedAndReturnsResponse() + { + Event::fake(NonImportantEvent::class); + Event::listen('test', function () { + // one + }); + Event::listen('test', function () { + return 'two'; + }); + Event::listen('test', function () { + $this->fail('should not be called'); + }); + + $this->assertEquals('two', Event::until('test')); + + Event::assertNotDispatched(NonImportantEvent::class); + } } class Post extends Model