add ping test
This commit is contained in:
parent
647def8d43
commit
6103f7ea1b
|
|
@ -14,7 +14,7 @@ class ConfigClientProvider implements ClientProvider
|
|||
$this->clients = collect(config('websockets.clients'));
|
||||
}
|
||||
|
||||
/** @return array[BeyondCode\LaravelWebSockets\ClientProviders\Client] */
|
||||
/** @return array[\BeyondCode\LaravelWebSockets\ClientProviders\Client] */
|
||||
public function all(): array
|
||||
{
|
||||
return $this->clients
|
||||
|
|
|
|||
|
|
@ -93,4 +93,20 @@ class ChannelTest extends TestCase
|
|||
$connection1->assertNotSentEvent('broadcasted-event');
|
||||
$connection2->assertSentEvent('broadcasted-event');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_responds_correctly_to_the_ping_message()
|
||||
{
|
||||
$connection = $this->getWebSocketConnection();
|
||||
|
||||
$message = new Message(json_encode([
|
||||
'event' => 'pusher:ping',
|
||||
]));
|
||||
|
||||
$this->pusherServer->onOpen($connection);
|
||||
|
||||
$this->pusherServer->onMessage($connection, $message);
|
||||
|
||||
$connection->assertSentEvent('pusher:pong');
|
||||
}
|
||||
}
|
||||
|
|
@ -37,10 +37,12 @@ class PrivateChannelTest extends TestCase
|
|||
|
||||
$signature = "{$connection->socketId}:private-channel";
|
||||
|
||||
$hashedAppSecret = hash_hmac('sha256', $signature, $connection->client->appSecret);
|
||||
|
||||
$message = new Message(json_encode([
|
||||
'event' => 'pusher:subscribe',
|
||||
'data' => [
|
||||
'auth' => $connection->client->appKey.':'.hash_hmac('sha256', $signature, $connection->client->appSecret),
|
||||
'auth' => "{$connection->client->appKey}:{$hashedAppSecret}",
|
||||
'channel' => 'private-channel'
|
||||
],
|
||||
]));
|
||||
|
|
|
|||
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
namespace BeyondCode\LaravelWebSockets\Tests\ClientProviders;
|
||||
|
||||
use BeyondCode\LaravelWebSockets\ClientProviders\Client;
|
||||
use BeyondCode\LaravelWebSockets\Exceptions\InvalidClient;
|
||||
use BeyondCode\LaravelWebSockets\Tests\TestCase;
|
||||
|
||||
class ClientTest extends TestCase
|
||||
{
|
||||
/** @test */
|
||||
public function it_can_create_a_client()
|
||||
{
|
||||
new Client(1, 'appKey', 'appSecret', 'new');
|
||||
|
||||
$this->markTestAsPassed();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_will_not_accept_an_empty_appKey()
|
||||
{
|
||||
$this->expectException(InvalidClient::class);
|
||||
|
||||
new Client(1, '', 'appSecret', 'new');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_will_not_accept_an_empty_appSecret()
|
||||
{
|
||||
$this->expectException(InvalidClient::class);
|
||||
|
||||
new Client(1, 'appKey', '', 'new');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_will_not_accept_an_non_numeric_appId()
|
||||
{
|
||||
$this->expectException(InvalidClient::class);
|
||||
|
||||
new Client('appId', 'appKey', '', 'new');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
namespace BeyondCode\LaravelWebSockets\Tests\ClientProviders;
|
||||
|
||||
use BeyondCode\LaravelWebSockets\ClientProviders\ConfigClientProvider;
|
||||
use BeyondCode\LaravelWebSockets\Tests\TestCase;
|
||||
|
||||
class ConfigClientProviderTest extends TestCase
|
||||
{
|
||||
/** @var \BeyondCode\LaravelWebSockets\ClientProviders\ConfigClientProvider */
|
||||
protected $configClientProvider;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->configClientProvider = new ConfigClientProvider();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_can_get_client_from_the_config_file()
|
||||
{
|
||||
$clients = $this->configClientProvider->all();
|
||||
|
||||
$this->assertCount(1, $clients);
|
||||
|
||||
/** @var $client */
|
||||
$client = $clients[0];
|
||||
|
||||
$this->assertEquals('Test Client', $client->name);
|
||||
$this->assertEquals(1234, $client->appId);
|
||||
$this->assertEquals('TestKey', $client->appKey);
|
||||
$this->assertEquals('TestSecret', $client->appSecret);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -15,12 +15,12 @@ class Connection implements ConnectionInterface
|
|||
|
||||
public $closed = false;
|
||||
|
||||
function send($data)
|
||||
public function send($data)
|
||||
{
|
||||
$this->sentData[] = json_decode($data, true);
|
||||
}
|
||||
|
||||
function close()
|
||||
public function close()
|
||||
{
|
||||
$this->closed = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
|
|||
/** @var \BeyondCode\LaravelWebSockets\WebSockets\WebSocketHandler */
|
||||
protected $pusherServer;
|
||||
|
||||
/** @var ChannelManager */
|
||||
/** @var \BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager */
|
||||
protected $channelManager;
|
||||
|
||||
public function setUp()
|
||||
|
|
@ -24,6 +24,7 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
|
|||
parent::setUp();
|
||||
|
||||
$this->pusherServer = app(WebSocketHandler::class);
|
||||
|
||||
$this->channelManager = app(ChannelManager::class);
|
||||
}
|
||||
|
||||
|
|
@ -79,4 +80,9 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
|
|||
{
|
||||
return $this->channelManager->findOrCreate($connection->client->appId, $channelId);
|
||||
}
|
||||
|
||||
protected function markTestAsPassed()
|
||||
{
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue