ProxyTest.php
1.82 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
<?php
namespace GuzzleHttp\Test\Handler;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\Handler\Proxy;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\RequestOptions;
use PHPUnit\Framework\TestCase;
/**
* @covers \GuzzleHttp\Handler\Proxy
*/
class ProxyTest extends TestCase
{
public function testSendsToNonSync()
{
$a = $b = null;
$m1 = new MockHandler([function ($v) use (&$a) { $a = $v; }]);
$m2 = new MockHandler([function ($v) use (&$b) { $b = $v; }]);
$h = Proxy::wrapSync($m1, $m2);
$h(new Request('GET', 'http://foo.com'), []);
$this->assertNotNull($a);
$this->assertNull($b);
}
public function testSendsToSync()
{
$a = $b = null;
$m1 = new MockHandler([function ($v) use (&$a) { $a = $v; }]);
$m2 = new MockHandler([function ($v) use (&$b) { $b = $v; }]);
$h = Proxy::wrapSync($m1, $m2);
$h(new Request('GET', 'http://foo.com'), [RequestOptions::SYNCHRONOUS => true]);
$this->assertNull($a);
$this->assertNotNull($b);
}
public function testSendsToStreaming()
{
$a = $b = null;
$m1 = new MockHandler([function ($v) use (&$a) { $a = $v; }]);
$m2 = new MockHandler([function ($v) use (&$b) { $b = $v; }]);
$h = Proxy::wrapStreaming($m1, $m2);
$h(new Request('GET', 'http://foo.com'), []);
$this->assertNotNull($a);
$this->assertNull($b);
}
public function testSendsToNonStreaming()
{
$a = $b = null;
$m1 = new MockHandler([function ($v) use (&$a) { $a = $v; }]);
$m2 = new MockHandler([function ($v) use (&$b) { $b = $v; }]);
$h = Proxy::wrapStreaming($m1, $m2);
$h(new Request('GET', 'http://foo.com'), ['stream' => true]);
$this->assertNull($a);
$this->assertNotNull($b);
}
}