laravel-websockets/tests/ConnectionTest.php

57 lines
1.6 KiB
PHP
Raw Normal View History

2018-11-25 22:43:43 +00:00
<?php
namespace BeyondCode\LaravelWebSockets\Tests;
2018-12-01 12:57:02 +00:00
use BeyondCode\LaravelWebSockets\Apps\App;
2018-11-27 15:35:28 +00:00
use BeyondCode\LaravelWebSockets\WebSockets\Exceptions\UnknownAppKey;
2018-11-25 23:14:50 +00:00
use BeyondCode\LaravelWebSockets\Tests\Mocks\Message;
2018-11-25 22:43:43 +00:00
class ConnectionTest extends TestCase
{
2018-11-26 22:58:28 +00:00
2018-11-25 22:43:43 +00:00
/** @test */
public function unknown_app_keys_can_not_connect()
{
2018-11-26 23:13:22 +00:00
$this->expectException(UnknownAppKey::class);
2018-11-25 22:43:43 +00:00
2018-11-26 22:58:28 +00:00
$this->pusherServer->onOpen($this->getWebSocketConnection('/?appKey=test'));
2018-11-25 22:43:43 +00:00
}
/** @test */
public function known_app_keys_can_connect()
{
2018-11-25 23:14:50 +00:00
$connection = $this->getWebSocketConnection();
2018-11-25 22:43:43 +00:00
2018-11-26 22:58:28 +00:00
$this->pusherServer->onOpen($connection);
2018-11-25 22:43:43 +00:00
$connection->assertSentEvent('pusher:connection_established');
}
/** @test */
public function successful_connections_have_the_client_attached()
{
2018-11-25 23:14:50 +00:00
$connection = $this->getWebSocketConnection();
2018-11-25 22:43:43 +00:00
2018-11-26 22:58:28 +00:00
$this->pusherServer->onOpen($connection);
2018-11-25 22:43:43 +00:00
2018-12-01 12:57:02 +00:00
$this->assertInstanceOf(App::class, $connection->client);
2018-11-25 22:43:43 +00:00
$this->assertSame(1234, $connection->client->appId);
$this->assertSame('TestKey', $connection->client->appKey);
$this->assertSame('TestSecret', $connection->client->appSecret);
$this->assertSame('Test Client', $connection->client->name);
}
2018-11-25 23:14:50 +00:00
/** @test */
public function ping_returns_pong()
{
$connection = $this->getWebSocketConnection();
$message = new Message('{"event": "pusher:ping"}');
2018-11-26 22:58:28 +00:00
$this->pusherServer->onOpen($connection);
2018-11-25 23:14:50 +00:00
2018-11-26 22:58:28 +00:00
$this->pusherServer->onMessage($connection, $message);
2018-11-25 23:14:50 +00:00
$connection->assertSentEvent('pusher:pong');
}
2018-11-25 22:43:43 +00:00
}