@@ -106,42 +106,53 @@ public function testCoroutineReturnsRejectedPromiseIfFunctionYieldsInvalidValue(
106
106
$ promise ->then (null , $ this ->expectCallableOnceWith (new \UnexpectedValueException ('Expected coroutine to yield React\Promise\PromiseInterface, but got integer ' )));
107
107
}
108
108
109
-
110
- public function testCoroutineWillCancelPendingPromiseWhenCallingCancelOnResultingPromise ()
109
+ public function testCancelCoroutineWillReturnRejectedPromiseWhenCancellingPendingPromiseRejects ()
111
110
{
112
- $ cancelled = 0 ;
113
- $ promise = coroutine (function () use (&$ cancelled ) {
114
- yield new Promise (function () use (&$ cancelled ) {
115
- ++$ cancelled ;
111
+ $ promise = coroutine (function () {
112
+ yield new Promise (function () { }, function () {
113
+ throw new \RuntimeException ('Operation cancelled ' );
116
114
});
117
115
});
118
116
119
117
$ promise ->cancel ();
120
118
121
- $ this -> assertEquals ( 1 , $ cancelled );
119
+ $ promise -> then ( null , $ this -> expectCallableOnceWith ( new \ RuntimeException ( ' Operation cancelled' )) );
122
120
}
123
121
124
- public function testCoroutineWillCancelAllPendingPromisesWhenFunctionContinuesToYieldWhenCallingCancelOnResultingPromise ()
122
+ public function testCancelCoroutineWillReturnFulfilledPromiseWhenCancellingPendingPromiseRejectsInsideCatchThatReturnsValue ()
125
123
{
126
124
$ promise = coroutine (function () {
127
- $ promise = new Promise (function () { }, function () {
128
- throw new \RuntimeException ('Frist operation cancelled ' , 21 );
129
- });
130
-
131
125
try {
132
- yield $ promise ;
126
+ yield new Promise (function () { }, function () {
127
+ throw new \RuntimeException ('Operation cancelled ' );
128
+ });
133
129
} catch (\RuntimeException $ e ) {
134
- // ignore exception and continue
130
+ return 42 ;
135
131
}
132
+ });
136
133
137
- yield new Promise (function () { }, function () {
138
- throw new \RuntimeException ('Second operation cancelled ' , 42 );
139
- });
134
+ $ promise ->cancel ();
135
+
136
+ $ promise ->then ($ this ->expectCallableOnceWith (42 ));
137
+ }
138
+
139
+ public function testCancelCoroutineWillReturnPendigPromiseWhenCancellingFirstPromiseRejectsInsideCatchThatYieldsSecondPromise ()
140
+ {
141
+ $ promise = coroutine (function () {
142
+ try {
143
+ yield new Promise (function () { }, function () {
144
+ throw new \RuntimeException ('First operation cancelled ' );
145
+ });
146
+ } catch (\RuntimeException $ e ) {
147
+ yield new Promise (function () { }, function () {
148
+ throw new \RuntimeException ('Second operation never cancelled ' );
149
+ });
150
+ }
140
151
});
141
152
142
153
$ promise ->cancel ();
143
154
144
- $ promise ->then (null , $ this ->expectCallableOnceWith ( new \ RuntimeException ( ' Second operation cancelled ' , 42 ) ));
155
+ $ promise ->then ($ this ->expectCallableNever (), $ this -> expectCallableNever ( ));
145
156
}
146
157
147
158
public function testCoroutineShouldNotCreateAnyGarbageReferencesWhenGeneratorReturns ()
0 commit comments