CompletedFutureValueTest.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace GuzzleHttp\Tests\Ring\Future;
  3. use GuzzleHttp\Ring\Exception\CancelledFutureAccessException;
  4. use GuzzleHttp\Ring\Future\CompletedFutureValue;
  5. class CompletedFutureValueTest extends \PHPUnit_Framework_TestCase
  6. {
  7. public function testReturnsValue()
  8. {
  9. $f = new CompletedFutureValue('hi');
  10. $this->assertEquals('hi', $f->wait());
  11. $f->cancel();
  12. $a = null;
  13. $f->then(function ($v) use (&$a) {
  14. $a = $v;
  15. });
  16. $this->assertSame('hi', $a);
  17. }
  18. public function testThrows()
  19. {
  20. $ex = new \Exception('foo');
  21. $f = new CompletedFutureValue(null, $ex);
  22. $f->cancel();
  23. try {
  24. $f->wait();
  25. $this->fail('did not throw');
  26. } catch (\Exception $e) {
  27. $this->assertSame($e, $ex);
  28. }
  29. }
  30. public function testMarksAsCancelled()
  31. {
  32. $ex = new CancelledFutureAccessException();
  33. $f = new CompletedFutureValue(null, $ex);
  34. try {
  35. $f->wait();
  36. $this->fail('did not throw');
  37. } catch (\Exception $e) {
  38. $this->assertSame($e, $ex);
  39. }
  40. }
  41. }