|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * BrtcModelTest.php |
| 5 | + * |
| 6 | + * Unit tests for BRTC model classes |
| 7 | + * |
| 8 | + * @copyright Bandwidth INC |
| 9 | + */ |
| 10 | + |
| 11 | +use PHPUnit\Framework\TestCase; |
| 12 | + |
| 13 | +final class BrtcModelTest extends TestCase |
| 14 | +{ |
| 15 | + public function testEndpointEventModel() { |
| 16 | + $device = new BandwidthLib\BRTC\Models\Device('dev-123', 'Test Device', 'ACTIVE', '2025-01-01T00:00:00Z'); |
| 17 | + |
| 18 | + $event = new BandwidthLib\BRTC\Models\EndpointEvent( |
| 19 | + 'ep-123', |
| 20 | + 'WEBRTC', |
| 21 | + 'ACTIVE', |
| 22 | + '2025-01-01T00:00:00Z', |
| 23 | + '2025-01-02T00:00:00Z', |
| 24 | + 'test-tag', |
| 25 | + '2025-01-01T01:00:00Z', |
| 26 | + 'DEVICE_CONNECTED', |
| 27 | + $device |
| 28 | + ); |
| 29 | + |
| 30 | + $this->assertEquals('ep-123', $event->endpointId); |
| 31 | + $this->assertEquals('WEBRTC', $event->type); |
| 32 | + $this->assertEquals('ACTIVE', $event->status); |
| 33 | + $this->assertEquals('2025-01-01T00:00:00Z', $event->creationTimestamp); |
| 34 | + $this->assertEquals('2025-01-02T00:00:00Z', $event->expirationTimestamp); |
| 35 | + $this->assertEquals('test-tag', $event->tag); |
| 36 | + $this->assertEquals('2025-01-01T01:00:00Z', $event->eventTime); |
| 37 | + $this->assertEquals('DEVICE_CONNECTED', $event->eventType); |
| 38 | + $this->assertInstanceOf(BandwidthLib\BRTC\Models\Device::class, $event->device); |
| 39 | + $this->assertEquals('dev-123', $event->device->deviceId); |
| 40 | + |
| 41 | + $json = $event->jsonSerialize(); |
| 42 | + $this->assertEquals('ep-123', $json['endpointId']); |
| 43 | + $this->assertEquals('DEVICE_CONNECTED', $json['eventType']); |
| 44 | + $this->assertEquals('2025-01-01T01:00:00Z', $json['eventTime']); |
| 45 | + } |
| 46 | + |
| 47 | + public function testEndpointEventModelDefaults() { |
| 48 | + $event = new BandwidthLib\BRTC\Models\EndpointEvent(); |
| 49 | + $this->assertNull($event->endpointId); |
| 50 | + $this->assertNull($event->type); |
| 51 | + $this->assertNull($event->device); |
| 52 | + $this->assertNull($event->eventType); |
| 53 | + } |
| 54 | + |
| 55 | + public function testDeviceModel() { |
| 56 | + $device = new BandwidthLib\BRTC\Models\Device('dev-456', 'My Phone', 'ACTIVE', '2025-01-01T00:00:00Z'); |
| 57 | + |
| 58 | + $this->assertEquals('dev-456', $device->deviceId); |
| 59 | + $this->assertEquals('My Phone', $device->deviceName); |
| 60 | + $this->assertEquals('ACTIVE', $device->status); |
| 61 | + $this->assertEquals('2025-01-01T00:00:00Z', $device->creationTimestamp); |
| 62 | + |
| 63 | + $json = $device->jsonSerialize(); |
| 64 | + $this->assertEquals('dev-456', $json['deviceId']); |
| 65 | + $this->assertEquals('My Phone', $json['deviceName']); |
| 66 | + $this->assertEquals('ACTIVE', $json['status']); |
| 67 | + $this->assertEquals('2025-01-01T00:00:00Z', $json['creationTimestamp']); |
| 68 | + } |
| 69 | + |
| 70 | + public function testDeviceModelDefaults() { |
| 71 | + $device = new BandwidthLib\BRTC\Models\Device(); |
| 72 | + $this->assertNull($device->deviceId); |
| 73 | + $this->assertNull($device->deviceName); |
| 74 | + $this->assertNull($device->status); |
| 75 | + $this->assertNull($device->creationTimestamp); |
| 76 | + } |
| 77 | + |
| 78 | + public function testPageModel() { |
| 79 | + $page = new BandwidthLib\BRTC\Models\Page(20, 100, 5, 1); |
| 80 | + |
| 81 | + $this->assertEquals(20, $page->pageSize); |
| 82 | + $this->assertEquals(100, $page->totalElements); |
| 83 | + $this->assertEquals(5, $page->totalPages); |
| 84 | + $this->assertEquals(1, $page->pageNumber); |
| 85 | + |
| 86 | + $json = $page->jsonSerialize(); |
| 87 | + $this->assertEquals(20, $json['pageSize']); |
| 88 | + $this->assertEquals(100, $json['totalElements']); |
| 89 | + $this->assertEquals(5, $json['totalPages']); |
| 90 | + $this->assertEquals(1, $json['pageNumber']); |
| 91 | + } |
| 92 | + |
| 93 | + public function testPageModelDefaults() { |
| 94 | + $page = new BandwidthLib\BRTC\Models\Page(); |
| 95 | + $this->assertNull($page->pageSize); |
| 96 | + $this->assertNull($page->totalElements); |
| 97 | + } |
| 98 | + |
| 99 | + public function testLinkModel() { |
| 100 | + $link = new BandwidthLib\BRTC\Models\Link('self', 'https://api.bandwidth.com/endpoints'); |
| 101 | + |
| 102 | + $this->assertEquals('self', $link->rel); |
| 103 | + $this->assertEquals('https://api.bandwidth.com/endpoints', $link->href); |
| 104 | + |
| 105 | + $json = $link->jsonSerialize(); |
| 106 | + $this->assertEquals('self', $json['rel']); |
| 107 | + $this->assertEquals('https://api.bandwidth.com/endpoints', $json['href']); |
| 108 | + } |
| 109 | + |
| 110 | + public function testErrorObjectModel() { |
| 111 | + $error = new BandwidthLib\BRTC\Models\ErrorObject('VALIDATION_ERROR', 'Field is required'); |
| 112 | + |
| 113 | + $this->assertEquals('VALIDATION_ERROR', $error->type); |
| 114 | + $this->assertEquals('Field is required', $error->description); |
| 115 | + |
| 116 | + $json = $error->jsonSerialize(); |
| 117 | + $this->assertEquals('VALIDATION_ERROR', $json['type']); |
| 118 | + $this->assertEquals('Field is required', $json['description']); |
| 119 | + } |
| 120 | +} |
0 commit comments