-
-
Notifications
You must be signed in to change notification settings - Fork 193
/
Copy pathDispatchEventFromAppControllerTest.php
48 lines (37 loc) · 1.14 KB
/
DispatchEventFromAppControllerTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
use Illuminate\Support\Facades\Event;
class TestEvent
{
public function __construct(public string $test = '') {}
}
it('dispatches an event', function () {
Event::fake();
$this->withoutMiddleware()
->post('_native/api/events', [
'event' => TestEvent::class,
])
->assertOk();
Event::assertDispatched(TestEvent::class);
});
// Since 45b7ccfcb86ebf35be35c1eb7fbb9f05a224448f nonexistent classes are handled as string events
it('dispatches a string event', function () {
Event::fake();
$this->withoutMiddleware()
->post('_native/api/events', [
'event' => 'some-event-that-is-no-class',
]);
Event::assertDispatched('some-event-that-is-no-class');
});
it('passes the payload to the event', function () {
Event::fake();
$this->withoutMiddleware()
->post('_native/api/events', [
'event' => TestEvent::class,
'payload' => [
'test' => 'Some payload string',
],
]);
Event::assertDispatched(TestEvent::class, function ($event) {
return $event->test === 'Some payload string';
});
});