You are here

public function FunctionsTest::testCanCatchExceptionsInCoroutine in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/guzzlehttp/promises/tests/functionsTest.php \GuzzleHttp\Promise\Tests\FunctionsTest::testCanCatchExceptionsInCoroutine()

File

vendor/guzzlehttp/promises/tests/functionsTest.php, line 344

Class

FunctionsTest

Namespace

GuzzleHttp\Promise\Tests

Code

public function testCanCatchExceptionsInCoroutine() {
  $promise = P\coroutine(function () {
    try {
      (yield new P\RejectedPromise('a'));
      $this
        ->fail('Should have thrown into the coroutine!');
    } catch (P\RejectionException $e) {
      $value = (yield new P\FulfilledPromise($e
        ->getReason()));
      (yield $value . 'b');
    }
  });
  $promise
    ->then(function ($value) use (&$result) {
    $result = $value;
  });
  P\queue()
    ->run();
  $this
    ->assertEquals(P\PromiseInterface::FULFILLED, $promise
    ->getState());
  $this
    ->assertEquals('ab', $result);
}