blob: 6ded40dfba63f90c7cfb08f70b32c991a64db9ac (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
<?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);
}
}
}
|