This repository was archived by the owner on Feb 7, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace BeyondCode \LaravelWebSockets \Tests \PubSub ;
4+
5+ use BeyondCode \LaravelWebSockets \PubSub \Drivers \RedisClient ;
6+ use BeyondCode \LaravelWebSockets \Tests \TestCase ;
7+ use React \EventLoop \Factory as LoopFactory ;
8+ use BeyondCode \LaravelWebSockets \Tests \Mocks \RedisFactory ;
9+
10+ class RedisDriverTest extends TestCase
11+ {
12+ /**
13+ * {@inheritdoc}
14+ */
15+ public function setUp (): void
16+ {
17+ parent ::setUp ();
18+
19+ $ this ->runOnlyOnRedisReplication ();
20+ }
21+
22+ /** @test */
23+ public function redis_listener_responds_properly_on_payload ()
24+ {
25+ $ connection = $ this ->getConnectedWebSocketConnection (['test-channel ' ]);
26+
27+ $ this ->pusherServer ->onOpen ($ connection );
28+
29+ $ channelData = [
30+ 'user_id ' => 1 ,
31+ 'user_info ' => [
32+ 'name ' => 'Marcel ' ,
33+ ],
34+ ];
35+
36+ $ payload = json_encode ([
37+ 'appId ' => '1234 ' ,
38+ 'event ' => 'test ' ,
39+ 'data ' => $ channelData ,
40+ 'socket ' => $ connection ->socketId ,
41+ ]);
42+
43+ $ this ->getSubscribeClient ()->onMessage ('1234:test-channel ' , $ payload );
44+
45+ $ this ->getSubscribeClient ()
46+ ->assertEventDispatched ('message ' )
47+ ->assertCalledWithArgs ('subscribe ' , ['1234:test-channel ' ])
48+ ->assertCalledWithArgs ('onMessage ' , [
49+ '1234:test-channel ' , $ payload ,
50+ ]);
51+ }
52+ }
You can’t perform that action at this time.
0 commit comments