2
namespace GuzzleHttp\Tests\Ring\Client;
4
use GuzzleHttp\Ring\Client\MockHandler;
5
use GuzzleHttp\Ring\Future\FutureArray;
6
use React\Promise\Deferred;
8
class MockHandlerTest extends \PHPUnit_Framework_TestCase
10
public function testReturnsArray()
12
$mock = new MockHandler(['status' => 200]);
13
$response = $mock([]);
14
$this->assertEquals(200, $response['status']);
15
$this->assertEquals([], $response['headers']);
16
$this->assertNull($response['body']);
17
$this->assertNull($response['reason']);
18
$this->assertNull($response['effective_url']);
21
public function testReturnsFutures()
23
$deferred = new Deferred();
24
$future = new FutureArray(
26
function () use ($deferred) {
27
$deferred->resolve(['status' => 200]);
30
$mock = new MockHandler($future);
31
$response = $mock([]);
32
$this->assertInstanceOf('GuzzleHttp\Ring\Future\FutureArray', $response);
33
$this->assertEquals(200, $response['status']);
36
public function testReturnsFuturesWithThenCall()
38
$deferred = new Deferred();
39
$future = new FutureArray(
41
function () use ($deferred) {
42
$deferred->resolve(['status' => 200]);
45
$mock = new MockHandler($future);
46
$response = $mock([]);
47
$this->assertInstanceOf('GuzzleHttp\Ring\Future\FutureArray', $response);
48
$this->assertEquals(200, $response['status']);
50
$promise = $response->then(function ($value) use (&$req) {
52
$this->assertEquals(200, $req['status']);
54
$this->assertInstanceOf('React\Promise\PromiseInterface', $promise);
55
$this->assertEquals(200, $req['status']);
58
public function testReturnsFuturesAndProxiesCancel()
61
$deferred = new Deferred();
62
$future = new FutureArray(
65
function () use (&$c) {
70
$mock = new MockHandler($future);
71
$response = $mock([]);
72
$this->assertInstanceOf('GuzzleHttp\Ring\Future\FutureArray', $response);
74
$this->assertTrue($c);
78
* @expectedException \InvalidArgumentException
79
* @expectedExceptionMessage Response must be an array or FutureArrayInterface. Found
81
public function testEnsuresMockIsValid()
83
$mock = new MockHandler('foo');