Skip to content

Commit

Permalink
Merge pull request #91 from aaa2000/wrong-json-stored-in-casette
Browse files Browse the repository at this point in the history
Correction of JSON when the file already exists and is blank
  • Loading branch information
adri committed Jan 11, 2015
2 parents 0f186ba + 8d9a993 commit b145def
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/VCR/Storage/AbstractStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function __construct($cassettePath, $cassetteName, $defaultContent = '[]'
{
$file = $cassettePath . DIRECTORY_SEPARATOR . $cassetteName;

if (!file_exists($file)) {
if (!file_exists($file) || 0 === filesize($file)) {
file_put_contents($file, $defaultContent);

$this->isNew = true;
Expand Down
15 changes: 15 additions & 0 deletions tests/VCR/Storage/JsonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,21 @@ public function testValidJson()

}

public function testStoreRecordingWhenBlankFileAlreadyExists()
{
vfsStream::create(array('blank_file_test' => ''));
$filePath = vfsStream::url('test/') . 'blank_file_test';

$jsonObject = new Json(vfsStream::url('test/'), 'blank_file_test');
$stored = array(
'request' => 'some request',
'response' => 'some response'
);
$jsonObject->storeRecording($stored);

$this->assertJson(file_get_contents($filePath));
}

private function iterateAndTest($json, $expected, $message)
{
file_put_contents($this->filePath, $json);
Expand Down

0 comments on commit b145def

Please sign in to comment.