From de1875a55003b5ac70ed512f8a248d4df2a8c3fd Mon Sep 17 00:00:00 2001 From: Ashley Broadley Date: Tue, 12 Aug 2014 14:25:56 +0100 Subject: [PATCH 1/2] Added a rewind to write to reset the file pointer --- src/Filesystem/File.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Filesystem/File.php b/src/Filesystem/File.php index 5e10203..b810ba0 100644 --- a/src/Filesystem/File.php +++ b/src/Filesystem/File.php @@ -32,6 +32,7 @@ public function write($data) } $this->ftruncate(0); + $this->rewind(); $this->fwrite($data); return $this; } From eac81d9f713375db9011f9744fca1b4081ef7c00 Mon Sep 17 00:00:00 2001 From: Ashley Broadley Date: Tue, 12 Aug 2014 14:29:31 +0100 Subject: [PATCH 2/2] Fixed writing test. Added test for new file. --- spec/Task/Plugin/Filesystem/FileSpec.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/spec/Task/Plugin/Filesystem/FileSpec.php b/spec/Task/Plugin/Filesystem/FileSpec.php index 3d37173..b87b35a 100644 --- a/spec/Task/Plugin/Filesystem/FileSpec.php +++ b/spec/Task/Plugin/Filesystem/FileSpec.php @@ -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()