diff --git a/src/Illuminate/Http/Testing/File.php b/src/Illuminate/Http/Testing/File.php index 4b1140c769c3..be343ef9b955 100644 --- a/src/Illuminate/Http/Testing/File.php +++ b/src/Illuminate/Http/Testing/File.php @@ -57,6 +57,18 @@ public static function create($name, $kilobytes = 0) return (new FileFactory)->create($name, $kilobytes); } + /** + * Create a new fake file with content. + * + * @param string $name + * @param string $content + * @return \Illuminate\Http\Testing\File + */ + public static function createWithContent($name, $content) + { + return (new FileFactory)->createWithContent($name, $content); + } + /** * Create a new fake image. * diff --git a/src/Illuminate/Http/Testing/FileFactory.php b/src/Illuminate/Http/Testing/FileFactory.php index c79617ebf5d8..ad2354b581a8 100644 --- a/src/Illuminate/Http/Testing/FileFactory.php +++ b/src/Illuminate/Http/Testing/FileFactory.php @@ -20,6 +20,23 @@ public function create($name, $kilobytes = 0) }); } + /** + * Create a new fake file with content. + * + * @param string $name + * @param string $content + * @return \Illuminate\Http\Testing\File + */ + public function createWithContent($name, $content) + { + $tmpfile = tmpfile(); + fwrite($tmpfile, $content); + + return tap(new File($name, $tmpfile), function ($file) use ($tmpfile) { + $file->sizeToReport = fstat($tmpfile)['size']; + }); + } + /** * Create a new fake image. *