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