21 protected function setUp()
29 $this->
getServer()->enqueue(
"HTTP/1.1 200 OK\r\nContent-Length: 2\r\n\r\nhi");
30 $request = $this->client->get(
'/');
31 $stream = $this->factory->fromRequest($request);
32 $this->assertEquals(
'hi', (
string) $stream);
33 $headers = $this->factory->getLastResponseHeaders();
34 $this->assertContains(
'HTTP/1.1 200 OK', $headers);
35 $this->assertContains(
'Content-Length: 2', $headers);
36 $this->assertSame($headers, $stream->getCustomData(
'response_headers'));
37 $this->assertEquals(2, $stream->getSize());
42 $request = $this->client->get(
'/');
43 $this->factory = $this->getMockBuilder(
'Guzzle\Stream\PhpStreamRequestFactory')
44 ->setMethods(array(
'createContext',
'createStream'))
46 $this->factory->expects($this->never())
47 ->method(
'createContext');
48 $this->factory->expects($this->once())
49 ->method(
'createStream')
50 ->will($this->returnValue(
new Stream(fopen(
'php://temp',
'r'))));
52 $context = array(
'http' => array(
'method' =>
'HEAD',
'ignore_errors' =>
false));
53 $this->factory->fromRequest($request, stream_context_create($context));
54 $options = stream_context_get_options($this->readAttribute($this->factory,
'context'));
55 $this->assertEquals(
'HEAD', $options[
'http'][
'method']);
56 $this->assertFalse($options[
'http'][
'ignore_errors']);
57 $this->assertEquals(
'1.1', $options[
'http'][
'protocol_version']);
62 $request = $this->client->get(
'/');
63 $request->getCurlOptions()->set(CURLOPT_PROXY,
'tcp://foo.com');
64 $this->factory = $this->getMockBuilder(
'Guzzle\Stream\PhpStreamRequestFactory')
65 ->setMethods(array(
'createStream'))
67 $this->factory->expects($this->once())
68 ->method(
'createStream')
69 ->will($this->returnValue(
new Stream(fopen(
'php://temp',
'r'))));
70 $this->factory->fromRequest($request);
71 $options = stream_context_get_options($this->readAttribute($this->factory,
'context'));
72 $this->assertEquals(
'tcp://foo.com', $options[
'http'][
'proxy']);
78 $this->
getServer()->enqueue(
"HTTP/1.1 200 OK\r\nContent-Length: 2\r\n\r\nhi");
79 $request = $this->client->post(
'/', array(
'Foo' =>
'Bar'), array(
'foo' =>
'baz bar'));
80 $stream = $this->factory->fromRequest($request);
81 $this->assertEquals(
'hi', (
string) $stream);
83 $headers = $this->factory->getLastResponseHeaders();
84 $this->assertContains(
'HTTP/1.1 200 OK', $headers);
85 $this->assertContains(
'Content-Length: 2', $headers);
86 $this->assertSame($headers, $stream->getCustomData(
'response_headers'));
88 $received = $this->
getServer()->getReceivedRequests();
89 $this->assertEquals(1, count($received));
90 $this->assertContains(
'POST / HTTP/1.1', $received[0]);
91 $this->assertContains(
'host: ', $received[0]);
92 $this->assertContains(
'user-agent: Guzzle/', $received[0]);
93 $this->assertContains(
'foo: Bar', $received[0]);
94 $this->assertContains(
'content-length: 13', $received[0]);
95 $this->assertContains(
'foo=baz%20bar', $received[0]);
101 $this->
getServer()->enqueue(
"HTTP/1.1 200 OK\r\nContent-Length: 2\r\n\r\nhi");
102 $request = $this->client->put(
'/', array(
'Foo' =>
'Bar'),
'Testing...123');
103 $stream = $this->factory->fromRequest($request);
104 $this->assertEquals(
'hi', (
string) $stream);
106 $headers = $this->factory->getLastResponseHeaders();
107 $this->assertContains(
'HTTP/1.1 200 OK', $headers);
108 $this->assertContains(
'Content-Length: 2', $headers);
109 $this->assertSame($headers, $stream->getCustomData(
'response_headers'));
111 $received = $this->
getServer()->getReceivedRequests();
112 $this->assertEquals(1, count($received));
113 $this->assertContains(
'PUT / HTTP/1.1', $received[0]);
114 $this->assertContains(
'host: ', $received[0]);
115 $this->assertContains(
'user-agent: Guzzle/', $received[0]);
116 $this->assertContains(
'foo: Bar', $received[0]);
117 $this->assertContains(
'content-length: 13', $received[0]);
118 $this->assertContains(
'Testing...123', $received[0]);
123 $request = $this->client->get(
'/');
124 $request->getCurlOptions()->set(CURLOPT_SSL_VERIFYPEER,
false);
125 $this->factory = $this->getMockBuilder(
'Guzzle\Stream\PhpStreamRequestFactory')
126 ->setMethods(array(
'createStream'))
128 $this->factory->expects($this->once())
129 ->method(
'createStream')
130 ->will($this->returnValue(
new Stream(fopen(
'php://temp',
'r'))));
131 $this->factory->fromRequest($request);
132 $options = stream_context_get_options($this->readAttribute($this->factory,
'context'));
133 $this->assertFalse($options[
'ssl'][
'verify_peer']);
138 $request = $this->client->get(
'/');
139 $this->factory = $this->getMockBuilder(
'Guzzle\Stream\PhpStreamRequestFactory')
140 ->setMethods(array(
'createStream'))
142 $this->factory->expects($this->once())
143 ->method(
'createStream')
144 ->will($this->returnValue(
new Stream(fopen(
'php://temp',
'r'))));
145 $this->factory->fromRequest($request);
146 $options = stream_context_get_options($this->readAttribute($this->factory,
'context'));
147 $this->assertTrue($options[
'ssl'][
'verify_peer']);
148 $this->assertSame($request->getCurlOptions()->get(CURLOPT_CAINFO), $options[
'ssl'][
'cafile']);
153 $request = $this->client->get(
'/');
154 $request->setAuth(
'Foo',
'Bar');
155 $this->factory = $this->getMockBuilder(
'Guzzle\Stream\PhpStreamRequestFactory')
156 ->setMethods(array(
'createStream'))
158 $this->factory->expects($this->once())
159 ->method(
'createStream')
160 ->will($this->returnValue(
new Stream(fopen(
'php://temp',
'r'))));
161 $this->factory->fromRequest($request);
162 $this->assertContains(
'Foo:Bar@', (
string) $this->readAttribute($this->factory,
'url'));
167 $this->
getServer()->enqueue(
"HTTP/1.1 200 OK\r\nContent-Length: 2\r\n\r\nhi");
168 $request = $this->client->get(
'/');
169 $stream = $this->factory->fromRequest($request, array(), array(
'stream_class' =>
'Guzzle\Http\EntityBody'));
170 $this->assertInstanceOf(
'Guzzle\Http\EntityBody', $stream);