@@ -175,4 +175,109 @@ public function testParseRetryTime($input, $expected)
175
175
176
176
$ this ->assertSame ($ expected , $ retryTime );
177
177
}
178
+
179
+ public function testConstructWithDefaultLastEventIdAndType ()
180
+ {
181
+ $ message = new MessageEvent ('hello ' );
182
+
183
+ $ this ->assertEquals ('hello ' , $ message ->data );
184
+ $ this ->assertEquals ('' , $ message ->lastEventId );
185
+ $ this ->assertEquals ('message ' , $ message ->type );
186
+ }
187
+
188
+ public function testConstructWithEmptyDataAndId ()
189
+ {
190
+ $ message = new MessageEvent ('' , '' );
191
+
192
+ $ this ->assertEquals ('' , $ message ->data );
193
+ $ this ->assertEquals ('' , $ message ->lastEventId );
194
+ $ this ->assertEquals ('message ' , $ message ->type );
195
+ }
196
+
197
+ public function testConstructWithNullBytesInDataAndType ()
198
+ {
199
+ $ message = new MessageEvent ("h \x00llo! " , '' , "h \x00llo! " );
200
+
201
+ $ this ->assertEquals ("h \x00llo! " , $ message ->data );
202
+ $ this ->assertEquals ('' , $ message ->lastEventId );
203
+ $ this ->assertEquals ("h \x00llo! " , $ message ->type );
204
+ }
205
+
206
+ public function testConstructWithCarriageReturnAndLineFeedsInDataReplacedWithSimpleLineFeeds ()
207
+ {
208
+ $ message = new MessageEvent ("hello \rworld! \r\n" );
209
+
210
+ $ this ->assertEquals ("hello \nworld! \n" , $ message ->data );
211
+ }
212
+
213
+ public function testConstructWithInvalidDataUtf8Throws ()
214
+ {
215
+ $ this ->setExpectedException ('InvalidArgumentException ' , 'Invalid $data given, must be valid UTF-8 string ' );
216
+ new MessageEvent ("h \xFFllo! " );
217
+ }
218
+
219
+ public function testConstructWithInvalidLastEventIdUtf8Throws ()
220
+ {
221
+ $ this ->setExpectedException ('InvalidArgumentException ' , 'Invalid $lastEventId given, must be valid UTF-8 string with no null bytes or newline characters ' );
222
+ new MessageEvent ('hello ' , "h \xFFllo " );
223
+ }
224
+
225
+ public function testConstructWithInvalidLastEventIdNullThrows ()
226
+ {
227
+ $ this ->setExpectedException ('InvalidArgumentException ' , 'Invalid $lastEventId given, must be valid UTF-8 string with no null bytes or newline characters ' );
228
+ new MessageEvent ('hello ' , "h \x00llo " );
229
+ }
230
+
231
+ public function testConstructWithInvalidLastEventIdCarriageReturnThrows ()
232
+ {
233
+ $ this ->setExpectedException ('InvalidArgumentException ' , 'Invalid $lastEventId given, must be valid UTF-8 string with no null bytes or newline characters ' );
234
+ new MessageEvent ('hello ' , "hello \r" );
235
+ }
236
+
237
+ public function testConstructWithInvalidLastEventIdLineFeedThrows ()
238
+ {
239
+ $ this ->setExpectedException ('InvalidArgumentException ' , 'Invalid $lastEventId given, must be valid UTF-8 string with no null bytes or newline characters ' );
240
+ new MessageEvent ('hello ' , "hello \n" );
241
+ }
242
+
243
+ public function testConstructWithInvalidTypeUtf8Throws ()
244
+ {
245
+ $ this ->setExpectedException ('InvalidArgumentException ' , 'Invalid $type given, must be valid UTF-8 string with no newline characters ' );
246
+ new MessageEvent ('hello ' , '' , "h \xFFllo " );
247
+ }
248
+
249
+ public function testConstructWithInvalidTypeEmptyThrows ()
250
+ {
251
+ $ this ->setExpectedException ('InvalidArgumentException ' , 'Invalid $type given, must be valid UTF-8 string with no newline characters ' );
252
+ new MessageEvent ('hello ' , '' , '' );
253
+ }
254
+
255
+ public function testConstructWithInvalidTypeCarriageReturnThrows ()
256
+ {
257
+ $ this ->setExpectedException ('InvalidArgumentException ' , 'Invalid $type given, must be valid UTF-8 string with no newline characters ' );
258
+ new MessageEvent ('hello ' , '' , "hello \r" );
259
+ }
260
+
261
+ public function testConstructWithInvalidTypeLineFeedThrows ()
262
+ {
263
+ $ this ->setExpectedException ('InvalidArgumentException ' , 'Invalid $type given, must be valid UTF-8 string with no newline characters ' );
264
+ new MessageEvent ('hello ' , '' , "hello \r" );
265
+ }
266
+
267
+ public function setExpectedException ($ exception , $ exceptionMessage = '' , $ exceptionCode = null )
268
+ {
269
+ if (method_exists ($ this , 'expectException ' )) {
270
+ // PHPUnit 5.2+
271
+ $ this ->expectException ($ exception );
272
+ if ($ exceptionMessage !== '' ) {
273
+ $ this ->expectExceptionMessage ($ exceptionMessage );
274
+ }
275
+ if ($ exceptionCode !== null ) {
276
+ $ this ->expectExceptionCode ($ exceptionCode );
277
+ }
278
+ } else {
279
+ // legacy PHPUnit < 5.2
280
+ parent ::setExpectedException ($ exception , $ exceptionMessage , $ exceptionCode );
281
+ }
282
+ }
178
283
}
0 commit comments