Commit ddd2c3e2 authored by Jeremy Mikola's avatar Jeremy Mikola

PHPLIB-251: WriteableStream::getSize() should include buffer length

parent bc98d9cc
......@@ -158,7 +158,7 @@ class WritableStream
*/
public function getSize()
{
return $this->length;
return $this->length + strlen($this->buffer);
}
/**
......
......@@ -56,6 +56,8 @@ class StreamWrapperFunctionalTest extends FunctionalTestCase
$stat = fstat($stream);
$this->assertSame(0100444, $stat[2]);
$this->assertSame(0100444, $stat['mode']);
$this->assertSame(10, $stat[7]);
$this->assertSame(10, $stat['size']);
}
public function testReadableStreamWrite()
......@@ -100,6 +102,14 @@ class StreamWrapperFunctionalTest extends FunctionalTestCase
$stat = fstat($stream);
$this->assertSame(0100222, $stat[2]);
$this->assertSame(0100222, $stat['mode']);
$this->assertSame(0, $stat[7]);
$this->assertSame(0, $stat['size']);
$this->assertSame(6, fwrite($stream, 'foobar'));
$stat = fstat($stream);
$this->assertSame(6, $stat[7]);
$this->assertSame(6, $stat['size']);
}
public function testWritableStreamWrite()
......
......@@ -61,6 +61,22 @@ class WritableStreamFunctionalTest extends FunctionalTestCase
new WritableStream($this->collectionWrapper, 'filename', ['chunkSizeBytes' => 0]);
}
public function testWriteBytesAlwaysUpdatesFileSize()
{
$stream = new WritableStream($this->collectionWrapper, 'filename', ['chunkSizeBytes' => 1024]);
$this->assertSame(0, $stream->getSize());
$this->assertSame(512, $stream->writeBytes(str_repeat('a', 512)));
$this->assertSame(512, $stream->getSize());
$this->assertSame(512, $stream->writeBytes(str_repeat('a', 512)));
$this->assertSame(1024, $stream->getSize());
$this->assertSame(512, $stream->writeBytes(str_repeat('a', 512)));
$this->assertSame(1536, $stream->getSize());
$stream->close();
$this->assertSame(1536, $stream->getSize());
}
/**
* @dataProvider provideInputDataAndExpectedMD5
*/
......
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