Skip to content

Commit b251eb2

Browse files
committed
Explicitly rewind in-memory streams before asserting contents
GridFS streams do not yet support seeking (PHPLIB-213), and HHVM requires a stream_seek() implementation in order to pass a non-negative offset to stream_get_contents().
1 parent e681f91 commit b251eb2

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

tests/GridFS/BucketFunctionalTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ public function testDownloadToStream($input)
174174
$id = $this->bucket->uploadFromStream('filename', $this->createStream($input));
175175
$destination = $this->createStream();
176176
$this->bucket->downloadToStream($id, $destination);
177+
rewind($destination);
177178

178179
$this->assertStreamContents($input, $destination);
179180
}
@@ -208,30 +209,37 @@ public function testDownloadToStreamByName()
208209

209210
$destination = $this->createStream();
210211
$this->bucket->downloadToStreamByName('filename', $destination);
212+
rewind($destination);
211213
$this->assertStreamContents('baz', $destination);
212214

213215
$destination = $this->createStream();
214216
$this->bucket->downloadToStreamByName('filename', $destination, ['revision' => -3]);
217+
rewind($destination);
215218
$this->assertStreamContents('foo', $destination);
216219

217220
$destination = $this->createStream();
218221
$this->bucket->downloadToStreamByName('filename', $destination, ['revision' => -2]);
222+
rewind($destination);
219223
$this->assertStreamContents('bar', $destination);
220224

221225
$destination = $this->createStream();
222226
$this->bucket->downloadToStreamByName('filename', $destination, ['revision' => -1]);
227+
rewind($destination);
223228
$this->assertStreamContents('baz', $destination);
224229

225230
$destination = $this->createStream();
226231
$this->bucket->downloadToStreamByName('filename', $destination, ['revision' => 0]);
232+
rewind($destination);
227233
$this->assertStreamContents('foo', $destination);
228234

229235
$destination = $this->createStream();
230236
$this->bucket->downloadToStreamByName('filename', $destination, ['revision' => 1]);
237+
rewind($destination);
231238
$this->assertStreamContents('bar', $destination);
232239

233240
$destination = $this->createStream();
234241
$this->bucket->downloadToStreamByName('filename', $destination, ['revision' => 2]);
242+
rewind($destination);
235243
$this->assertStreamContents('baz', $destination);
236244
}
237245

tests/GridFS/FunctionalTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ protected function assertStreamContents($expectedContents, $stream)
3838
{
3939
$this->assertInternalType('resource', $stream);
4040
$this->assertSame('stream', get_resource_type($stream));
41-
$this->assertEquals($expectedContents, stream_get_contents($stream, -1, 0));
41+
$this->assertEquals($expectedContents, stream_get_contents($stream));
4242
}
4343

4444
/**

0 commit comments

Comments
 (0)