Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Commit e34c7e8

Browse files
committed
Added a redis driver test
1 parent a36d336 commit e34c7e8

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

tests/PubSub/RedisDriverTest.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
}

0 commit comments

Comments
 (0)