3
3
namespace React \Promise \PromiseTest ;
4
4
5
5
use React \Promise \Deferred ;
6
+ use React \Promise \ErrorCollector ;
6
7
use React \Promise \UnhandledRejectionException ;
7
8
8
9
trait PromiseRejectedTestTrait
@@ -200,27 +201,40 @@ public function doneShouldInvokeRejectionHandlerForRejectedPromise()
200
201
}
201
202
202
203
/** @test */
203
- public function doneShouldThrowExceptionThrownByRejectionHandlerForRejectedPromise ()
204
+ public function doneShouldTriggerFatalErrorExceptionThrownByRejectionHandlerForRejectedPromise ()
204
205
{
205
- $ adapter = $ this ->getPromiseTestAdapter ();
206
+ $ errorCollector = new ErrorCollector ();
207
+ $ errorCollector ->start ();
206
208
207
- $ this ->setExpectedException ( ' \Exception ' , ' UnhandledRejectionException ' );
209
+ $ adapter = $ this ->getPromiseTestAdapter ( );
208
210
209
211
$ adapter ->reject (1 );
210
212
$ this ->assertNull ($ adapter ->promise ()->done (null , function () {
211
- throw new \Exception ('UnhandledRejectionException ' );
213
+ throw new \Exception ('Unhandled Rejection ' );
212
214
}));
215
+
216
+ $ errors = $ errorCollector ->stop ();
217
+
218
+ $ this ->assertEquals (E_USER_ERROR , $ errors [0 ]['errno ' ]);
219
+ $ this ->assertContains ('Unhandled Rejection ' , $ errors [0 ]['errstr ' ]);
213
220
}
214
221
215
222
/** @test */
216
- public function doneShouldThrowUnhandledRejectionExceptionWhenRejectedWithNonExceptionForRejectedPromise ()
223
+ public function doneShouldTriggerFatalErrorUnhandledRejectionExceptionWhenRejectedWithNonExceptionForRejectedPromise ()
217
224
{
218
225
$ adapter = $ this ->getPromiseTestAdapter ();
219
226
220
- $ this ->setExpectedException ('React \\Promise \\UnhandledRejectionException ' );
221
-
222
227
$ adapter ->reject (1 );
228
+
229
+ $ errorCollector = new ErrorCollector ();
230
+ $ errorCollector ->start ();
231
+
223
232
$ this ->assertNull ($ adapter ->promise ()->done ());
233
+
234
+ $ errors = $ errorCollector ->stop ();
235
+
236
+ $ this ->assertEquals (E_USER_ERROR , $ errors [0 ]['errno ' ]);
237
+ $ this ->assertContains ('Unhandled Rejection: 1 ' , $ errors [0 ]['errstr ' ]);
224
238
}
225
239
226
240
/** @test */
@@ -232,57 +246,83 @@ public function unhandledRejectionExceptionThrownByDoneHoldsRejectionValue()
232
246
233
247
$ adapter ->reject ($ expected );
234
248
235
- try {
236
- $ adapter -> promise ()-> done ();
237
- } catch ( UnhandledRejectionException $ e ) {
238
- $ this -> assertSame ( $ expected , $ e -> getReason () );
239
- return ;
240
- }
249
+ $ errorCollector = new ErrorCollector ();
250
+ $ errorCollector -> start ();
251
+
252
+ $ adapter -> promise ()-> done ( );
253
+
254
+ $ errors = $ errorCollector -> stop ();
241
255
242
- $ this ->fail ();
256
+ $ this ->assertEquals (E_USER_ERROR , $ errors [0 ]['errno ' ]);
257
+ $ this ->assertContains ('Unhandled Rejection: {} ' , $ errors [0 ]['errstr ' ]);
258
+
259
+ $ this ->assertArrayHasKey ('error ' , $ errors [0 ]['errcontext ' ]);
260
+ $ this ->assertInstanceOf ('React\Promise\UnhandledRejectionException ' , $ errors [0 ]['errcontext ' ]['error ' ]);
261
+ $ this ->assertSame ($ expected , $ errors [0 ]['errcontext ' ]['error ' ]->getReason ());
243
262
}
244
263
245
264
/** @test */
246
- public function doneShouldThrowUnhandledRejectionExceptionWhenRejectionHandlerRejectsForRejectedPromise ()
265
+ public function doneShouldTriggerFatalErrorUnhandledRejectionExceptionWhenRejectionHandlerRejectsForRejectedPromise ()
247
266
{
248
- $ adapter = $ this ->getPromiseTestAdapter ();
267
+ $ errorCollector = new ErrorCollector ();
268
+ $ errorCollector ->start ();
249
269
250
- $ this ->setExpectedException ( ' React \\ Promise \\ UnhandledRejectionException ' );
270
+ $ adapter = $ this ->getPromiseTestAdapter ( );
251
271
252
272
$ adapter ->reject (1 );
253
273
$ this ->assertNull ($ adapter ->promise ()->done (null , function () {
254
274
return \React \Promise \reject ();
255
275
}));
276
+
277
+ $ errors = $ errorCollector ->stop ();
278
+
279
+ $ this ->assertEquals (E_USER_ERROR , $ errors [0 ]['errno ' ]);
280
+ $ this ->assertContains ('Unhandled Rejection: null ' , $ errors [0 ]['errstr ' ]);
256
281
}
257
282
258
283
/** @test */
259
- public function doneShouldThrowRejectionExceptionWhenRejectionHandlerRejectsWithExceptionForRejectedPromise ()
284
+ public function doneShouldTriggerFatalErrorRejectionExceptionWhenRejectionHandlerRejectsWithExceptionForRejectedPromise ()
260
285
{
261
- $ adapter = $ this ->getPromiseTestAdapter ();
286
+ $ errorCollector = new ErrorCollector ();
287
+ $ errorCollector ->start ();
262
288
263
- $ this ->setExpectedException ( ' \Exception ' , ' UnhandledRejectionException ' );
289
+ $ adapter = $ this ->getPromiseTestAdapter ( );
264
290
265
291
$ adapter ->reject (1 );
266
292
$ this ->assertNull ($ adapter ->promise ()->done (null , function () {
267
- return \React \Promise \reject (new \Exception ('UnhandledRejectionException ' ));
293
+ return \React \Promise \reject (new \Exception ('Unhandled Rejection ' ));
268
294
}));
295
+
296
+ $ errors = $ errorCollector ->stop ();
297
+
298
+ $ this ->assertEquals (E_USER_ERROR , $ errors [0 ]['errno ' ]);
299
+ $ this ->assertContains ('Unhandled Rejection ' , $ errors [0 ]['errstr ' ]);
269
300
}
270
301
271
302
/** @test */
272
- public function doneShouldThrowExceptionProvidedAsRejectionValueForRejectedPromise ()
303
+ public function doneShouldTriggerFatalErrorExceptionProvidedAsRejectionValueForRejectedPromise ()
273
304
{
305
+ $ errorCollector = new ErrorCollector ();
306
+ $ errorCollector ->start ();
307
+
274
308
$ adapter = $ this ->getPromiseTestAdapter ();
275
309
276
- $ this -> setExpectedException ( ' \Exception ' , ' UnhandledRejectionException ' );
310
+ $ exception = new \Exception ( ' Unhandled Rejection ' );
277
311
278
- $ adapter ->reject (new \ Exception ( ' UnhandledRejectionException ' ) );
312
+ $ adapter ->reject ($ exception );
279
313
$ this ->assertNull ($ adapter ->promise ()->done ());
314
+
315
+ $ errors = $ errorCollector ->stop ();
316
+
317
+ $ this ->assertEquals (E_USER_ERROR , $ errors [0 ]['errno ' ]);
318
+ $ this ->assertEquals ((string ) $ exception , $ errors [0 ]['errstr ' ]);
280
319
}
281
320
282
321
/** @test */
283
- public function doneShouldThrowWithDeepNestingPromiseChainsForRejectedPromise ()
322
+ public function doneShouldTriggerFatalErrorWithDeepNestingPromiseChainsForRejectedPromise ()
284
323
{
285
- $ this ->setExpectedException ('\Exception ' , 'UnhandledRejectionException ' );
324
+ $ errorCollector = new ErrorCollector ();
325
+ $ errorCollector ->start ();
286
326
287
327
$ exception = new \Exception ('UnhandledRejectionException ' );
288
328
@@ -301,6 +341,11 @@ function () use ($exception) {
301
341
})));
302
342
303
343
$ result ->done ();
344
+
345
+ $ errors = $ errorCollector ->stop ();
346
+
347
+ $ this ->assertEquals (E_USER_ERROR , $ errors [0 ]['errno ' ]);
348
+ $ this ->assertEquals ((string ) $ exception , $ errors [0 ]['errstr ' ]);
304
349
}
305
350
306
351
/** @test */
0 commit comments