Skip to content

Commit aadf70a

Browse files
authored
Merge pull request #27430 from jasonvarga/5.7
[5.7] Fix for EventFake not returning responses
2 parents 9bbf644 + a7f7ee6 commit aadf70a

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

src/Illuminate/Support/Testing/Fakes/EventFake.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ public function dispatch($event, $payload = [], $halt = false)
211211
if ($this->shouldFakeEvent($name, $payload)) {
212212
$this->events[$name][] = func_get_args();
213213
} else {
214-
$this->dispatcher->dispatch($event, $payload, $halt);
214+
return $this->dispatcher->dispatch($event, $payload, $halt);
215215
}
216216
}
217217

tests/Integration/Events/EventFakeTest.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,60 @@ public function testNonFakedEventGetsProperlyDispatched()
7373

7474
Event::assertNotDispatched(NonImportantEvent::class);
7575
}
76+
77+
public function testNonFakedEventGetsProperlyDispatchedAndReturnsResponses()
78+
{
79+
Event::fake(NonImportantEvent::class);
80+
Event::listen('test', function () {
81+
// one
82+
});
83+
Event::listen('test', function () {
84+
return 'two';
85+
});
86+
Event::listen('test', function () {
87+
//
88+
});
89+
90+
$this->assertEquals([null, 'two', null], Event::dispatch('test'));
91+
92+
Event::assertNotDispatched(NonImportantEvent::class);
93+
}
94+
95+
public function testNonFakedEventGetsProperlyDispatchedAndCancelsFutureListeners()
96+
{
97+
Event::fake(NonImportantEvent::class);
98+
Event::listen('test', function () {
99+
// one
100+
});
101+
Event::listen('test', function () {
102+
return false;
103+
});
104+
Event::listen('test', function () {
105+
$this->fail('should not be called');
106+
});
107+
108+
$this->assertEquals([null], Event::dispatch('test'));
109+
110+
Event::assertNotDispatched(NonImportantEvent::class);
111+
}
112+
113+
public function testNonFakedHaltedEventGetsProperlyDispatchedAndReturnsResponse()
114+
{
115+
Event::fake(NonImportantEvent::class);
116+
Event::listen('test', function () {
117+
// one
118+
});
119+
Event::listen('test', function () {
120+
return 'two';
121+
});
122+
Event::listen('test', function () {
123+
$this->fail('should not be called');
124+
});
125+
126+
$this->assertEquals('two', Event::until('test'));
127+
128+
Event::assertNotDispatched(NonImportantEvent::class);
129+
}
76130
}
77131

78132
class Post extends Model

0 commit comments

Comments
 (0)