diff --git a/src/Console/StartWebSocketServer.php b/src/Console/StartWebSocketServer.php index 2223e8a..b44b3a0 100644 --- a/src/Console/StartWebSocketServer.php +++ b/src/Console/StartWebSocketServer.php @@ -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() diff --git a/tests/Commands/StartWebSocketServerTest.php b/tests/Commands/StartWebSocketServerTest.php new file mode 100644 index 0000000..3420c8f --- /dev/null +++ b/tests/Commands/StartWebSocketServerTest.php @@ -0,0 +1,20 @@ +artisan('websockets:serve', ['--test' => true]); + + $this->assertTrue(true); + } +}