File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -53,16 +53,23 @@ final public function runAsyncTest(...$args)
5353
5454 $ start = \microtime (true );
5555
56- Loop::run (function () use (&$ returnValue , $ args ) {
56+ Loop::run (function () use (&$ returnValue , & $ exception , $ args ) {
5757 try {
5858 $ returnValue = yield call ([$ this , $ this ->realTestName ], ...$ args );
59+ } catch (\Throwable $ exception ) {
60+ // Also catches exception from potential nested loop.
61+ // Exception is rethrown after Loop::run().
5962 } finally {
6063 if (isset ($ this ->timeoutId )) {
6164 Loop::cancel ($ this ->timeoutId );
6265 }
6366 }
6467 });
6568
69+ if (isset ($ exception )) {
70+ throw $ exception ;
71+ }
72+
6673 $ actualRuntime = (int ) (\round (\microtime (true ) - $ start , self ::RUNTIME_PRECISION ) * 1000 );
6774 if ($ this ->minimumRuntime > $ actualRuntime ) {
6875 $ msg = 'Expected test to take at least %dms but instead took %dms ' ;
Original file line number Diff line number Diff line change @@ -57,6 +57,16 @@ public function testExpectingAnExceptionThrown(): \Generator
5757 yield $ throwException ();
5858 }
5959
60+ public function testNestedLoop ()
61+ {
62+ $ this ->expectException (\Exception::class);
63+ $ this ->expectExceptionMessage ('threw the error ' );
64+
65+ Loop::run (function () {
66+ throw new \Exception ('threw the error ' );
67+ });
68+ }
69+
6070 public function testExpectingAnErrorThrown (): \Generator
6171 {
6272 $ this ->expectException (\Error::class);
You can’t perform that action at this time.
0 commit comments