You are here

public function PromiseTest::testCancelsUppermostPendingPromise in Zircon Profile 8

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

File

vendor/guzzlehttp/promises/tests/PromiseTest.php, line 203

Class

PromiseTest
@covers GuzzleHttp\Promise\Promise

Namespace

GuzzleHttp\Promise\Tests

Code

public function testCancelsUppermostPendingPromise() {
  $called = false;
  $p1 = new Promise(null, function () use (&$called) {
    $called = true;
  });
  $p2 = $p1
    ->then(function () {
  });
  $p3 = $p2
    ->then(function () {
  });
  $p4 = $p3
    ->then(function () {
  });
  $p3
    ->cancel();
  $this
    ->assertEquals('rejected', $p1
    ->getState());
  $this
    ->assertEquals('rejected', $p2
    ->getState());
  $this
    ->assertEquals('rejected', $p3
    ->getState());
  $this
    ->assertEquals('pending', $p4
    ->getState());
  $this
    ->assertTrue($called);
  try {
    $p3
      ->wait();
    $this
      ->fail();
  } catch (CancellationException $e) {
    $this
      ->assertContains('cancelled', $e
      ->getMessage());
  }
  try {
    $p4
      ->wait();
    $this
      ->fail();
  } catch (CancellationException $e) {
    $this
      ->assertContains('cancelled', $e
      ->getMessage());
  }
  $this
    ->assertEquals('rejected', $p4
    ->getState());
}