wip
This commit is contained in:
parent
fb71f41e05
commit
1e5b8994df
|
|
@ -67,4 +67,28 @@ class ConnectionTest extends TestCase
|
|||
|
||||
$connection->assertSentEvent('pusher:pong');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function clients_can_subscribe_to_channels()
|
||||
{
|
||||
/** @var PusherServer $server */
|
||||
$server = app(PusherServer::class);
|
||||
|
||||
$connection = $this->getWebSocketConnection();
|
||||
|
||||
$message = new Message(json_encode([
|
||||
'event' => 'pusher:subscribe',
|
||||
'data' => [
|
||||
'channel' => 'basic-channel'
|
||||
],
|
||||
]));
|
||||
|
||||
$server->onOpen($connection);
|
||||
|
||||
$server->onMessage($connection, $message);
|
||||
|
||||
$connection->assertSentEvent('pusher_internal:subscription_succeeded', [
|
||||
'channel' => 'basic-channel'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -11,7 +11,7 @@ class Connection implements ConnectionInterface
|
|||
/** @var Request */
|
||||
public $httpRequest;
|
||||
|
||||
protected $sentData = [];
|
||||
public $sentData = [];
|
||||
|
||||
function send($data)
|
||||
{
|
||||
|
|
@ -23,10 +23,16 @@ class Connection implements ConnectionInterface
|
|||
// TODO: Implement close() method.
|
||||
}
|
||||
|
||||
public function assertSentEvent(string $name)
|
||||
public function assertSentEvent(string $name, array $additionalParameters = [])
|
||||
{
|
||||
$event = collect($this->sentData)->firstWhere('event', '=', $name);
|
||||
|
||||
PHPUnit::assertTrue(
|
||||
! is_null(collect($this->sentData)->firstWhere('event', '=', $name))
|
||||
! is_null($event)
|
||||
);
|
||||
|
||||
foreach ($additionalParameters as $parameter => $value) {
|
||||
PHPUnit::assertSame($event[$parameter], $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue