Skip to content

Commit

Permalink
allow string content on fake file creation
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Nov 19, 2019
1 parent f2a67ed commit 181db51
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Illuminate/Http/Testing/File.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function __construct($name, $tempFile)
* Create a new fake file. * Create a new fake file.
* *
* @param string $name * @param string $name
* @param int $kilobytes * @param string|int $kilobytes
* @return \Illuminate\Http\Testing\File * @return \Illuminate\Http\Testing\File
*/ */
public static function create($name, $kilobytes = 0) public static function create($name, $kilobytes = 0)
Expand Down
12 changes: 9 additions & 3 deletions src/Illuminate/Http/Testing/FileFactory.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -10,13 +10,19 @@ class FileFactory
* Create a new fake file. * Create a new fake file.
* *
* @param string $name * @param string $name
* @param int $kilobytes * @param string|int $kilobytes
* @return \Illuminate\Http\Testing\File * @return \Illuminate\Http\Testing\File
*/ */
public function create($name, $kilobytes = 0) public function create($name, $kilobytes = 0)
{ {
return tap(new File($name, tmpfile()), function ($file) use ($kilobytes) { $tmp = tmpfile();
$file->sizeToReport = $kilobytes * 1024;
if (is_string($kilobytes)) {
file_put_contents($tmp, $kilobytes);
}

return tap(new File($name, $tmp), function ($file) use ($kilobytes) {
$file->sizeToReport = is_string($kilobytes) ? fstat($tmp)['size'] : ($kilobytes * 1024);
}); });
} }


Expand Down

0 comments on commit 181db51

Please sign in to comment.