Skip to content

Commit

Permalink
Add test for empty file write using stream wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
howardlopez committed Mar 6, 2019
1 parent c33009a commit 6267c24
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/S3/StreamWrapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6267c24

Please sign in to comment.