@@ -2926,6 +2926,98 @@ public function testListStreams(): void
29262926 $ this ->assertInstanceOf ('OpenTok\StreamList ' , $ streamList );
29272927 }
29282928
2929+ public function testListConnections (): void
2930+ {
2931+ // Arrange
2932+ $ this ->setupOTWithMocks ([[
2933+ 'code ' => 200 ,
2934+ 'headers ' => [
2935+ 'Content-Type ' => 'application/json '
2936+ ],
2937+ 'path ' => '/v2/project/APIKEY/session/SESSIONID/connection/get '
2938+ ]]);
2939+
2940+ $ sessionId = '1_MX4xMjM0NTY3OH4-VGh1IEZlYiAyNyAwNDozODozMSBQU1QgMjAxNH4wLjI0NDgyMjI ' ;
2941+
2942+ // Act
2943+ $ connectionList = $ this ->opentok ->listConnections ($ sessionId );
2944+
2945+ // Assert
2946+ $ this ->assertCount (1 , $ this ->historyContainer );
2947+
2948+ $ request = $ this ->historyContainer [0 ]['request ' ];
2949+ $ this ->assertEquals ('GET ' , strtoupper ($ request ->getMethod ()));
2950+ $ this ->assertEquals ('/v2/project/ ' . $ this ->API_KEY . '/session/ ' . $ sessionId . '/connection/ ' , $ request ->getUri ()->getPath ());
2951+ $ this ->assertEquals ('api.opentok.com ' , $ request ->getUri ()->getHost ());
2952+ $ this ->assertEquals ('https ' , $ request ->getUri ()->getScheme ());
2953+
2954+ $ authString = $ request ->getHeaderLine ('X-OPENTOK-AUTH ' );
2955+ $ this ->assertEquals (true , TestHelpers::validateOpenTokAuthHeader ($ this ->API_KEY , $ this ->API_SECRET , $ authString ));
2956+
2957+ $ this ->assertInstanceOf ('OpenTok\ConnectionList ' , $ connectionList );
2958+ $ this ->assertEquals (3 , $ connectionList ->totalCount ());
2959+ $ this ->assertEquals ('e9f8c166-6c67-440d-994a-04fb6dfed007 ' , $ connectionList ->getProjectId ());
2960+ $ this ->assertEquals ('b40ef09b-3811-4726-b508-e41a0f96c68f ' , $ connectionList ->getSessionId ());
2961+
2962+ $ connections = $ connectionList ->getItems ();
2963+ $ this ->assertCount (3 , $ connections );
2964+ $ this ->assertInstanceOf ('OpenTok\Connection ' , $ connections [0 ]);
2965+ $ this ->assertEquals ('8b732909-0a06-46a2-8ea8-074e64d43422 ' , $ connections [0 ]->connectionId );
2966+ $ this ->assertEquals ('Connected ' , $ connections [0 ]->connectionState );
2967+ $ this ->assertEquals ('1384221730000 ' , $ connections [0 ]->createdAt );
2968+ }
2969+
2970+ public function testListConnectionsWithInvalidSessionId (): void
2971+ {
2972+ // Arrange
2973+ $ this ->setupOT ();
2974+
2975+ // Assert
2976+ $ this ->expectException ('OpenTok\Exception\InvalidArgumentException ' );
2977+
2978+ // Act
2979+ $ this ->opentok ->listConnections ('invalid-session-id ' );
2980+ }
2981+
2982+ public function testListConnectionsIteration (): void
2983+ {
2984+ // Arrange
2985+ $ this ->setupOTWithMocks ([[
2986+ 'code ' => 200 ,
2987+ 'headers ' => [
2988+ 'Content-Type ' => 'application/json '
2989+ ],
2990+ 'path ' => '/v2/project/APIKEY/session/SESSIONID/connection/get '
2991+ ]]);
2992+
2993+ $ sessionId = '1_MX4xMjM0NTY3OH4-VGh1IEZlYiAyNyAwNDozODozMSBQU1QgMjAxNH4wLjI0NDgyMjI ' ;
2994+
2995+ // Act
2996+ $ connectionList = $ this ->opentok ->listConnections ($ sessionId );
2997+
2998+ // Assert - Test direct iteration over ConnectionList
2999+ $ iteratedConnections = [];
3000+ foreach ($ connectionList as $ index => $ connection ) {
3001+ $ iteratedConnections [$ index ] = $ connection ;
3002+ $ this ->assertInstanceOf ('OpenTok\Connection ' , $ connection );
3003+ }
3004+
3005+ $ this ->assertCount (3 , $ iteratedConnections );
3006+ $ this ->assertEquals ('8b732909-0a06-46a2-8ea8-074e64d43422 ' , $ iteratedConnections [0 ]->connectionId );
3007+ $ this ->assertEquals ('Connected ' , $ iteratedConnections [0 ]->connectionState );
3008+ $ this ->assertEquals ('ab732909-0a06-46a2-8ea8-074e64d43412 ' , $ iteratedConnections [1 ]->connectionId );
3009+ $ this ->assertEquals ('Connecting ' , $ iteratedConnections [1 ]->connectionState );
3010+ $ this ->assertEquals ('cd732909-0a06-46a2-8ea8-074e64d43433 ' , $ iteratedConnections [2 ]->connectionId );
3011+ $ this ->assertEquals ('Connected ' , $ iteratedConnections [2 ]->connectionState );
3012+
3013+ // Assert - Test that getItems() still works as before
3014+ $ itemsConnections = $ connectionList ->getItems ();
3015+ $ this ->assertCount (3 , $ itemsConnections );
3016+ $ this ->assertEquals ($ iteratedConnections [0 ]->connectionId , $ itemsConnections [0 ]->connectionId );
3017+ $ this ->assertEquals ($ iteratedConnections [1 ]->connectionId , $ itemsConnections [1 ]->connectionId );
3018+ $ this ->assertEquals ($ iteratedConnections [2 ]->connectionId , $ itemsConnections [2 ]->connectionId );
3019+ }
3020+
29293021 public function testsSetArchiveLayoutWithPredefined (): void
29303022 {
29313023 // Arrange
0 commit comments