You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.1 KiB
47 lines
1.1 KiB
3 months ago
|
<?php
|
||
|
namespace GuzzleHttp\Tests\Ring\Future;
|
||
|
|
||
|
use GuzzleHttp\Ring\Exception\CancelledFutureAccessException;
|
||
|
use GuzzleHttp\Ring\Future\CompletedFutureValue;
|
||
|
|
||
|
class CompletedFutureValueTest extends \PHPUnit_Framework_TestCase
|
||
|
{
|
||
|
public function testReturnsValue()
|
||
|
{
|
||
|
$f = new CompletedFutureValue('hi');
|
||
|
$this->assertEquals('hi', $f->wait());
|
||
|
$f->cancel();
|
||
|
|
||
|
$a = null;
|
||
|
$f->then(function ($v) use (&$a) {
|
||
|
$a = $v;
|
||
|
});
|
||
|
$this->assertSame('hi', $a);
|
||
|
}
|
||
|
|
||
|
public function testThrows()
|
||
|
{
|
||
|
$ex = new \Exception('foo');
|
||
|
$f = new CompletedFutureValue(null, $ex);
|
||
|
$f->cancel();
|
||
|
try {
|
||
|
$f->wait();
|
||
|
$this->fail('did not throw');
|
||
|
} catch (\Exception $e) {
|
||
|
$this->assertSame($e, $ex);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public function testMarksAsCancelled()
|
||
|
{
|
||
|
$ex = new CancelledFutureAccessException();
|
||
|
$f = new CompletedFutureValue(null, $ex);
|
||
|
try {
|
||
|
$f->wait();
|
||
|
$this->fail('did not throw');
|
||
|
} catch (\Exception $e) {
|
||
|
$this->assertSame($e, $ex);
|
||
|
}
|
||
|
}
|
||
|
}
|