@@ -62,6 +62,92 @@ public function testShouldBroadcastFail()
62
62
63
63
$ this ->assertFalse ($ d ->shouldBroadcast ([$ event ]));
64
64
}
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
+ }
65
151
}
66
152
67
153
class BroadcastEvent implements ShouldBroadcast
0 commit comments