You are here

public function PromiseTest::testCancelsChildPromises in Zircon Profile 8

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

File

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

Class

PromiseTest
@covers GuzzleHttp\Promise\Promise

Namespace

GuzzleHttp\Promise\Tests

Code

public function testCancelsChildPromises() {
  $called1 = $called2 = $called3 = false;
  $p1 = new Promise(null, function () use (&$called1) {
    $called1 = true;
  });
  $p2 = new Promise(null, function () use (&$called2) {
    $called2 = true;
  });
  $p3 = new Promise(null, function () use (&$called3) {
    $called3 = true;
  });
  $p4 = $p2
    ->then(function () use ($p3) {
    return $p3;
  });
  $p5 = $p4
    ->then(function () {
    $this
      ->fail();
  });
  $p4
    ->cancel();
  $this
    ->assertEquals('pending', $p1
    ->getState());
  $this
    ->assertEquals('rejected', $p2
    ->getState());
  $this
    ->assertEquals('rejected', $p4
    ->getState());
  $this
    ->assertEquals('pending', $p5
    ->getState());
  $this
    ->assertFalse($called1);
  $this
    ->assertTrue($called2);
  $this
    ->assertFalse($called3);
}