19 public function setUp()
29 $this->assertEquals(4, $caching->getSize());
30 $this->assertEquals(4, $caching->getContentLength());
39 $this->body->setRewindFunction(
true);
48 $this->body->seek(10);
57 $this->body->seek(2, SEEK_END);
62 $size = filesize(__FILE__);
63 $s = fopen(__FILE__,
'r');
64 $this->body->setStream($s, $size);
65 $this->assertEquals($size, $this->body->getSize());
66 $this->assertEquals($size, $this->decorated->getSize());
67 $this->assertSame($s, $this->body->getStream());
68 $this->assertSame($s, $this->decorated->getStream());
74 $d = $this->getMockBuilder(
'Guzzle\Http\CachingEntityBody')
75 ->setMethods(array(
'seek'))
76 ->setConstructorArgs(array($a))
78 $d->expects($this->once())
81 ->will($this->returnValue(
true));
87 $this->assertEquals(
'te', $this->body->read(2));
89 $this->assertEquals(
'test', $this->body->read(4));
90 $this->assertEquals(4, $this->body->ftell());
92 $this->assertEquals(2, $this->body->ftell());
93 $this->body->seek(2, SEEK_CUR);
94 $this->assertEquals(4, $this->body->ftell());
95 $this->assertEquals(
'ing', $this->body->read(3));
100 $this->body->read(2);
101 $this->body->write(
'hi');
102 $this->body->rewind();
103 $this->assertEquals(
'tehiing', (
string) $this->body);
108 $this->body->seek($this->body->ftell());
109 $this->body->write(
"test\n123\nhello\n1234567890\n");
110 $this->body->rewind();
111 $this->assertEquals(
"test\n", $this->body->readLine(7));
112 $this->assertEquals(
"123\n", $this->body->readLine(7));
113 $this->assertEquals(
"hello\n", $this->body->readLine(7));
114 $this->assertEquals(
"123456", $this->body->readLine(7));
115 $this->assertEquals(
"7890\n", $this->body->readLine(7));
117 $this->assertEquals(
'', $this->body->readLine(7));
123 implode(
"\n", array_map(
function ($n) {
124 return str_pad($n, 4,
'0', STR_PAD_LEFT);
130 $this->assertEquals(
"0000\n",
$body->readLine());
131 $this->assertEquals(
"0001\n",
$body->readLine());
133 $this->assertEquals(5,
$body->write(
"TEST\n"));
134 $this->assertEquals(5, $this->readAttribute(
$body,
'skipReadBytes'));
136 $this->assertEquals(
"0003\n",
$body->readLine());
137 $this->assertEquals(0, $this->readAttribute(
$body,
'skipReadBytes'));
138 $this->assertEquals(
"0004\n",
$body->readLine());
139 $this->assertEquals(
"0005\n",
$body->readLine());
143 $this->assertEquals(5,
$body->write(
"ABCD\n"));
144 $this->assertEquals(0, $this->readAttribute(
$body,
'skipReadBytes'));
145 $this->assertEquals(
"TEST\n",
$body->readLine());
146 $this->assertEquals(
"0003\n",
$body->readLine());
147 $this->assertEquals(
"0004\n",
$body->readLine());
148 $this->assertEquals(
"0005\n",
$body->readLine());
149 $this->assertEquals(
"0006\n",
$body->readLine());
150 $this->assertEquals(5,
$body->write(
"1234\n"));
151 $this->assertEquals(5, $this->readAttribute(
$body,
'skipReadBytes'));
155 $this->assertEquals(
"0000\nABCD\nTEST\n0003\n0004\n0005\n0006\n1234\n0008\n0009\n",
$body->read(50));
158 $this->assertContains(
"0000\nABCD\nTEST\n0003\n0004\n0005\n0006\n1234\n0008\n0009\n", (
string)
$body);
163 $a = $this->getMockBuilder(
'Guzzle\Http\EntityBody')
164 ->setMethods(array(
'getContentType'))
165 ->setConstructorArgs(array(fopen(__FILE__,
'r')))
167 $a->expects($this->once())
168 ->method(
'getContentType')
169 ->will($this->returnValue(
'foo'));
171 $this->assertEquals(
'foo', $d->getContentType());
176 $a = $this->getMockBuilder(
'Guzzle\Http\EntityBody')
177 ->setMethods(array(
'getContentEncoding'))
178 ->setConstructorArgs(array(fopen(__FILE__,
'r')))
180 $a->expects($this->once())
181 ->method(
'getContentEncoding')
182 ->will($this->returnValue(
'foo'));
184 $this->assertEquals(
'foo', $d->getContentEncoding());
189 $a = $this->getMockBuilder(
'Guzzle\Http\EntityBody')
190 ->setMethods(array(
'getMetadata',
'getWrapper',
'getWrapperData',
'getStreamType',
'getUri'))
191 ->setConstructorArgs(array(fopen(__FILE__,
'r')))
194 $a->expects($this->once())
195 ->method(
'getMetadata')
196 ->will($this->returnValue(array()));
198 $a->expects($this->exactly(1))
199 ->method(
'getWrapper')
200 ->will($this->returnValue(
'wrapper'));
201 $a->expects($this->once())
202 ->method(
'getWrapperData')
203 ->will($this->returnValue(array()));
204 $a->expects($this->once())
205 ->method(
'getStreamType')
206 ->will($this->returnValue(
'baz'));
207 $a->expects($this->once())
209 ->will($this->returnValue(
'path/to/foo'));
212 $this->assertEquals(array(), $d->getMetaData());
213 $this->assertEquals(
'wrapper', $d->getWrapper());
214 $this->assertEquals(array(), $d->getWrapperData());
215 $this->assertEquals(
'baz', $d->getStreamType());
216 $this->assertEquals(
'path/to/foo', $d->getUri());
221 $a = $this->getMockBuilder(
'Guzzle\Http\EntityBody')
222 ->setMethods(array(
'getCustomData',
'setCustomData'))
223 ->setConstructorArgs(array(fopen(__FILE__,
'r')))
226 $a->expects($this->exactly(1))
227 ->method(
'getCustomData')
229 ->will($this->returnValue(
'bar'));
231 $a->expects($this->exactly(1))
232 ->method(
'setCustomData')
234 ->will($this->returnSelf());
237 $this->assertSame($d, $d->setCustomData(
'foo',
'bar'));
238 $this->assertEquals(
'bar', $d->getCustomData(
'foo'));
243 $s = fopen(
'php://temp',
'r');
247 $this->assertFalse(is_resource($s));