Added --test for websockets:serve command

This commit is contained in:
Alex Renoki 2020-08-13 14:21:06 +03:00
parent 815eabc801
commit 344dfa7f96
2 changed files with 33 additions and 5 deletions

View File

@ -23,7 +23,12 @@ use React\Socket\Connector;
class StartWebSocketServer extends Command
{
protected $signature = 'websockets:serve {--host=0.0.0.0} {--port=6001} {--debug : Forces the loggers to be enabled and thereby overriding the app.debug config setting } ';
protected $signature = 'websockets:serve
{--host=0.0.0.0}
{--port=6001}
{--debug : Forces the loggers to be enabled and thereby overriding the APP_DEBUG setting.}
{--test : Prepare the server, but do not start it.}
';
protected $description = 'Start the Laravel WebSocket Server';
@ -142,15 +147,18 @@ class StartWebSocketServer extends Command
$routes = WebSocketsRouter::getRoutes();
/* 🛰 Start the server 🛰 */
(new WebSocketServerFactory())
$server = (new WebSocketServerFactory())
->setLoop($this->loop)
->useRoutes($routes)
->setHost($this->option('host'))
->setPort($this->option('port'))
->setConsoleOutput($this->output)
->createServer()
->run();
->createServer();
if (! $this->option('test')) {
/* 🛰 Start the server 🛰 */
$server->run();
}
}
protected function configurePubSubReplication()

View File

@ -0,0 +1,20 @@
<?php
namespace BeyondCode\LaravelWebSockets\Tests\Commands;
use Artisan;
use BeyondCode\LaravelWebSockets\Statistics\Models\WebSocketsStatisticsEntry;
use BeyondCode\LaravelWebSockets\Tests\TestCase;
use Carbon\Carbon;
use Illuminate\Support\Collection;
class StartWebSocketServerTest extends TestCase
{
/** @test */
public function does_not_fail_if_building_up()
{
$this->artisan('websockets:serve', ['--test' => true]);
$this->assertTrue(true);
}
}