55use GuzzleHttp \Handler \MockHandler ;
66use GuzzleHttp \HandlerStack ;
77use GuzzleHttp \Middleware ;
8- use OpenTok \Archive ;
98use OpenTok \Broadcast ;
109use OpenTok \Exception \InvalidArgumentException ;
1110use OpenTok \StreamMode ;
1413
1514class BroadcastTest extends TestCase
1615{
17-
18- // Fixtures
19- protected $ broadcastData ;
2016 protected $ API_KEY ;
2117 protected $ API_SECRET ;
2218
2319 protected $ broadcast ;
20+ protected $ broadcastData ;
2421 protected $ client ;
2522
2623 protected static $ mockBasePath ;
24+ /**
25+ * @var array
26+ */
27+ private $ historyContainer ;
2728
28- public static function setUpBeforeClass (): void
29- {
30- self ::$ mockBasePath = __DIR__ . DIRECTORY_SEPARATOR . '.. ' . DIRECTORY_SEPARATOR . 'mock ' . DIRECTORY_SEPARATOR ;
31- }
32-
33- public function setupBroadcasts ($ streamMode )
29+ public function setUp (): void
3430 {
35- // Set up fixtures
36- $ this ->broadcastData = array (
31+ $ this ->broadcastData = [
3732 'id ' => '063e72a4-64b4-43c8-9da5-eca071daab89 ' ,
3833 'createdAt ' => 1394394801000 ,
3934 'updatedAt ' => 1394394801000 ,
@@ -42,14 +37,27 @@ public function setupBroadcasts($streamMode)
4237 'layout ' => [
4338 'type ' => 'custom ' ,
4439 'stylesheet ' => 'a layout stylesheet ' ,
45- 'streenshareType ' => 'some options '
40+ 'screenshareType ' => 'some options '
4641 ],
4742 'maxDuration ' => 5400 ,
4843 'resolution ' => '640x480 ' ,
49- 'streamMode ' => $ streamMode
50- );
44+ 'streamMode ' => StreamMode::AUTO ,
45+ 'isAudio ' => true ,
46+ 'isVideo ' => true
47+ ];
48+ }
5149
52- $ this ->broadcast = new Broadcast ($ this ->broadcastData , array (
50+ public static function setUpBeforeClass (): void
51+ {
52+ self ::$ mockBasePath = __DIR__ . DIRECTORY_SEPARATOR . '.. ' . DIRECTORY_SEPARATOR . 'mock ' . DIRECTORY_SEPARATOR ;
53+ }
54+
55+ public function setupBroadcasts ($ streamMode )
56+ {
57+ $ data = $ this ->broadcastData ;
58+ $ data ['streamMode ' ] = $ streamMode ;
59+
60+ $ this ->broadcast = new Broadcast ($ data , array (
5361 'apiKey ' => $ this ->API_KEY ,
5462 'apiSecret ' => $ this ->API_SECRET ,
5563 'client ' => $ this ->client
@@ -88,6 +96,39 @@ private function setupOTWithMocks($mocks)
8896 $ handlerStack ->push ($ history );
8997 }
9098
99+ public function testCannotCreateBroadcastWithAddInvalidApiKey (): void
100+ {
101+ $ this ->expectException (InvalidArgumentException::class);
102+ $ this ->expectExceptionMessage ('The apiKey was not a string nor an integer: ' );
103+
104+ $ broadcastObject = new Broadcast ($ this ->broadcastData , [
105+ 'apiKey ' => new Client ()
106+ ]);
107+ }
108+
109+ public function testCannotCreateBroadcastWithInvalidApiSecret (): void
110+ {
111+ $ this ->expectException (InvalidArgumentException::class);
112+ $ this ->expectExceptionMessage ('The apiSecret was not a string: OpenTok\Util\Client Object ' );
113+
114+ $ broadcastObject = new Broadcast ($ this ->broadcastData , [
115+ 'apiKey ' => 'test ' ,
116+ 'apiSecret ' => new Client ()
117+ ]);
118+ }
119+
120+ public function testCannotCreateBroadcastWithInvalidApiUrl (): void
121+ {
122+ $ this ->expectException (InvalidArgumentException::class);
123+ $ this ->expectExceptionMessage ('The optional apiUrl was not a string: ' );
124+
125+ $ broadcastObject = new Broadcast ($ this ->broadcastData , [
126+ 'apiKey ' => 'validKey ' ,
127+ 'apiSecret ' => 'validSecret ' ,
128+ 'apiUrl ' => 'test '
129+ ]);
130+ }
131+
91132 private function setupOT ()
92133 {
93134 return $ this ->setupOTWithMocks ([]);
@@ -98,8 +139,6 @@ public function testInitializes()
98139 // Arrange
99140 $ this ->setupOT ();
100141 $ this ->setupBroadcasts (StreamMode::AUTO );
101- // Act
102- // Assert
103142 $ this ->assertInstanceOf (Broadcast::class, $ this ->broadcast );
104143 }
105144
@@ -180,5 +219,24 @@ public function testCanRemoveStreamFromBroadcast(): void
180219 );
181220 $ this ->assertTrue ($ return );
182221 }
222+
223+ public function testCannotRemoveStreamFromBroadcastOnAuto (): void
224+ {
225+ $ this ->expectException (InvalidArgumentException::class);
226+
227+ $ this ->setupOTWithMocks ([[
228+ 'code ' => 200 ,
229+ 'headers ' => [
230+ 'Content-Type ' => 'application/json '
231+ ],
232+ 'path ' => 'v2/project/APIKEY/broadcast/BROADCASTID/get '
233+ ]]);
234+
235+ $ this ->setupBroadcasts (StreamMode::AUTO );
236+
237+ $ return = $ this ->broadcast ->removeStreamFromBroadcast (
238+ '5dfds4-asdda4asf4 '
239+ );
240+ }
183241}
184242
0 commit comments