CS fixes
Jan Sorgalla
9 years ago
49 | 49 | |
50 | 50 | public function always(callable $onFulfilledOrRejected) |
51 | 51 | { |
52 | return $this->then(function($value) use ($onFulfilledOrRejected) { | |
52 | return $this->then(function ($value) use ($onFulfilledOrRejected) { | |
53 | 53 | return resolve($onFulfilledOrRejected())->then(function () use ($value) { |
54 | 54 | return $value; |
55 | 55 | }); |
65 | 65 | |
66 | 66 | public function always(callable $onFulfilledOrRejected) |
67 | 67 | { |
68 | return $this->then(function($value) use ($onFulfilledOrRejected) { | |
68 | return $this->then(function ($value) use ($onFulfilledOrRejected) { | |
69 | 69 | return resolve($onFulfilledOrRejected())->then(function () use ($value) { |
70 | 70 | return $value; |
71 | 71 | }); |
140 | 140 | $result = $promise; |
141 | 141 | |
142 | 142 | if (!$result instanceof ExtendedPromiseInterface) { |
143 | $result = new static(function($resolve, $reject, $notify) use ($promise) { | |
143 | $result = new static(function ($resolve, $reject, $notify) use ($promise) { | |
144 | 144 | $promise->then($resolve, $reject, $notify); |
145 | 145 | }); |
146 | 146 | } |
327 | 327 | |
328 | 328 | $this->setExpectedException('\Exception', 'UnhandledRejectionException'); |
329 | 329 | |
330 | $this->assertNull($adapter->promise()->done(null, null, function() { | |
330 | $this->assertNull($adapter->promise()->done(null, null, function () { | |
331 | 331 | throw new \Exception('UnhandledRejectionException'); |
332 | 332 | })); |
333 | 333 | $adapter->notify(1); |
198 | 198 | $this->setExpectedException('\Exception', 'UnhandledRejectionException'); |
199 | 199 | |
200 | 200 | $adapter->resolve(1); |
201 | $this->assertNull($adapter->promise()->done(function() { | |
201 | $this->assertNull($adapter->promise()->done(function () { | |
202 | 202 | throw new \Exception('UnhandledRejectionException'); |
203 | 203 | })); |
204 | 204 | } |
211 | 211 | $this->setExpectedException('React\\Promise\\UnhandledRejectionException'); |
212 | 212 | |
213 | 213 | $adapter->resolve(1); |
214 | $this->assertNull($adapter->promise()->done(function() { | |
214 | $this->assertNull($adapter->promise()->done(function () { | |
215 | 215 | return \React\Promise\reject(); |
216 | 216 | })); |
217 | 217 | } |
240 | 240 | |
241 | 241 | $adapter->resolve($value); |
242 | 242 | $adapter->promise() |
243 | ->always(function() {}) | |
243 | ->always(function () {}) | |
244 | 244 | ->then($mock); |
245 | 245 | } |
246 | 246 | |
259 | 259 | |
260 | 260 | $adapter->resolve($value); |
261 | 261 | $adapter->promise() |
262 | ->always(function() { | |
262 | ->always(function () { | |
263 | 263 | return 1; |
264 | 264 | }) |
265 | 265 | ->then($mock); |
280 | 280 | |
281 | 281 | $adapter->resolve($value); |
282 | 282 | $adapter->promise() |
283 | ->always(function() { | |
283 | ->always(function () { | |
284 | 284 | return \React\Promise\resolve(1); |
285 | 285 | }) |
286 | 286 | ->then($mock); |
301 | 301 | |
302 | 302 | $adapter->resolve(1); |
303 | 303 | $adapter->promise() |
304 | ->always(function() use($exception) { | |
304 | ->always(function () use ($exception) { | |
305 | 305 | throw $exception; |
306 | 306 | }) |
307 | 307 | ->then(null, $mock); |
322 | 322 | |
323 | 323 | $adapter->resolve(1); |
324 | 324 | $adapter->promise() |
325 | ->always(function() use($exception) { | |
325 | ->always(function () use ($exception) { | |
326 | 326 | return \React\Promise\reject($exception); |
327 | 327 | }) |
328 | 328 | ->then(null, $mock); |
54 | 54 | { |
55 | 55 | $adapter = $this->getPromiseTestAdapter(); |
56 | 56 | |
57 | $this->assertInstanceOf('React\\Promise\\PromiseInterface', $adapter->promise()->always(function(){})); | |
57 | $this->assertInstanceOf('React\\Promise\\PromiseInterface', $adapter->promise()->always(function () {})); | |
58 | 58 | } |
59 | 59 | } |
205 | 205 | $this->setExpectedException('\Exception', 'UnhandledRejectionException'); |
206 | 206 | |
207 | 207 | $adapter->reject(1); |
208 | $this->assertNull($adapter->promise()->done(null, function() { | |
208 | $this->assertNull($adapter->promise()->done(null, function () { | |
209 | 209 | throw new \Exception('UnhandledRejectionException'); |
210 | 210 | })); |
211 | 211 | } |
229 | 229 | $this->setExpectedException('React\\Promise\\UnhandledRejectionException'); |
230 | 230 | |
231 | 231 | $adapter->reject(1); |
232 | $this->assertNull($adapter->promise()->done(null, function() { | |
232 | $this->assertNull($adapter->promise()->done(null, function () { | |
233 | 233 | return \React\Promise\reject(); |
234 | 234 | })); |
235 | 235 | } |
242 | 242 | $this->setExpectedException('\Exception', 'UnhandledRejectionException'); |
243 | 243 | |
244 | 244 | $adapter->reject(1); |
245 | $this->assertNull($adapter->promise()->done(null, function() { | |
245 | $this->assertNull($adapter->promise()->done(null, function () { | |
246 | 246 | return \React\Promise\reject(new \Exception('UnhandledRejectionException')); |
247 | 247 | })); |
248 | 248 | } |
268 | 268 | $d = new Deferred(); |
269 | 269 | $d->resolve(); |
270 | 270 | |
271 | $result = \React\Promise\resolve(\React\Promise\resolve($d->promise()->then(function () use($exception) { | |
271 | $result = \React\Promise\resolve(\React\Promise\resolve($d->promise()->then(function () use ($exception) { | |
272 | 272 | $d = new Deferred(); |
273 | 273 | $d->resolve(); |
274 | 274 | |
288 | 288 | $adapter = $this->getPromiseTestAdapter(); |
289 | 289 | |
290 | 290 | $adapter->reject(new \Exception('UnhandledRejectionException')); |
291 | $this->assertNull($adapter->promise()->done(null, function(\Exception $e) { | |
291 | $this->assertNull($adapter->promise()->done(null, function (\Exception $e) { | |
292 | 292 | |
293 | 293 | })); |
294 | 294 | } |
323 | 323 | |
324 | 324 | $adapter->reject($exception); |
325 | 325 | $adapter->promise() |
326 | ->otherwise(function(\InvalidArgumentException $reason) use ($mock) { | |
326 | ->otherwise(function (\InvalidArgumentException $reason) use ($mock) { | |
327 | 327 | $mock($reason); |
328 | 328 | }); |
329 | 329 | } |
339 | 339 | |
340 | 340 | $adapter->reject($exception); |
341 | 341 | $adapter->promise() |
342 | ->otherwise(function(\InvalidArgumentException $reason) use ($mock) { | |
342 | ->otherwise(function (\InvalidArgumentException $reason) use ($mock) { | |
343 | 343 | $mock($reason); |
344 | 344 | }); |
345 | 345 | } |
359 | 359 | |
360 | 360 | $adapter->reject($exception); |
361 | 361 | $adapter->promise() |
362 | ->always(function() {}) | |
362 | ->always(function () {}) | |
363 | 363 | ->then(null, $mock); |
364 | 364 | } |
365 | 365 | |
378 | 378 | |
379 | 379 | $adapter->reject($exception); |
380 | 380 | $adapter->promise() |
381 | ->always(function() { | |
381 | ->always(function () { | |
382 | 382 | return 1; |
383 | 383 | }) |
384 | 384 | ->then(null, $mock); |
399 | 399 | |
400 | 400 | $adapter->reject($exception); |
401 | 401 | $adapter->promise() |
402 | ->always(function() { | |
402 | ->always(function () { | |
403 | 403 | return \React\Promise\resolve(1); |
404 | 404 | }) |
405 | 405 | ->then(null, $mock); |
421 | 421 | |
422 | 422 | $adapter->reject($exception1); |
423 | 423 | $adapter->promise() |
424 | ->always(function() use ($exception2) { | |
424 | ->always(function () use ($exception2) { | |
425 | 425 | throw $exception2; |
426 | 426 | }) |
427 | 427 | ->then(null, $mock); |
443 | 443 | |
444 | 444 | $adapter->reject($exception1); |
445 | 445 | $adapter->promise() |
446 | ->always(function() use ($exception2) { | |
446 | ->always(function () use ($exception2) { | |
447 | 447 | return \React\Promise\reject($exception2); |
448 | 448 | }) |
449 | 449 | ->then(null, $mock); |
32 | 32 | $adapter = $this->getPromiseTestAdapter(); |
33 | 33 | |
34 | 34 | $adapter->settle(); |
35 | $this->assertNull($adapter->promise()->done(null, function() {})); | |
35 | $this->assertNull($adapter->promise()->done(null, function () {})); | |
36 | 36 | } |
37 | 37 | |
38 | 38 | /** @test */ |
41 | 41 | $adapter = $this->getPromiseTestAdapter(); |
42 | 42 | |
43 | 43 | $adapter->settle(); |
44 | $this->assertNull($adapter->promise()->done(null, function() {}, null)); | |
44 | $this->assertNull($adapter->promise()->done(null, function () {}, null)); | |
45 | 45 | } |
46 | 46 | |
47 | 47 | /** @test */ |
60 | 60 | $adapter = $this->getPromiseTestAdapter(); |
61 | 61 | |
62 | 62 | $adapter->settle(); |
63 | $this->assertInstanceOf('React\\Promise\\PromiseInterface', $adapter->promise()->always(function(){})); | |
63 | $this->assertInstanceOf('React\\Promise\\PromiseInterface', $adapter->promise()->always(function () {})); | |
64 | 64 | } |
65 | 65 | } |
145 | 145 | |
146 | 146 | $this->setExpectedException('\Exception', 'UnhandledRejectionException'); |
147 | 147 | |
148 | $this->assertNull($adapter->promise()->done(null, function() { | |
148 | $this->assertNull($adapter->promise()->done(null, function () { | |
149 | 149 | throw new \Exception('UnhandledRejectionException'); |
150 | 150 | })); |
151 | 151 | $adapter->reject(1); |
169 | 169 | |
170 | 170 | $this->setExpectedException('React\\Promise\\UnhandledRejectionException'); |
171 | 171 | |
172 | $this->assertNull($adapter->promise()->done(null, function() { | |
172 | $this->assertNull($adapter->promise()->done(null, function () { | |
173 | 173 | return \React\Promise\reject(); |
174 | 174 | })); |
175 | 175 | $adapter->reject(1); |
182 | 182 | |
183 | 183 | $this->setExpectedException('\Exception', 'UnhandledRejectionException'); |
184 | 184 | |
185 | $this->assertNull($adapter->promise()->done(null, function() { | |
185 | $this->assertNull($adapter->promise()->done(null, function () { | |
186 | 186 | return \React\Promise\reject(new \Exception('UnhandledRejectionException')); |
187 | 187 | })); |
188 | 188 | $adapter->reject(1); |
198 | 198 | $d = new Deferred(); |
199 | 199 | $promise = $d->promise(); |
200 | 200 | |
201 | $this->assertNull($adapter->promise()->done(null, function() use ($promise) { | |
201 | $this->assertNull($adapter->promise()->done(null, function () use ($promise) { | |
202 | 202 | return $promise; |
203 | 203 | })); |
204 | 204 | $adapter->reject(1); |
225 | 225 | |
226 | 226 | $d = new Deferred(); |
227 | 227 | |
228 | $result = \React\Promise\resolve(\React\Promise\resolve($d->promise()->then(function () use($exception) { | |
228 | $result = \React\Promise\resolve(\React\Promise\resolve($d->promise()->then(function () use ($exception) { | |
229 | 229 | $d = new Deferred(); |
230 | 230 | $d->resolve(); |
231 | 231 | |
246 | 246 | { |
247 | 247 | $adapter = $this->getPromiseTestAdapter(); |
248 | 248 | |
249 | $this->assertNull($adapter->promise()->done(null, function(\Exception $e) { | |
249 | $this->assertNull($adapter->promise()->done(null, function (\Exception $e) { | |
250 | 250 | |
251 | 251 | })); |
252 | 252 | $adapter->reject(new \Exception('UnhandledRejectionException')); |
266 | 266 | ->with($this->identicalTo($exception)); |
267 | 267 | |
268 | 268 | $adapter->promise() |
269 | ->always(function() {}) | |
269 | ->always(function () {}) | |
270 | 270 | ->then(null, $mock); |
271 | 271 | |
272 | 272 | $adapter->reject($exception); |
286 | 286 | ->with($this->identicalTo($exception)); |
287 | 287 | |
288 | 288 | $adapter->promise() |
289 | ->always(function() { | |
289 | ->always(function () { | |
290 | 290 | return 1; |
291 | 291 | }) |
292 | 292 | ->then(null, $mock); |
308 | 308 | ->with($this->identicalTo($exception)); |
309 | 309 | |
310 | 310 | $adapter->promise() |
311 | ->always(function() { | |
311 | ->always(function () { | |
312 | 312 | return \React\Promise\resolve(1); |
313 | 313 | }) |
314 | 314 | ->then(null, $mock); |
330 | 330 | ->with($this->identicalTo($exception)); |
331 | 331 | |
332 | 332 | $adapter->promise() |
333 | ->always(function() use($exception) { | |
333 | ->always(function () use ($exception) { | |
334 | 334 | throw $exception; |
335 | 335 | }) |
336 | 336 | ->then(null, $mock); |
352 | 352 | ->with($this->identicalTo($exception)); |
353 | 353 | |
354 | 354 | $adapter->promise() |
355 | ->always(function() use($exception) { | |
355 | ->always(function () use ($exception) { | |
356 | 356 | return \React\Promise\reject($exception); |
357 | 357 | }) |
358 | 358 | ->then(null, $mock); |
128 | 128 | |
129 | 129 | $this->setExpectedException('\Exception', 'UnhandledRejectionException'); |
130 | 130 | |
131 | $this->assertNull($adapter->promise()->done(function() { | |
131 | $this->assertNull($adapter->promise()->done(function () { | |
132 | 132 | throw new \Exception('UnhandledRejectionException'); |
133 | 133 | })); |
134 | 134 | $adapter->resolve(1); |
141 | 141 | |
142 | 142 | $this->setExpectedException('React\\Promise\\UnhandledRejectionException'); |
143 | 143 | |
144 | $this->assertNull($adapter->promise()->done(function() { | |
144 | $this->assertNull($adapter->promise()->done(function () { | |
145 | 145 | return \React\Promise\reject(); |
146 | 146 | })); |
147 | 147 | $adapter->resolve(1); |
161 | 161 | ->with($this->identicalTo($value)); |
162 | 162 | |
163 | 163 | $adapter->promise() |
164 | ->always(function() {}) | |
164 | ->always(function () {}) | |
165 | 165 | ->then($mock); |
166 | 166 | |
167 | 167 | $adapter->resolve($value); |
181 | 181 | ->with($this->identicalTo($value)); |
182 | 182 | |
183 | 183 | $adapter->promise() |
184 | ->always(function() { | |
184 | ->always(function () { | |
185 | 185 | return 1; |
186 | 186 | }) |
187 | 187 | ->then($mock); |
203 | 203 | ->with($this->identicalTo($value)); |
204 | 204 | |
205 | 205 | $adapter->promise() |
206 | ->always(function() { | |
206 | ->always(function () { | |
207 | 207 | return \React\Promise\resolve(1); |
208 | 208 | }) |
209 | 209 | ->then($mock); |
225 | 225 | ->with($this->identicalTo($exception)); |
226 | 226 | |
227 | 227 | $adapter->promise() |
228 | ->always(function() use($exception) { | |
228 | ->always(function () use ($exception) { | |
229 | 229 | throw $exception; |
230 | 230 | }) |
231 | 231 | ->then(null, $mock); |
247 | 247 | ->with($this->identicalTo($exception)); |
248 | 248 | |
249 | 249 | $adapter->promise() |
250 | ->always(function() use($exception) { | |
250 | ->always(function () use ($exception) { | |
251 | 251 | return \React\Promise\reject($exception); |
252 | 252 | }) |
253 | 253 | ->then(null, $mock); |