Merge branch 'master' of github.com:beyondcode/laravel-websockets

This commit is contained in:
Marcel Pociot 2018-12-03 13:57:58 +01:00
commit 361ef0284a
6 changed files with 45 additions and 5 deletions

View File

@ -45,7 +45,7 @@ return [
/* /*
* This model will be used to store the statistics of the WebSocketsServer * This model will be used to store the statistics of the WebSocketsServer
*/ */
'statistics_model' => \BeyondCode\LaravelWebSockets\Statistics\WebSocketsStatisticsEntry::class, 'statistics_model' => \BeyondCode\LaravelWebSockets\Statistics\Models\WebSocketsStatisticsEntry::class,
/* /*
* Define the optional SSL context for your WebSocket connections. * Define the optional SSL context for your WebSocket connections.

View File

@ -3,7 +3,7 @@
namespace BeyondCode\LaravelWebSockets\Statistics\Http\Controllers; namespace BeyondCode\LaravelWebSockets\Statistics\Http\Controllers;
use BeyondCode\LaravelWebSockets\Statistics\Rules\AppId; use BeyondCode\LaravelWebSockets\Statistics\Rules\AppId;
use BeyondCode\LaravelWebSockets\Statistics\WebSocketsStatisticsEntry; use BeyondCode\LaravelWebSockets\Statistics\Models\WebSocketsStatisticsEntry;
use Illuminate\Http\Request; use Illuminate\Http\Request;
class WebsocketStatisticsEntriesController class WebsocketStatisticsEntriesController

View File

@ -1,6 +1,6 @@
<?php <?php
namespace BeyondCode\LaravelWebSockets\Statistics; namespace BeyondCode\LaravelWebSockets\Statistics\Models;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;

View File

@ -64,14 +64,14 @@ class WebSocketsServiceProvider extends ServiceProvider
protected function registerRouteMacro() protected function registerRouteMacro()
{ {
Route::macro('webSockets', function($prefix = 'websockets') { Route::macro('webSockets', function($prefix = 'websockets') {
Route::prefix($prefix)->namespace('\\')->middleware(Authorize::class)->group(function() { Route::prefix($prefix)->middleware(Authorize::class)->group(function() {
Route::get('/', ShowDashboard::class); Route::get('/', ShowDashboard::class);
Route::post('auth', AuthenticateDashboard::class); Route::post('auth', AuthenticateDashboard::class);
Route::post('event', SendMessage::class); Route::post('event', SendMessage::class);
}); });
//TODO: add middleware //TODO: add middleware
Route::prefix($prefix)->namespace('\\')->group(function() { Route::prefix($prefix)->group(function() {
Route::post('statistics', [WebsocketStatisticsEntriesController::class, 'store']); Route::post('statistics', [WebsocketStatisticsEntriesController::class, 'store']);
}); });
}); });

View File

@ -0,0 +1,35 @@
<?php
namespace BeyondCode\LaravelWebSockets\Tests\Statistics\Controllers;
use BeyondCode\LaravelWebSockets\Statistics\Http\Controllers\WebsocketStatisticsEntriesController;
use BeyondCode\LaravelWebSockets\Statistics\Models\WebSocketsStatisticsEntry;
use BeyondCode\LaravelWebSockets\Tests\TestCase;
class WebSocketsStatisticsControllerTest extends TestCase
{
/** @test */
public function it_can_store_statistics()
{
$this->post(
action([WebsocketStatisticsEntriesController::class, 'store']),
$this->payload()
);
$entries = WebSocketsStatisticsEntry::get();
$this->assertCount(1, $entries);
$this->assertArraySubset($this->payload(), $entries->first()->attributesToArray());
}
protected function payload(): array
{
return [
'app_id' => config('websockets.apps.0.id'),
'peak_connections' => 1,
'websocket_message_count' => 2,
'api_message_count' => 3,
];
}
}

View File

@ -8,6 +8,7 @@ use BeyondCode\LaravelWebSockets\WebSockets\WebSocketHandler;
use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Request;
use BeyondCode\LaravelWebSockets\Tests\Mocks\Connection; use BeyondCode\LaravelWebSockets\Tests\Mocks\Connection;
use BeyondCode\LaravelWebSockets\WebSocketsServiceProvider; use BeyondCode\LaravelWebSockets\WebSocketsServiceProvider;
use Illuminate\Support\Facades\Route;
use Ratchet\ConnectionInterface; use Ratchet\ConnectionInterface;
abstract class TestCase extends \Orchestra\Testbench\TestCase abstract class TestCase extends \Orchestra\Testbench\TestCase
@ -25,6 +26,8 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
$this->pusherServer = app(WebSocketHandler::class); $this->pusherServer = app(WebSocketHandler::class);
$this->channelManager = app(ChannelManager::class); $this->channelManager = app(ChannelManager::class);
Route::webSockets();
} }
protected function getPackageProviders($app) protected function getPackageProviders($app)
@ -48,6 +51,8 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
include_once __DIR__.'/../database/migrations/create_websockets_statistics_entries_table.php.stub'; include_once __DIR__.'/../database/migrations/create_websockets_statistics_entries_table.php.stub';
(new \CreateWebSocketsStatisticsEntriesTable())->up(); (new \CreateWebSocketsStatisticsEntriesTable())->up();
} }
protected function getWebSocketConnection(string $url = '/?appKey=TestKey'): Connection protected function getWebSocketConnection(string $url = '/?appKey=TestKey'): Connection