sls/tests/Unit/IceCandidateDtoTest.php
kushal.saha 3aca6d90f3 feat(webrtc): implement IceCandidateProviderInterface with Metered and ConvexSol drivers
- Add Metered and ConvexSol (CoTURN) provider drivers with response validation and caching
- Add IceCandidateManager with automatic failover and structured logging
- Add IceCandidateProviderInterface and DTOs conforming to RTCIceServer format
2026-08-26 12:44:41 +00:00

71 lines
2.5 KiB
PHP

<?php
namespace Tests\Unit;
use App\DTOs\IceCandidateDto;
use App\DTOs\IceCandidatesDto;
use PHPUnit\Framework\TestCase;
class IceCandidateDtoTest extends TestCase
{
public function test_ice_candidate_dto_instantiation_and_serialization(): void
{
$dto = new IceCandidateDto(
urls: 'stun:stun.l.google.com:19302',
username: null,
credential: null
);
$array = $dto->toArray();
$this->assertEquals(['urls' => 'stun:stun.l.google.com:19302'], $array);
$this->assertArrayNotHasKey('username', $array);
$this->assertArrayNotHasKey('credential', $array);
$this->assertEquals($array, $dto->jsonSerialize());
}
public function test_ice_candidate_dto_with_turn_credentials(): void
{
$dto = IceCandidateDto::fromArray([
'urls' => ['turn:turn.convexsol.com:3478', 'turns:turn.convexsol.com:5349'],
'username' => 'convex_user',
'password' => 'secret_pass',
]);
$array = $dto->toArray();
$this->assertEquals(['turn:turn.convexsol.com:3478', 'turns:turn.convexsol.com:5349'], $array['urls']);
$this->assertEquals('convex_user', $array['username']);
$this->assertEquals('secret_pass', $array['credential']);
}
public function test_ice_candidates_dto_collection_handling(): void
{
$candidates = IceCandidatesDto::fromArray([
['urls' => 'stun:stun.l.google.com:19302'],
['urls' => 'turn:turn.convexsol.com:3478', 'username' => 'user1', 'credential' => 'pass1'],
]);
$this->assertCount(2, $candidates);
$this->assertFalse($candidates->isEmpty());
$array = $candidates->toArray();
$this->assertCount(2, $array);
$this->assertEquals('stun:stun.l.google.com:19302', $array[0]['urls']);
$this->assertEquals('user1', $array[1]['username']);
$this->assertEquals('pass1', $array[1]['credential']);
$json = json_encode($candidates);
$this->assertStringContainsString('stun:stun.l.google.com:19302', $json);
$this->assertStringContainsString('turn:turn.convexsol.com:3478', $json);
}
public function test_default_stun_factory(): void
{
$default = IceCandidatesDto::defaultStun();
$this->assertCount(1, $default);
$array = $default->toArray();
$this->assertContains('stun:stun.l.google.com:19302', $array[0]['urls']);
$this->assertContains('stun:stun.cloudflare.com:3478', $array[0]['urls']);
}
}