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

Apply fixes from StyleCI #463

Merged
merged 1 commit into from
Aug 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
198 changes: 99 additions & 99 deletions tests/Channels/ChannelReplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,142 +17,142 @@ public function setUp(): void
$this->runOnlyOnRedisReplication();
}

/** @test */
public function replication_clients_can_subscribe_to_channels()
{
$connection = $this->getWebSocketConnection();

$message = new Message(json_encode([
'event' => 'pusher:subscribe',
'data' => [
'channel' => 'basic-channel',
],
/** @test */
public function replication_clients_can_subscribe_to_channels()
{
$connection = $this->getWebSocketConnection();

$message = new Message(json_encode([
'event' => 'pusher:subscribe',
'data' => [
'channel' => 'basic-channel',
],
]));

$this->pusherServer->onOpen($connection);
$this->pusherServer->onOpen($connection);

$this->pusherServer->onMessage($connection, $message);
$this->pusherServer->onMessage($connection, $message);

$connection->assertSentEvent('pusher_internal:subscription_succeeded', [
'channel' => 'basic-channel',
]);
}
$connection->assertSentEvent('pusher_internal:subscription_succeeded', [
'channel' => 'basic-channel',
]);
}

/** @test */
public function replication_clients_can_unsubscribe_from_channels()
{
$connection = $this->getConnectedWebSocketConnection(['test-channel']);
/** @test */
public function replication_clients_can_unsubscribe_from_channels()
{
$connection = $this->getConnectedWebSocketConnection(['test-channel']);

$channel = $this->getChannel($connection, 'test-channel');
$channel = $this->getChannel($connection, 'test-channel');

$this->assertTrue($channel->hasConnections());
$this->assertTrue($channel->hasConnections());

$message = new Message(json_encode([
'event' => 'pusher:unsubscribe',
'data' => [
'channel' => 'test-channel',
],
$message = new Message(json_encode([
'event' => 'pusher:unsubscribe',
'data' => [
'channel' => 'test-channel',
],
]));

$this->pusherServer->onMessage($connection, $message);
$this->pusherServer->onMessage($connection, $message);

$this->assertFalse($channel->hasConnections());
}
$this->assertFalse($channel->hasConnections());
}

/** @test */
public function replication_a_client_cannot_broadcast_to_other_clients_by_default()
{
// One connection inside channel "test-channel".
$existingConnection = $this->getConnectedWebSocketConnection(['test-channel']);
/** @test */
public function replication_a_client_cannot_broadcast_to_other_clients_by_default()
{
// One connection inside channel "test-channel".
$existingConnection = $this->getConnectedWebSocketConnection(['test-channel']);

$connection = $this->getConnectedWebSocketConnection(['test-channel']);
$connection = $this->getConnectedWebSocketConnection(['test-channel']);

$message = new Message('{"event": "client-test", "data": {}, "channel": "test-channel"}');
$message = new Message('{"event": "client-test", "data": {}, "channel": "test-channel"}');

$this->pusherServer->onMessage($connection, $message);
$this->pusherServer->onMessage($connection, $message);

$existingConnection->assertNotSentEvent('client-test');
}
$existingConnection->assertNotSentEvent('client-test');
}

/** @test */
public function replication_a_client_can_be_enabled_to_broadcast_to_other_clients()
{
config()->set('websockets.apps.0.enable_client_messages', true);
/** @test */
public function replication_a_client_can_be_enabled_to_broadcast_to_other_clients()
{
config()->set('websockets.apps.0.enable_client_messages', true);

// One connection inside channel "test-channel".
$existingConnection = $this->getConnectedWebSocketConnection(['test-channel']);
// One connection inside channel "test-channel".
$existingConnection = $this->getConnectedWebSocketConnection(['test-channel']);

$connection = $this->getConnectedWebSocketConnection(['test-channel']);
$connection = $this->getConnectedWebSocketConnection(['test-channel']);

$message = new Message('{"event": "client-test", "data": {}, "channel": "test-channel"}');
$message = new Message('{"event": "client-test", "data": {}, "channel": "test-channel"}');

$this->pusherServer->onMessage($connection, $message);
$this->pusherServer->onMessage($connection, $message);

$existingConnection->assertSentEvent('client-test');
}
$existingConnection->assertSentEvent('client-test');
}

/** @test */
public function replication_closed_connections_get_removed_from_all_connected_channels()
{
$connection = $this->getConnectedWebSocketConnection(['test-channel-1', 'test-channel-2']);
/** @test */
public function replication_closed_connections_get_removed_from_all_connected_channels()
{
$connection = $this->getConnectedWebSocketConnection(['test-channel-1', 'test-channel-2']);

$channel1 = $this->getChannel($connection, 'test-channel-1');
$channel2 = $this->getChannel($connection, 'test-channel-2');
$channel1 = $this->getChannel($connection, 'test-channel-1');
$channel2 = $this->getChannel($connection, 'test-channel-2');

$this->assertTrue($channel1->hasConnections());
$this->assertTrue($channel2->hasConnections());
$this->assertTrue($channel1->hasConnections());
$this->assertTrue($channel2->hasConnections());

$this->pusherServer->onClose($connection);
$this->pusherServer->onClose($connection);

$this->assertFalse($channel1->hasConnections());
$this->assertFalse($channel2->hasConnections());
}
$this->assertFalse($channel1->hasConnections());
$this->assertFalse($channel2->hasConnections());
}

/** @test */
public function replication_channels_can_broadcast_messages_to_all_connections()
{
$connection1 = $this->getConnectedWebSocketConnection(['test-channel']);
$connection2 = $this->getConnectedWebSocketConnection(['test-channel']);
/** @test */
public function replication_channels_can_broadcast_messages_to_all_connections()
{
$connection1 = $this->getConnectedWebSocketConnection(['test-channel']);
$connection2 = $this->getConnectedWebSocketConnection(['test-channel']);

$channel = $this->getChannel($connection1, 'test-channel');
$channel = $this->getChannel($connection1, 'test-channel');

$channel->broadcast([
'event' => 'broadcasted-event',
'channel' => 'test-channel',
]);
$channel->broadcast([
'event' => 'broadcasted-event',
'channel' => 'test-channel',
]);

$connection1->assertSentEvent('broadcasted-event');
$connection2->assertSentEvent('broadcasted-event');
}
$connection1->assertSentEvent('broadcasted-event');
$connection2->assertSentEvent('broadcasted-event');
}

/** @test */
public function replication_channels_can_broadcast_messages_to_all_connections_except_the_given_connection()
{
$connection1 = $this->getConnectedWebSocketConnection(['test-channel']);
$connection2 = $this->getConnectedWebSocketConnection(['test-channel']);
/** @test */
public function replication_channels_can_broadcast_messages_to_all_connections_except_the_given_connection()
{
$connection1 = $this->getConnectedWebSocketConnection(['test-channel']);
$connection2 = $this->getConnectedWebSocketConnection(['test-channel']);

$channel = $this->getChannel($connection1, 'test-channel');
$channel = $this->getChannel($connection1, 'test-channel');

$channel->broadcastToOthers($connection1, (object) [
'event' => 'broadcasted-event',
'channel' => 'test-channel',
]);
$channel->broadcastToOthers($connection1, (object) [
'event' => 'broadcasted-event',
'channel' => 'test-channel',
]);

$connection1->assertNotSentEvent('broadcasted-event');
$connection2->assertSentEvent('broadcasted-event');
}
$connection1->assertNotSentEvent('broadcasted-event');
$connection2->assertSentEvent('broadcasted-event');
}

/** @test */
public function replication_it_responds_correctly_to_the_ping_message()
{
$connection = $this->getConnectedWebSocketConnection();
/** @test */
public function replication_it_responds_correctly_to_the_ping_message()
{
$connection = $this->getConnectedWebSocketConnection();

$message = new Message(json_encode([
'event' => 'pusher:ping',
]));
$message = new Message(json_encode([
'event' => 'pusher:ping',
]));

$this->pusherServer->onMessage($connection, $message);
$this->pusherServer->onMessage($connection, $message);

$connection->assertSentEvent('pusher:pong');
}
$connection->assertSentEvent('pusher:pong');
}
}
1 change: 0 additions & 1 deletion tests/Channels/PrivateChannelReplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use BeyondCode\LaravelWebSockets\Tests\TestCase;
use BeyondCode\LaravelWebSockets\WebSockets\Exceptions\InvalidSignature;


class PrivateChannelReplicationTest extends TestCase
{
/**
Expand Down
2 changes: 0 additions & 2 deletions tests/HttpApi/FetchChannelsReplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use GuzzleHttp\Psr7\Request;
use Illuminate\Http\JsonResponse;
use Pusher\Pusher;
use Symfony\Component\HttpKernel\Exception\HttpException;

class FetchChannelsReplicationTest extends TestCase
{
Expand Down Expand Up @@ -55,7 +54,6 @@ public function replication_it_returns_the_channel_information()
->assertCalled('multi')
->assertCalledWithArgs('hlen', ['1234:presence-channel'])
->assertCalled('exec');

}

/** @test */
Expand Down