33namespace React \Promise \PromiseTest ;
44
55use React \Promise \Deferred ;
6+ use React \Promise \ErrorCollector ;
67use React \Promise \UnhandledRejectionException ;
78
89trait PromiseRejectedTestTrait
@@ -200,27 +201,40 @@ public function doneShouldInvokeRejectionHandlerForRejectedPromise()
200201 }
201202
202203 /** @test */
203- public function doneShouldThrowExceptionThrownByRejectionHandlerForRejectedPromise ()
204+ public function doneShouldTriggerFatalErrorExceptionThrownByRejectionHandlerForRejectedPromise ()
204205 {
205- $ adapter = $ this ->getPromiseTestAdapter ();
206+ $ errorCollector = new ErrorCollector ();
207+ $ errorCollector ->start ();
206208
207- $ this ->setExpectedException ( ' \Exception ' , ' UnhandledRejectionException ' );
209+ $ adapter = $ this ->getPromiseTestAdapter ( );
208210
209211 $ adapter ->reject (1 );
210212 $ this ->assertNull ($ adapter ->promise ()->done (null , function () {
211- throw new \Exception ('UnhandledRejectionException ' );
213+ throw new \Exception ('Unhandled Rejection ' );
212214 }));
215+
216+ $ errors = $ errorCollector ->stop ();
217+
218+ $ this ->assertEquals (E_USER_ERROR , $ errors [0 ]['errno ' ]);
219+ $ this ->assertContains ('Unhandled Rejection ' , $ errors [0 ]['errstr ' ]);
213220 }
214221
215222 /** @test */
216- public function doneShouldThrowUnhandledRejectionExceptionWhenRejectedWithNonExceptionForRejectedPromise ()
223+ public function doneShouldTriggerFatalErrorUnhandledRejectionExceptionWhenRejectedWithNonExceptionForRejectedPromise ()
217224 {
218225 $ adapter = $ this ->getPromiseTestAdapter ();
219226
220- $ this ->setExpectedException ('React \\Promise \\UnhandledRejectionException ' );
221-
222227 $ adapter ->reject (1 );
228+
229+ $ errorCollector = new ErrorCollector ();
230+ $ errorCollector ->start ();
231+
223232 $ 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 ' ]);
224238 }
225239
226240 /** @test */
@@ -232,57 +246,83 @@ public function unhandledRejectionExceptionThrownByDoneHoldsRejectionValue()
232246
233247 $ adapter ->reject ($ expected );
234248
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 ();
241255
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 ());
243262 }
244263
245264 /** @test */
246- public function doneShouldThrowUnhandledRejectionExceptionWhenRejectionHandlerRejectsForRejectedPromise ()
265+ public function doneShouldTriggerFatalErrorUnhandledRejectionExceptionWhenRejectionHandlerRejectsForRejectedPromise ()
247266 {
248- $ adapter = $ this ->getPromiseTestAdapter ();
267+ $ errorCollector = new ErrorCollector ();
268+ $ errorCollector ->start ();
249269
250- $ this ->setExpectedException ( ' React \\ Promise \\ UnhandledRejectionException ' );
270+ $ adapter = $ this ->getPromiseTestAdapter ( );
251271
252272 $ adapter ->reject (1 );
253273 $ this ->assertNull ($ adapter ->promise ()->done (null , function () {
254274 return \React \Promise \reject ();
255275 }));
276+
277+ $ errors = $ errorCollector ->stop ();
278+
279+ $ this ->assertEquals (E_USER_ERROR , $ errors [0 ]['errno ' ]);
280+ $ this ->assertContains ('Unhandled Rejection: null ' , $ errors [0 ]['errstr ' ]);
256281 }
257282
258283 /** @test */
259- public function doneShouldThrowRejectionExceptionWhenRejectionHandlerRejectsWithExceptionForRejectedPromise ()
284+ public function doneShouldTriggerFatalErrorRejectionExceptionWhenRejectionHandlerRejectsWithExceptionForRejectedPromise ()
260285 {
261- $ adapter = $ this ->getPromiseTestAdapter ();
286+ $ errorCollector = new ErrorCollector ();
287+ $ errorCollector ->start ();
262288
263- $ this ->setExpectedException ( ' \Exception ' , ' UnhandledRejectionException ' );
289+ $ adapter = $ this ->getPromiseTestAdapter ( );
264290
265291 $ adapter ->reject (1 );
266292 $ this ->assertNull ($ adapter ->promise ()->done (null , function () {
267- return \React \Promise \reject (new \Exception ('UnhandledRejectionException ' ));
293+ return \React \Promise \reject (new \Exception ('Unhandled Rejection ' ));
268294 }));
295+
296+ $ errors = $ errorCollector ->stop ();
297+
298+ $ this ->assertEquals (E_USER_ERROR , $ errors [0 ]['errno ' ]);
299+ $ this ->assertContains ('Unhandled Rejection ' , $ errors [0 ]['errstr ' ]);
269300 }
270301
271302 /** @test */
272- public function doneShouldThrowExceptionProvidedAsRejectionValueForRejectedPromise ()
303+ public function doneShouldTriggerFatalErrorExceptionProvidedAsRejectionValueForRejectedPromise ()
273304 {
305+ $ errorCollector = new ErrorCollector ();
306+ $ errorCollector ->start ();
307+
274308 $ adapter = $ this ->getPromiseTestAdapter ();
275309
276- $ this -> setExpectedException ( ' \Exception ' , ' UnhandledRejectionException ' );
310+ $ exception = new \Exception ( ' Unhandled Rejection ' );
277311
278- $ adapter ->reject (new \ Exception ( ' UnhandledRejectionException ' ) );
312+ $ adapter ->reject ($ exception );
279313 $ 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 ' ]);
280319 }
281320
282321 /** @test */
283- public function doneShouldThrowWithDeepNestingPromiseChainsForRejectedPromise ()
322+ public function doneShouldTriggerFatalErrorWithDeepNestingPromiseChainsForRejectedPromise ()
284323 {
285- $ this ->setExpectedException ('\Exception ' , 'UnhandledRejectionException ' );
324+ $ errorCollector = new ErrorCollector ();
325+ $ errorCollector ->start ();
286326
287327 $ exception = new \Exception ('UnhandledRejectionException ' );
288328
@@ -301,6 +341,11 @@ function () use ($exception) {
301341 })));
302342
303343 $ 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 ' ]);
304349 }
305350
306351 /** @test */
0 commit comments