You are here

public function EachPromiseTest::testCanResolveBeforeConsumingAll in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/guzzlehttp/promises/tests/EachPromiseTest.php \GuzzleHttp\Promise\Tests\EachPromiseTest::testCanResolveBeforeConsumingAll()

File

vendor/guzzlehttp/promises/tests/EachPromiseTest.php, line 54

Class

EachPromiseTest
@covers GuzzleHttp\Promise\EachPromise

Namespace

GuzzleHttp\Promise\Tests

Code

public function testCanResolveBeforeConsumingAll() {
  $called = 0;
  $a = new Promise(function () use (&$a) {
    $a
      ->resolve('a');
  });
  $b = new Promise(function () {
    $this
      ->fail();
  });
  $each = new EachPromise([
    $a,
    $b,
  ], [
    'fulfilled' => function ($value, $idx, Promise $aggregate) use (&$called) {
      $this
        ->assertSame($idx, 0);
      $this
        ->assertEquals('a', $value);
      $aggregate
        ->resolve(null);
      $called++;
    },
    'rejected' => function (\Exception $reason) {
      $this
        ->fail($reason
        ->getMessage());
    },
  ]);
  $p = $each
    ->promise();
  $p
    ->wait();
  $this
    ->assertNull($p
    ->wait());
  $this
    ->assertEquals(1, $called);
  $this
    ->assertEquals(PromiseInterface::FULFILLED, $a
    ->getState());
  $this
    ->assertEquals(PromiseInterface::PENDING, $b
    ->getState());

  // Resolving $b has no effect on the aggregate promise.
  $b
    ->resolve('foo');
  $this
    ->assertEquals(1, $called);
}