Skip to content

Commit 98f9785

Browse files
enhance broadcast event test coverage (#55458)
1 parent 494fa56 commit 98f9785

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed

tests/Events/BroadcastedEventsTest.php

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,92 @@ public function testShouldBroadcastFail()
6262

6363
$this->assertFalse($d->shouldBroadcast([$event]));
6464
}
65+
66+
public function testBroadcastWithMultipleChannels()
67+
{
68+
$d = new Dispatcher($container = m::mock(Container::class));
69+
$broadcast = m::mock(BroadcastFactory::class);
70+
$broadcast->shouldReceive('queue')->once();
71+
$container->shouldReceive('make')->once()->with(BroadcastFactory::class)->andReturn($broadcast);
72+
73+
$event = new class implements ShouldBroadcast
74+
{
75+
public function broadcastOn()
76+
{
77+
return ['channel-1', 'channel-2'];
78+
}
79+
};
80+
81+
$d->dispatch($event);
82+
}
83+
84+
public function testBroadcastWithCustomConnectionName()
85+
{
86+
$d = new Dispatcher($container = m::mock(Container::class));
87+
$broadcast = m::mock(BroadcastFactory::class);
88+
$broadcast->shouldReceive('queue')->once();
89+
$container->shouldReceive('make')->once()->with(BroadcastFactory::class)->andReturn($broadcast);
90+
91+
$event = new class implements ShouldBroadcast
92+
{
93+
public $connection = 'custom-connection';
94+
95+
public function broadcastOn()
96+
{
97+
return ['test-channel'];
98+
}
99+
};
100+
101+
$d->dispatch($event);
102+
}
103+
104+
public function testBroadcastWithCustomEventName()
105+
{
106+
$d = new Dispatcher($container = m::mock(Container::class));
107+
$broadcast = m::mock(BroadcastFactory::class);
108+
$broadcast->shouldReceive('queue')->once();
109+
$container->shouldReceive('make')->once()->with(BroadcastFactory::class)->andReturn($broadcast);
110+
111+
$event = new class implements ShouldBroadcast
112+
{
113+
public function broadcastOn()
114+
{
115+
return ['test-channel'];
116+
}
117+
118+
public function broadcastAs()
119+
{
120+
return 'custom-event-name';
121+
}
122+
};
123+
124+
$d->dispatch($event);
125+
}
126+
127+
public function testBroadcastWithCustomPayload()
128+
{
129+
$d = new Dispatcher($container = m::mock(Container::class));
130+
$broadcast = m::mock(BroadcastFactory::class);
131+
$broadcast->shouldReceive('queue')->once();
132+
$container->shouldReceive('make')->once()->with(BroadcastFactory::class)->andReturn($broadcast);
133+
134+
$event = new class implements ShouldBroadcast
135+
{
136+
public $customData = 'test-data';
137+
138+
public function broadcastOn()
139+
{
140+
return ['test-channel'];
141+
}
142+
143+
public function broadcastWith()
144+
{
145+
return ['custom' => $this->customData];
146+
}
147+
};
148+
149+
$d->dispatch($event);
150+
}
65151
}
66152

67153
class BroadcastEvent implements ShouldBroadcast

0 commit comments

Comments
 (0)