laravel-websockets/tests/Statistics/Controllers/WebSocketsStatisticsControl...

42 lines
1.2 KiB
PHP

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