public function EachPromiseTest::testLimitsPendingPromises in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/guzzlehttp/promises/tests/EachPromiseTest.php \GuzzleHttp\Promise\Tests\EachPromiseTest::testLimitsPendingPromises()
File
- vendor/
guzzlehttp/ promises/ tests/ EachPromiseTest.php, line 81
Class
Namespace
GuzzleHttp\Promise\TestsCode
public function testLimitsPendingPromises() {
$pending = [
new Promise(),
new Promise(),
new Promise(),
new Promise(),
];
$promises = new \ArrayIterator($pending);
$each = new EachPromise($promises, [
'concurrency' => 2,
]);
$p = $each
->promise();
$this
->assertCount(2, $this
->readAttribute($each, 'pending'));
$pending[0]
->resolve('a');
$this
->assertCount(2, $this
->readAttribute($each, 'pending'));
$this
->assertTrue($promises
->valid());
$pending[1]
->resolve('b');
P\queue()
->run();
$this
->assertCount(2, $this
->readAttribute($each, 'pending'));
$this
->assertTrue($promises
->valid());
$promises[2]
->resolve('c');
P\queue()
->run();
$this
->assertCount(1, $this
->readAttribute($each, 'pending'));
$this
->assertEquals(PromiseInterface::PENDING, $p
->getState());
$promises[3]
->resolve('d');
P\queue()
->run();
$this
->assertNull($this
->readAttribute($each, 'pending'));
$this
->assertEquals(PromiseInterface::FULFILLED, $p
->getState());
$this
->assertFalse($promises
->valid());
}