22
33namespace Ably \LaravelBroadcaster \Tests ;
44
5+ use Ably \Exceptions \AblyException ;
56use Ably \LaravelBroadcaster \Utils ;
67
78class UtilsTest extends TestCase
@@ -27,12 +28,49 @@ public function testGenerateAndValidateToken()
2728 self ::assertTrue ($ jwtIsValid );
2829 }
2930
30- public function testValidateDecodingSocketId () {
31+ /**
32+ * @throws AblyException
33+ */
34+ public function testDecodingSocketId () {
3135 $ socketId = new \stdClass ();
3236 $ socketId ->connectionKey = 'key ' ;
33- $ socketId ->clientId = ' clientId ' ;
37+ $ socketId ->clientId = null ;
3438 $ socketIdObject = Utils::decodeSocketId (Utils::base64url_encode (json_encode ($ socketId )));
3539 self ::assertEquals ('key ' , $ socketIdObject ->connectionKey );
36- self ::assertEquals ('clientId ' , $ socketIdObject ->clientId );
40+ self ::assertNull ($ socketIdObject ->clientId );
41+
42+ $ socketId = new \stdClass ();
43+ $ socketId ->connectionKey = 'key ' ;
44+ $ socketId ->clientId = 'id ' ;
45+ $ socketIdObject = Utils::decodeSocketId (Utils::base64url_encode (json_encode ($ socketId )));
46+ self ::assertEquals ('key ' , $ socketIdObject ->connectionKey );
47+ self ::assertEquals ('id ' , $ socketIdObject ->clientId );
48+ }
49+
50+ public function testExceptionOnDecodingInvalidSocketId ()
51+ {
52+ self ::expectException (AblyException::class);
53+ self ::expectExceptionMessage ("SocketId decoding failed, " .Utils::SOCKET_ID_ERROR );
54+ Utils::decodeSocketId ("invalid_socket_id " );
55+ }
56+
57+ public function testExceptionOnMissingClientIdInSocketId ()
58+ {
59+ $ socketId = new \stdClass ();
60+ $ socketId ->connectionKey = 'key ' ;
61+
62+ self ::expectException (AblyException::class);
63+ self ::expectExceptionMessage ("ClientId is missing, " .Utils::SOCKET_ID_ERROR );
64+ Utils::decodeSocketId (Utils::base64url_encode (json_encode ($ socketId )));
65+ }
66+
67+ public function testExceptionOnMissingConnectionKeyInSocketId ()
68+ {
69+ $ socketId = new \stdClass ();
70+ $ socketId ->clientId = 'id ' ;
71+
72+ self ::expectException (AblyException::class);
73+ self ::expectExceptionMessage ("ConnectionKey is not set, " .Utils::SOCKET_ID_ERROR );
74+ Utils::decodeSocketId (Utils::base64url_encode (json_encode ($ socketId )));
3775 }
3876}
0 commit comments