laravel-webrtc/tests/RoomStoreTest.php

47 lines
1.6 KiB
PHP
Raw Permalink Normal View History

<?php
declare(strict_types=1);
namespace Blax\WebRtc\Tests;
use Blax\WebRtc\Rooms\RoomManager;
use Blax\WebRtc\Rooms\Stores\ArrayRoomStore;
use PHPUnit\Framework\TestCase;
final class RoomStoreTest extends TestCase
{
public function test_array_store_tracks_membership_presence_and_reverse_index(): void
{
$store = new ArrayRoomStore;
$store->add('presence-lobby', 'p1', ['name' => 'Ada']);
$store->add('presence-lobby', 'p2', []);
$this->assertSame(['p1', 'p2'], $store->members('presence-lobby'));
$this->assertSame(['name' => 'Ada'], $store->info('presence-lobby', 'p1'));
$this->assertSame('presence-lobby', $store->roomOf('p1'));
$this->assertSame(['presence-lobby'], $store->roomIds());
$store->remove('presence-lobby', 'p1');
$this->assertSame(['p2'], $store->members('presence-lobby'));
$this->assertNull($store->roomOf('p1'));
$store->remove('presence-lobby', 'p2');
$this->assertSame([], $store->roomIds()); // room dropped when empty
}
public function test_room_manager_uses_the_injected_store_and_exposes_presence(): void
{
$store = new ArrayRoomStore;
$rooms = new RoomManager($store);
$rooms->join('presence-x', 'p1', ['role' => 'host']);
$this->assertSame(['p1'], $rooms->join('presence-x', 'p2', ['role' => 'guest']));
$room = $rooms->room('presence-x');
$this->assertNotNull($room);
$this->assertSame(['p1', 'p2'], $room->peers());
$this->assertSame(['role' => 'host'], $room->info('p1'));
$this->assertSame($store, $rooms->store());
}
}