33namespace OpenTokTest \Validators ;
44
55use OpenTok \Exception \InvalidArgumentException ;
6+ use OpenTok \Util \Client ;
67use OpenTok \Util \Validators ;
78use PHPUnit \Framework \TestCase ;
89
@@ -66,34 +67,34 @@ public function testWillPassCorrectForceMutePayload(): void
6667 'streamId1 ' ,
6768 'streamId2 '
6869 ],
69- 'active ' => true
70+ 'active ' => true
7071 ];
7172
7273 Validators::validateForceMuteAllOptions ($ options );
7374 }
7475
75- public function testIsAssocWithValidArray (): void
76+ public function testIsAssocWithIndexedArray (): void
7677 {
77- $ haystack = [
78- 'one ' => '1 ' ,
79- 'two ' => '2 ' ,
80- 'three ' => '3 ' ,
81- 'four ' => '4 '
82- ];
78+ $ array = [1 , 2 , 3 , 4 ];
79+ $ this ->assertFalse (Validators::isAssoc ($ array ));
80+ }
8381
84- $ this ->assertTrue (Validators::isAssoc ($ haystack ));
82+ public function testIsAssocWithAssociativeArray (): void
83+ {
84+ $ array = ['a ' => 1 , 'b ' => 2 , 'c ' => 3 ];
85+ $ this ->assertTrue (Validators::isAssoc ($ array ));
8586 }
8687
87- public function testIsAssocWithInvalidArray (): void
88+ public function testIsAssocWithMixedKeysArray (): void
8889 {
89- $ haystack = [
90- 'one ' ,
91- 'two ' ,
92- 'three ' ,
93- 'four '
94- ];
90+ $ array = [1 , 'a ' => 2 , 3 ];
91+ $ this ->assertTrue (Validators::isAssoc ($ array ));
92+ }
9593
96- $ this ->assertFalse (Validators::isAssoc ($ haystack ));
94+ public function testIsAssocWithEmptyArray (): void
95+ {
96+ $ array = [];
97+ $ this ->assertFalse (Validators::isAssoc ($ array ));
9798 }
9899
99100 public function testWillFailWhenStreamIdsAreNotCorrect (): void
@@ -105,7 +106,7 @@ public function testWillFailWhenStreamIdsAreNotCorrect(): void
105106 3536 ,
106107 'streamId2 '
107108 ],
108- 'active ' => true
109+ 'active ' => true
109110 ];
110111
111112 Validators::validateForceMuteAllOptions ($ options );
@@ -120,7 +121,7 @@ public function testWillFailWhenActiveIsNotBool(): void
120121 'streamId1 ' ,
121122 'streamId2 '
122123 ],
123- 'active ' => 'true '
124+ 'active ' => 'true '
124125 ];
125126
126127 Validators::validateForceMuteAllOptions ($ options );
@@ -132,7 +133,7 @@ public function testWillFailWhenStreamIdsIsNotArray(): void
132133
133134 $ options = [
134135 'excludedStreams ' => 'streamIdOne ' ,
135- 'active ' => false
136+ 'active ' => false
136137 ];
137138
138139 Validators::validateForceMuteAllOptions ($ options );
@@ -142,7 +143,7 @@ public function testWillValidateWebsocketConfiguration(): void
142143 {
143144 $ this ->expectNotToPerformAssertions ();
144145 $ websocketConfig = [
145- 'uri ' => 'ws://valid-websocket ' ,
146+ 'uri ' => 'ws://valid-websocket ' ,
146147 'streams ' => [
147148 '525503c7-913e-43a1-84b4-31b2e9fe668b ' ,
148149 '14026813-4f50-4a5a-9b72-fea25430916d '
@@ -162,14 +163,14 @@ public function testWillThrowExceptionOnInvalidWebsocketConfiguration(): void
162163 ]
163164 ];
164165 Validators::validateWebsocketOptions ($ websocketConfig );
165- }
166+ }
166167
167168 /**
168169 * @dataProvider resolutionProvider
169170 */
170171 public function testValidResolutions ($ resolution , $ isValid ): void
171172 {
172- if (! $ isValid ) {
173+ if ( ! $ isValid ) {
173174 $ this ->expectException (InvalidArgumentException::class);
174175 } else {
175176 $ this ->expectNotToPerformAssertions ();
@@ -178,6 +179,121 @@ public function testValidResolutions($resolution, $isValid): void
178179 Validators::validateResolution ($ resolution );
179180 }
180181
182+ public function testValidLayoutClassListItemErrorOnString (): void
183+ {
184+ $ input = 'example_id ' ;
185+ $ this ->expectException (\InvalidArgumentException::class);
186+ Validators::validateLayoutClassListItem ($ input );
187+ }
188+
189+ public function testValidLayoutClassListItem (): void
190+ {
191+ $ layoutClassList = [
192+ 'id ' => 'example_id ' ,
193+ 'layoutClassList ' => ['class1 ' , 'class2 ' ]
194+ ];
195+
196+ $ this ->assertNull (Validators::validateLayoutClassListItem ($ layoutClassList ));
197+ }
198+
199+ public function testInvalidIdType (): void
200+ {
201+ $ this ->expectException (InvalidArgumentException::class);
202+ $ layoutClassList = [
203+ 'id ' => 123 ,
204+ 'layoutClassList ' => ['class1 ' , 'class2 ' ]
205+ ];
206+
207+ Validators::validateLayoutClassListItem ($ layoutClassList );
208+ }
209+
210+ public function testMissingLayoutClassList (): void
211+ {
212+ $ this ->expectException (InvalidArgumentException::class);
213+ $ layoutClassList = [
214+ 'id ' => 'example_id '
215+ ];
216+
217+ Validators::validateLayoutClassListItem ($ layoutClassList );
218+ }
219+
220+ public function testInvalidLayoutClassListType (): void
221+ {
222+ $ this ->expectException (InvalidArgumentException::class);
223+ $ layoutClassList = [
224+ 'id ' => 'example_id ' ,
225+ 'layoutClassList ' => 'invalid_class '
226+ ];
227+
228+ Validators::validateLayoutClassListItem ($ layoutClassList );
229+ }
230+ public function testValidateClient (): void
231+ {
232+ $ client = new Client ();
233+ Validators::validateClient ($ client );
234+
235+ // No exception, which was the test so fake a pass
236+ $ this ->assertTrue (true );
237+ }
238+
239+ public function testExceptionOnInvalidClient (): void
240+ {
241+ $ this ->expectException (\InvalidArgumentException::class);
242+ $ client = new \stdClass ();
243+ Validators::validateClient ($ client );
244+ }
245+
246+ public function testThrowsErrorOnInvalidStreamMode (): void
247+ {
248+ $ this ->expectException (\InvalidArgumentException::class);
249+ $ streamMode = ['auto ' ];
250+ Validators::validateHasStreamMode ($ streamMode );
251+ }
252+
253+ public function testValidateSignalPayload (): void
254+ {
255+ $ validPayload = ['type ' => 'signal_type ' , 'data ' => 'signal_data ' ];
256+ $ this ->assertNull (Validators::validateSignalPayload ($ validPayload ));
257+
258+ $ invalidDataPayload = ['type ' => 'signal_type ' , 'data ' => 123 ];
259+ $ this ->expectException (InvalidArgumentException::class);
260+ $ this ->expectExceptionMessage ("Signal Payload cannot be null: " );
261+ Validators::validateSignalPayload ($ invalidDataPayload );
262+
263+ $ invalidTypePayload = ['type ' => null , 'data ' => 'signal_data ' ];
264+ $ this ->expectException (InvalidArgumentException::class);
265+ $ this ->expectExceptionMessage ("Signal Payload cannot be null: " );
266+ Validators::validateSignalPayload ($ invalidTypePayload );
267+
268+ // Invalid payload: both type and data are null
269+ $ invalidBothPayload = ['type ' => null , 'data ' => null ];
270+ $ this ->expectException (InvalidArgumentException::class);
271+ $ this ->expectExceptionMessage ("Signal Payload cannot be null: " );
272+ Validators::validateSignalPayload ($ invalidBothPayload );
273+ }
274+
275+ /**
276+ * @dataProvider connectionIdProvider
277+ */
278+ public function testConnectionId ($ input , $ expectException ): void
279+ {
280+ if ($ expectException ) {
281+ $ this ->expectException (\InvalidArgumentException::class);
282+ }
283+
284+ Validators::validateConnectionId ($ input );
285+ $ this ->assertTrue (true );
286+ }
287+
288+ public function connectionIdProvider (): array
289+ {
290+ return [
291+ [['this ' => 'is not a string ' ], true ],
292+ ['' , true ],
293+ ['valid_connection_string ' , false ]
294+ ];
295+ }
296+
181297 public function resolutionProvider (): array
182298 {
183299 return [
0 commit comments