Skip to content

Commit 8e3edc2

Browse files
smoghe-bwclaude
andcommitted
Remove try/catch blocks from BRTC tests and consolidate into single test
- Removed all try/catch wrappers from BRTC API calls — let tests fail naturally on exceptions, matching the pattern used by TN lookup and other existing smoke tests - Removed 6 redundant test methods (testCreateEndpointResponseFields, testGetEndpointFields, testListEndpointsContainsCreated, testListEndpointsEachItemIsEndpointsInstance, testCreateMultipleEndpointsAndDeleteAll, testDeleteEndpointRemovedFromList) - Consolidated all assertions into testCreateListGetDeleteEndpoint following the create → list → get → delete flow - Added thorough field assertions on each response (status, creationTimestamp, expirationTimestamp, tag, first list element) Generated from Claude9 with Claude Code Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 65ddbd7 commit 8e3edc2

1 file changed

Lines changed: 22 additions & 235 deletions

File tree

tests/ApiTest.php

Lines changed: 22 additions & 235 deletions
Original file line numberDiff line numberDiff line change
@@ -263,265 +263,52 @@ public function testCreateListGetDeleteEndpoint() {
263263
null,
264264
'php-sdk-test'
265265
);
266-
try {
267-
$createResp = $brtcClient->createEndpoint($accountId, $createReq)->getResult();
268-
} catch (BandwidthLib\APIException $e) {
269-
$this->fail("[{$e->getCode()}] {$e->getMessage()}");
270-
}
266+
$createResp = $brtcClient->createEndpoint($accountId, $createReq)->getResult();
271267
$this->assertInstanceOf(BandwidthLib\BRTC\Models\CreateEndpointResponse::class, $createResp);
272268
$this->assertIsArray($createResp->links);
273269
$this->assertNotNull($createResp->data);
274270
$this->assertInstanceOf(BandwidthLib\BRTC\Models\CreateEndpointResponseData::class, $createResp->data);
275271
$this->assertNotNull($createResp->data->endpointId);
272+
$this->assertIsString($createResp->data->endpointId);
276273
$this->assertEquals('WEBRTC', $createResp->data->type);
274+
$this->assertNotNull($createResp->data->status);
275+
$this->assertNotNull($createResp->data->creationTimestamp);
276+
$this->assertNotNull($createResp->data->expirationTimestamp);
277+
$this->assertEquals('php-sdk-test', $createResp->data->tag);
277278
$this->assertIsArray($createResp->errors);
278279

280+
$endpointId = $createResp->data->endpointId;
281+
279282
// List endpoints
280-
try {
281-
$listResp = $brtcClient->listEndpoints($accountId)->getResult();
282-
} catch (BandwidthLib\APIException $e) {
283-
$this->fail("[{$e->getCode()}] {$e->getMessage()}");
284-
}
283+
$listResp = $brtcClient->listEndpoints($accountId)->getResult();
285284
$this->assertInstanceOf(BandwidthLib\BRTC\Models\ListEndpointsResponse::class, $listResp);
286285
$this->assertIsArray($listResp->links);
287286
$this->assertIsArray($listResp->data);
287+
$this->assertNotEmpty($listResp->data);
288288
$this->assertIsArray($listResp->errors);
289+
$this->assertInstanceOf(BandwidthLib\BRTC\Models\Endpoints::class, $listResp->data[0]);
290+
$this->assertNotNull($listResp->data[0]->endpointId);
291+
$this->assertNotNull($listResp->data[0]->type);
292+
$this->assertNotNull($listResp->data[0]->status);
289293
$ids = array_map(fn($ep) => $ep->endpointId, $listResp->data);
290-
$this->assertContains($createResp->data->endpointId, $ids, 'Created endpoint should be in list');
294+
$this->assertContains($endpointId, $ids, 'Created endpoint should be in list');
291295

292296
// Get endpoint
293-
try {
294-
$getResp = $brtcClient->getEndpoint($accountId, $createResp->data->endpointId)->getResult();
295-
} catch (BandwidthLib\APIException $e) {
296-
$this->fail("[{$e->getCode()}] {$e->getMessage()}");
297-
}
297+
$getResp = $brtcClient->getEndpoint($accountId, $endpointId)->getResult();
298298
$this->assertInstanceOf(BandwidthLib\BRTC\Models\EndpointResponse::class, $getResp);
299299
$this->assertIsArray($getResp->links);
300300
$this->assertNotNull($getResp->data);
301301
$this->assertInstanceOf(BandwidthLib\BRTC\Models\Endpoint::class, $getResp->data);
302-
$this->assertEquals($createResp->data->endpointId, $getResp->data->endpointId);
302+
$this->assertEquals($endpointId, $getResp->data->endpointId);
303303
$this->assertEquals('WEBRTC', $getResp->data->type);
304+
$this->assertNotNull($getResp->data->status);
305+
$this->assertNotNull($getResp->data->creationTimestamp);
306+
$this->assertNotNull($getResp->data->expirationTimestamp);
307+
$this->assertEquals('php-sdk-test', $getResp->data->tag);
304308
$this->assertIsArray($getResp->errors);
305309

306310
// Delete endpoint
307-
try {
308-
$deleteResp = $brtcClient->deleteEndpoint($accountId, $createResp->data->endpointId);
309-
} catch (BandwidthLib\APIException $e) {
310-
$this->fail("[{$e->getCode()}] {$e->getMessage()}");
311-
}
311+
$deleteResp = $brtcClient->deleteEndpoint($accountId, $endpointId);
312312
$this->assertEquals(204, $deleteResp->getStatusCode());
313313
}
314-
315-
public function testCreateEndpointResponseFields() {
316-
$accountId = getenv("BW_ACCOUNT_ID");
317-
$brtcClient = self::$bandwidthClient->getBRTC()->getClient();
318-
319-
$createReq = new BandwidthLib\BRTC\Models\CreateEndpointRequest(
320-
'WEBRTC',
321-
'INBOUND',
322-
getenv("BASE_CALLBACK_URL") . "/brtc/events",
323-
getenv("BASE_CALLBACK_URL") . "/brtc/fallback",
324-
'php-sdk-fields-test'
325-
);
326-
try {
327-
$createResp = $brtcClient->createEndpoint($accountId, $createReq)->getResult();
328-
} catch (BandwidthLib\APIException $e) {
329-
$this->fail("[{$e->getCode()}] {$e->getMessage()}");
330-
}
331-
332-
$this->assertNotNull($createResp->data);
333-
$this->assertNotNull($createResp->data->endpointId);
334-
$this->assertIsString($createResp->data->endpointId);
335-
$this->assertEquals('WEBRTC', $createResp->data->type);
336-
$this->assertNotNull($createResp->data->status);
337-
$this->assertNotNull($createResp->data->creationTimestamp);
338-
$this->assertNotNull($createResp->data->expirationTimestamp);
339-
$this->assertEquals('php-sdk-fields-test', $createResp->data->tag);
340-
341-
// Cleanup
342-
try {
343-
$brtcClient->deleteEndpoint($accountId, $createResp->data->endpointId);
344-
} catch (BandwidthLib\APIException $e) {
345-
$this->fail("[{$e->getCode()}] {$e->getMessage()}");
346-
}
347-
}
348-
349-
public function testGetEndpointFields() {
350-
$accountId = getenv("BW_ACCOUNT_ID");
351-
$brtcClient = self::$bandwidthClient->getBRTC()->getClient();
352-
353-
$createReq = new BandwidthLib\BRTC\Models\CreateEndpointRequest(
354-
'WEBRTC',
355-
'INBOUND',
356-
getenv("BASE_CALLBACK_URL") . "/brtc/events",
357-
null,
358-
'php-sdk-get-test'
359-
);
360-
try {
361-
$endpointId = $brtcClient->createEndpoint($accountId, $createReq)->getResult()->data->endpointId;
362-
} catch (BandwidthLib\APIException $e) {
363-
$this->fail("[{$e->getCode()}] {$e->getMessage()}");
364-
}
365-
366-
try {
367-
$getResp = $brtcClient->getEndpoint($accountId, $endpointId)->getResult();
368-
} catch (BandwidthLib\APIException $e) {
369-
$this->fail("[{$e->getCode()}] {$e->getMessage()}");
370-
}
371-
$endpoint = $getResp->data;
372-
$this->assertInstanceOf(BandwidthLib\BRTC\Models\Endpoint::class, $endpoint);
373-
$this->assertEquals($endpointId, $endpoint->endpointId);
374-
$this->assertEquals('WEBRTC', $endpoint->type);
375-
$this->assertNotNull($endpoint->status);
376-
$this->assertNotNull($endpoint->creationTimestamp);
377-
$this->assertNotNull($endpoint->expirationTimestamp);
378-
$this->assertEquals('php-sdk-get-test', $endpoint->tag);
379-
380-
// Cleanup
381-
try {
382-
$brtcClient->deleteEndpoint($accountId, $endpointId);
383-
} catch (BandwidthLib\APIException $e) {
384-
$this->fail("[{$e->getCode()}] {$e->getMessage()}");
385-
}
386-
}
387-
388-
public function testListEndpointsContainsCreated() {
389-
$accountId = getenv("BW_ACCOUNT_ID");
390-
$brtcClient = self::$bandwidthClient->getBRTC()->getClient();
391-
392-
$createReq = new BandwidthLib\BRTC\Models\CreateEndpointRequest(
393-
'WEBRTC',
394-
'INBOUND',
395-
getenv("BASE_CALLBACK_URL") . "/brtc/events",
396-
null,
397-
'php-sdk-list-test'
398-
);
399-
try {
400-
$endpointId = $brtcClient->createEndpoint($accountId, $createReq)->getResult()->data->endpointId;
401-
} catch (BandwidthLib\APIException $e) {
402-
$this->fail("[{$e->getCode()}] {$e->getMessage()}");
403-
}
404-
405-
try {
406-
$listResp = $brtcClient->listEndpoints($accountId)->getResult();
407-
} catch (BandwidthLib\APIException $e) {
408-
$this->fail("[{$e->getCode()}] {$e->getMessage()}");
409-
}
410-
$this->assertIsArray($listResp->data);
411-
$this->assertNotEmpty($listResp->data);
412-
413-
$ids = array_map(fn($ep) => $ep->endpointId, $listResp->data);
414-
$this->assertContains($endpointId, $ids, 'Newly created endpoint should appear in list');
415-
416-
// Cleanup
417-
try {
418-
$brtcClient->deleteEndpoint($accountId, $endpointId);
419-
} catch (BandwidthLib\APIException $e) {
420-
$this->fail("[{$e->getCode()}] {$e->getMessage()}");
421-
}
422-
}
423-
424-
public function testListEndpointsEachItemIsEndpointsInstance() {
425-
$accountId = getenv("BW_ACCOUNT_ID");
426-
$brtcClient = self::$bandwidthClient->getBRTC()->getClient();
427-
428-
$createReq = new BandwidthLib\BRTC\Models\CreateEndpointRequest(
429-
'WEBRTC',
430-
'INBOUND',
431-
getenv("BASE_CALLBACK_URL") . "/brtc/events"
432-
);
433-
try {
434-
$endpointId = $brtcClient->createEndpoint($accountId, $createReq)->getResult()->data->endpointId;
435-
} catch (BandwidthLib\APIException $e) {
436-
$this->fail("[{$e->getCode()}] {$e->getMessage()}");
437-
}
438-
439-
try {
440-
$listResp = $brtcClient->listEndpoints($accountId)->getResult();
441-
} catch (BandwidthLib\APIException $e) {
442-
$this->fail("[{$e->getCode()}] {$e->getMessage()}");
443-
}
444-
foreach ($listResp->data as $ep) {
445-
$this->assertInstanceOf(BandwidthLib\BRTC\Models\Endpoints::class, $ep);
446-
$this->assertNotNull($ep->endpointId);
447-
$this->assertNotNull($ep->type);
448-
$this->assertNotNull($ep->status);
449-
}
450-
451-
// Cleanup
452-
try {
453-
$brtcClient->deleteEndpoint($accountId, $endpointId);
454-
} catch (BandwidthLib\APIException $e) {
455-
$this->fail("[{$e->getCode()}] {$e->getMessage()}");
456-
}
457-
}
458-
459-
public function testCreateMultipleEndpointsAndDeleteAll() {
460-
$accountId = getenv("BW_ACCOUNT_ID");
461-
$brtcClient = self::$bandwidthClient->getBRTC()->getClient();
462-
463-
$createdIds = [];
464-
for ($i = 0; $i < 3; $i++) {
465-
$createReq = new BandwidthLib\BRTC\Models\CreateEndpointRequest(
466-
'WEBRTC',
467-
'INBOUND',
468-
getenv("BASE_CALLBACK_URL") . "/brtc/events",
469-
null,
470-
"php-sdk-multi-{$i}"
471-
);
472-
try {
473-
$endpointId = $brtcClient->createEndpoint($accountId, $createReq)->getResult()->data->endpointId;
474-
} catch (BandwidthLib\APIException $e) {
475-
$this->fail("[{$e->getCode()}] {$e->getMessage()}");
476-
}
477-
$this->assertNotNull($endpointId);
478-
$createdIds[] = $endpointId;
479-
}
480-
481-
$this->assertCount(3, $createdIds);
482-
483-
// Delete all created endpoints
484-
foreach ($createdIds as $id) {
485-
try {
486-
$deleteResp = $brtcClient->deleteEndpoint($accountId, $id);
487-
} catch (BandwidthLib\APIException $e) {
488-
$this->fail("[{$e->getCode()}] {$e->getMessage()}");
489-
}
490-
$this->assertEquals(204, $deleteResp->getStatusCode());
491-
}
492-
}
493-
494-
public function testDeleteEndpointRemovedFromList() {
495-
$accountId = getenv("BW_ACCOUNT_ID");
496-
$brtcClient = self::$bandwidthClient->getBRTC()->getClient();
497-
498-
$createReq = new BandwidthLib\BRTC\Models\CreateEndpointRequest(
499-
'WEBRTC',
500-
'INBOUND',
501-
getenv("BASE_CALLBACK_URL") . "/brtc/events",
502-
null,
503-
'php-sdk-delete-check'
504-
);
505-
try {
506-
$endpointId = $brtcClient->createEndpoint($accountId, $createReq)->getResult()->data->endpointId;
507-
} catch (BandwidthLib\APIException $e) {
508-
$this->fail("[{$e->getCode()}] {$e->getMessage()}");
509-
}
510-
511-
// Delete it
512-
try {
513-
$brtcClient->deleteEndpoint($accountId, $endpointId);
514-
} catch (BandwidthLib\APIException $e) {
515-
$this->fail("[{$e->getCode()}] {$e->getMessage()}");
516-
}
517-
518-
// Should no longer appear in list
519-
try {
520-
$listResp = $brtcClient->listEndpoints($accountId)->getResult();
521-
} catch (BandwidthLib\APIException $e) {
522-
$this->fail("[{$e->getCode()}] {$e->getMessage()}");
523-
}
524-
$ids = array_map(fn($ep) => $ep->endpointId, $listResp->data);
525-
$this->assertNotContains($endpointId, $ids, 'Deleted endpoint should not appear in list');
526-
}
527314
}

0 commit comments

Comments
 (0)