EachTest.php 908 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. declare(strict_types=1);
  3. namespace GuzzleHttp\Promise\Tests;
  4. use GuzzleHttp\Promise as P;
  5. use GuzzleHttp\Promise\FulfilledPromise;
  6. use GuzzleHttp\Promise\Promise;
  7. use GuzzleHttp\Promise\RejectedPromise;
  8. use PHPUnit\Framework\TestCase;
  9. class EachTest extends TestCase
  10. {
  11. public function testCallsEachLimit(): void
  12. {
  13. $p = new Promise();
  14. $aggregate = P\Each::ofLimit($p, 2);
  15. $p->resolve('a');
  16. P\Utils::queue()->run();
  17. $this->assertTrue(P\Is::fulfilled($aggregate));
  18. }
  19. public function testEachLimitAllRejectsOnFailure(): void
  20. {
  21. $p = [new FulfilledPromise('a'), new RejectedPromise('b')];
  22. $aggregate = P\Each::ofLimitAll($p, 2);
  23. P\Utils::queue()->run();
  24. $this->assertTrue(P\Is::rejected($aggregate));
  25. $result = P\Utils::inspect($aggregate);
  26. $this->assertSame('b', $result['reason']);
  27. }
  28. }