2020-09-10 19:59:26 +00:00
|
|
|
<?php
|
|
|
|
|
|
2025-01-16 07:54:02 +00:00
|
|
|
namespace BlaxSoftware\LaravelWebSockets\Test;
|
2020-09-10 19:59:26 +00:00
|
|
|
|
|
|
|
|
class ReplicationTest extends TestCase
|
|
|
|
|
{
|
2020-09-15 17:46:19 +00:00
|
|
|
/**
|
|
|
|
|
* {@inheritdoc}
|
|
|
|
|
*/
|
|
|
|
|
public function setUp(): void
|
2020-09-10 19:59:26 +00:00
|
|
|
{
|
2020-09-15 17:46:19 +00:00
|
|
|
parent::setUp();
|
|
|
|
|
|
2020-09-10 19:59:26 +00:00
|
|
|
$this->runOnlyOnRedisReplication();
|
2020-09-15 17:46:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function test_publishing_client_gets_subscribed()
|
|
|
|
|
{
|
|
|
|
|
$this->newActiveConnection(['public-channel']);
|
2020-09-10 19:59:26 +00:00
|
|
|
|
2020-09-15 17:46:19 +00:00
|
|
|
$this->getSubscribeClient()
|
|
|
|
|
->assertCalledWithArgs('subscribe', [$this->channelManager->getRedisKey('1234')])
|
|
|
|
|
->assertCalledWithArgs('subscribe', [$this->channelManager->getRedisKey('1234', 'public-channel')]);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-18 09:53:36 +00:00
|
|
|
public function test_unsubscribe_from_topic_when_the_last_connection_leaves()
|
2020-09-15 17:46:19 +00:00
|
|
|
{
|
2020-09-10 19:59:26 +00:00
|
|
|
$connection = $this->newActiveConnection(['public-channel']);
|
2020-09-18 09:15:49 +00:00
|
|
|
|
2020-09-18 09:53:36 +00:00
|
|
|
$this->pusherServer->onClose($connection);
|
2020-09-18 09:15:49 +00:00
|
|
|
|
|
|
|
|
$this->getSubscribeClient()
|
2020-09-18 09:53:36 +00:00
|
|
|
->assertCalledWithArgs('unsubscribe', [$this->channelManager->getRedisKey('1234')])
|
|
|
|
|
->assertCalledWithArgs('unsubscribe', [$this->channelManager->getRedisKey('1234', 'public-channel')]);
|
2020-09-18 09:15:49 +00:00
|
|
|
}
|
2020-09-10 19:59:26 +00:00
|
|
|
}
|