Browse Source

Fix dumping empty content to file.

ADmad 6 years ago
parent
commit
63ee8e2703
2 changed files with 6 additions and 2 deletions
  1. 2 2
      src/Filesystem/Filesystem.php
  2. 4 0
      tests/TestCase/Filesystem/FilesystemTest.php

+ 2 - 2
src/Filesystem/Filesystem.php

@@ -143,8 +143,8 @@ class Filesystem
             $success = @file_put_contents($filename, $content, LOCK_EX);
         }
 
-        if (!$success) {
-            throw new Exception(sprintf('Failed dumping content to file "%s"', $dir));
+        if ($success === false) {
+            throw new Exception(sprintf('Failed dumping content to file `%s`', $dir));
         }
 
         if (!$exists) {

+ 4 - 0
tests/TestCase/Filesystem/FilesystemTest.php

@@ -69,6 +69,10 @@ class FilesystemTest extends TestCase
 
         $this->fs->dumpFile($path, 'bar');
         $this->assertEquals(file_get_contents($path), 'bar');
+
+        $path = $this->vfsPath . DS . 'empty.txt';
+        $this->fs->dumpFile($path, '');
+        $this->assertSame(file_get_contents($path), '');
     }
 
     /**