Skip to content

Commit

Permalink
Merge pull request #1 from ls12styler/master
Browse files Browse the repository at this point in the history
`rewind` `File` pointer before writing data
  • Loading branch information
mbfisher committed Aug 12, 2014
2 parents 5afc74d + eac81d9 commit 44c62c8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
16 changes: 13 additions & 3 deletions spec/Task/Plugin/Filesystem/FileSpec.php
Expand Up @@ -53,15 +53,25 @@ function it_should_write_content()
expect(file_get_contents($this->path))->toBe('foo');
}

function it_should_write_file_content()
function it_should_write_new_file_content()
{
$src = vfsStream::url('tmp').'/src';

$src = new File($src);
$this->write('bar');

$this->read()->shouldReturn('bar');
}

function it_should_overwrite_file_content()
{
$src = vfsStream::url('tmp').'/src';
file_put_contents($src, 'foo');

$src = new File($src);
$this->write($src);
$this->write('bar');

$this->read()->shouldReturn('foo');
$this->read()->shouldReturn('bar');
}

function it_should_append_content()
Expand Down
1 change: 1 addition & 0 deletions src/Filesystem/File.php
Expand Up @@ -32,6 +32,7 @@ public function write($data)
}

$this->ftruncate(0);
$this->rewind();
$this->fwrite($data);
return $this;
}
Expand Down

0 comments on commit 44c62c8

Please sign in to comment.