diff --git a/tests/S3/StreamWrapperTest.php b/tests/S3/StreamWrapperTest.php index bd0ab9cac4..23f53eaf4b 100644 --- a/tests/S3/StreamWrapperTest.php +++ b/tests/S3/StreamWrapperTest.php @@ -170,6 +170,25 @@ public function testCanOpenWriteOnlyStreams() $this->assertEquals('test', (string) $cmd['Body']); } + public function testCanWriteEmptyFileToStream() + { + $history = new History(); + $this->client->getHandlerList()->appendSign(Middleware::history($history)); + $this->addMockResults($this->client, [new Result()]); + $s = fopen('s3://bucket/key', 'w'); + $this->assertEquals(0, fwrite($s, '')); + $this->assertTrue(fclose($s)); + + // Ensure that the stream was flushed even with zero characters, and + // that it only executed PutObject once. + $this->assertCount(1, $history); + $cmd = $history->getLastCommand(); + $this->assertEquals('PutObject', $cmd->getName()); + $this->assertEquals('bucket', $cmd['Bucket']); + $this->assertEquals('key', $cmd['Key']); + $this->assertEquals('', (string) $cmd['Body']); + } + /** * @expectedException \PHPUnit\Framework\Error\Warning * @expectedExceptionMessage 403 Forbidden