Skip to content

Commit

Permalink
[6.x] Allow to create fake file with content
Browse files Browse the repository at this point in the history
  • Loading branch information
shadoWalker89 committed Nov 18, 2019
1 parent 899b8c3 commit 2cc6fa3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Illuminate/Http/Testing/File.php
Expand Up @@ -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.
*
Expand Down
17 changes: 17 additions & 0 deletions src/Illuminate/Http/Testing/FileFactory.php
Expand Up @@ -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.
*
Expand Down

0 comments on commit 2cc6fa3

Please sign in to comment.