laravel-webrtc/tests/RoomManagerTest.php

53 lines
1.5 KiB
PHP
Raw Normal View History

<?php
declare(strict_types=1);
namespace Blax\WebRtc\Tests;
use Blax\WebRtc\Rooms\RoomManager;
use PHPUnit\Framework\TestCase;
final class RoomManagerTest extends TestCase
{
public function test_first_joiner_meshes_with_nobody(): void
{
$rooms = new RoomManager;
$this->assertSame([], $rooms->join('lobby', 'p1'));
$this->assertSame(['p1'], $rooms->peersIn('lobby'));
$this->assertSame('lobby', $rooms->roomOf('p1'));
}
public function test_second_joiner_meshes_with_the_first(): void
{
$rooms = new RoomManager;
$rooms->join('lobby', 'p1');
$this->assertSame(['p1'], $rooms->join('lobby', 'p2'));
$this->assertSame(['p1', 'p2'], $rooms->peersIn('lobby'));
}
public function test_leaving_returns_remaining_and_drops_empty_rooms(): void
{
$rooms = new RoomManager;
$rooms->join('lobby', 'p1');
$rooms->join('lobby', 'p2');
$this->assertSame(['p1'], $rooms->leave('p2'));
$this->assertSame([], $rooms->leave('p1')); // room now empty
$this->assertSame(0, $rooms->count());
$this->assertNull($rooms->room('lobby'));
}
public function test_joining_a_new_room_leaves_the_old(): void
{
$rooms = new RoomManager;
$rooms->join('a', 'p1');
$rooms->join('b', 'p1');
$this->assertSame([], $rooms->peersIn('a')); // 'a' emptied + dropped
$this->assertSame(['p1'], $rooms->peersIn('b'));
$this->assertSame('b', $rooms->roomOf('p1'));
}
}