Commit b251eb26 authored by Jeremy Mikola's avatar Jeremy Mikola

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().
parent e681f91e
...@@ -174,6 +174,7 @@ class BucketFunctionalTest extends FunctionalTestCase ...@@ -174,6 +174,7 @@ class BucketFunctionalTest extends FunctionalTestCase
$id = $this->bucket->uploadFromStream('filename', $this->createStream($input)); $id = $this->bucket->uploadFromStream('filename', $this->createStream($input));
$destination = $this->createStream(); $destination = $this->createStream();
$this->bucket->downloadToStream($id, $destination); $this->bucket->downloadToStream($id, $destination);
rewind($destination);
$this->assertStreamContents($input, $destination); $this->assertStreamContents($input, $destination);
} }
...@@ -208,30 +209,37 @@ class BucketFunctionalTest extends FunctionalTestCase ...@@ -208,30 +209,37 @@ class BucketFunctionalTest extends FunctionalTestCase
$destination = $this->createStream(); $destination = $this->createStream();
$this->bucket->downloadToStreamByName('filename', $destination); $this->bucket->downloadToStreamByName('filename', $destination);
rewind($destination);
$this->assertStreamContents('baz', $destination); $this->assertStreamContents('baz', $destination);
$destination = $this->createStream(); $destination = $this->createStream();
$this->bucket->downloadToStreamByName('filename', $destination, ['revision' => -3]); $this->bucket->downloadToStreamByName('filename', $destination, ['revision' => -3]);
rewind($destination);
$this->assertStreamContents('foo', $destination); $this->assertStreamContents('foo', $destination);
$destination = $this->createStream(); $destination = $this->createStream();
$this->bucket->downloadToStreamByName('filename', $destination, ['revision' => -2]); $this->bucket->downloadToStreamByName('filename', $destination, ['revision' => -2]);
rewind($destination);
$this->assertStreamContents('bar', $destination); $this->assertStreamContents('bar', $destination);
$destination = $this->createStream(); $destination = $this->createStream();
$this->bucket->downloadToStreamByName('filename', $destination, ['revision' => -1]); $this->bucket->downloadToStreamByName('filename', $destination, ['revision' => -1]);
rewind($destination);
$this->assertStreamContents('baz', $destination); $this->assertStreamContents('baz', $destination);
$destination = $this->createStream(); $destination = $this->createStream();
$this->bucket->downloadToStreamByName('filename', $destination, ['revision' => 0]); $this->bucket->downloadToStreamByName('filename', $destination, ['revision' => 0]);
rewind($destination);
$this->assertStreamContents('foo', $destination); $this->assertStreamContents('foo', $destination);
$destination = $this->createStream(); $destination = $this->createStream();
$this->bucket->downloadToStreamByName('filename', $destination, ['revision' => 1]); $this->bucket->downloadToStreamByName('filename', $destination, ['revision' => 1]);
rewind($destination);
$this->assertStreamContents('bar', $destination); $this->assertStreamContents('bar', $destination);
$destination = $this->createStream(); $destination = $this->createStream();
$this->bucket->downloadToStreamByName('filename', $destination, ['revision' => 2]); $this->bucket->downloadToStreamByName('filename', $destination, ['revision' => 2]);
rewind($destination);
$this->assertStreamContents('baz', $destination); $this->assertStreamContents('baz', $destination);
} }
......
...@@ -38,7 +38,7 @@ abstract class FunctionalTestCase extends BaseFunctionalTestCase ...@@ -38,7 +38,7 @@ abstract class FunctionalTestCase extends BaseFunctionalTestCase
{ {
$this->assertInternalType('resource', $stream); $this->assertInternalType('resource', $stream);
$this->assertSame('stream', get_resource_type($stream)); $this->assertSame('stream', get_resource_type($stream));
$this->assertEquals($expectedContents, stream_get_contents($stream, -1, 0)); $this->assertEquals($expectedContents, stream_get_contents($stream));
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment