Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Commit 344dfa7

Browse files
committed
Added --test for websockets:serve command
1 parent 815eabc commit 344dfa7

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

src/Console/StartWebSocketServer.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@
2323

2424
class StartWebSocketServer extends Command
2525
{
26-
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 } ';
26+
protected $signature = 'websockets:serve
27+
{--host=0.0.0.0}
28+
{--port=6001}
29+
{--debug : Forces the loggers to be enabled and thereby overriding the APP_DEBUG setting.}
30+
{--test : Prepare the server, but do not start it.}
31+
';
2732

2833
protected $description = 'Start the Laravel WebSocket Server';
2934

@@ -142,15 +147,18 @@ protected function startWebSocketServer()
142147

143148
$routes = WebSocketsRouter::getRoutes();
144149

145-
/* 🛰 Start the server 🛰 */
146-
(new WebSocketServerFactory())
150+
$server = (new WebSocketServerFactory())
147151
->setLoop($this->loop)
148152
->useRoutes($routes)
149153
->setHost($this->option('host'))
150154
->setPort($this->option('port'))
151155
->setConsoleOutput($this->output)
152-
->createServer()
153-
->run();
156+
->createServer();
157+
158+
if (! $this->option('test')) {
159+
/* 🛰 Start the server 🛰 */
160+
$server->run();
161+
}
154162
}
155163

156164
protected function configurePubSubReplication()
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace BeyondCode\LaravelWebSockets\Tests\Commands;
4+
5+
use Artisan;
6+
use BeyondCode\LaravelWebSockets\Statistics\Models\WebSocketsStatisticsEntry;
7+
use BeyondCode\LaravelWebSockets\Tests\TestCase;
8+
use Carbon\Carbon;
9+
use Illuminate\Support\Collection;
10+
11+
class StartWebSocketServerTest extends TestCase
12+
{
13+
/** @test */
14+
public function does_not_fail_if_building_up()
15+
{
16+
$this->artisan('websockets:serve', ['--test' => true]);
17+
18+
$this->assertTrue(true);
19+
}
20+
}

0 commit comments

Comments
 (0)