Skip to content

Commit f87f4fa

Browse files
adamwathantaylorotwell
authored andcommitted
[5.4] Add named constructor helpers directly to Testing/File (#18180)
* Add named constructor helpers directly to Testing/File * Fix some doc blocks
1 parent 713a2b6 commit f87f4fa

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/Illuminate/Http/Testing/File.php

+25
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,31 @@ public function __construct($name, $tempFile)
4545
);
4646
}
4747

48+
/**
49+
* Create a new fake file.
50+
*
51+
* @param string $name
52+
* @param int $kilobytes
53+
* @return \Illuminate\Http\Testing\File
54+
*/
55+
public static function create($name, $kilobytes = 0)
56+
{
57+
return (new FileFactory)->create($name, $kilobytes);
58+
}
59+
60+
/**
61+
* Create a new fake image.
62+
*
63+
* @param string $name
64+
* @param int $width
65+
* @param int $height
66+
* @return \Illuminate\Http\Testing\File
67+
*/
68+
public static function image($name, $width = 10, $height = 10)
69+
{
70+
return (new FileFactory)->image($name, $width, $height);
71+
}
72+
4873
/**
4974
* Set the "size" of the file in kilobytes.
5075
*

src/Illuminate/Http/Testing/FileFactory.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class FileFactory
1111
* @param int $kilobytes
1212
* @return \Illuminate\Http\Testing\File
1313
*/
14-
public function create($name, $kilobytes)
14+
public function create($name, $kilobytes = 0)
1515
{
1616
return tap(new File($name, tmpfile()), function ($file) use ($kilobytes) {
1717
$file->sizeToReport = $kilobytes * 1024;
@@ -22,7 +22,7 @@ public function create($name, $kilobytes)
2222
* Create a new fake image.
2323
*
2424
* @param string $name
25-
* @param int $height
25+
* @param int $width
2626
* @param int $height
2727
* @return \Illuminate\Http\Testing\File
2828
*/

0 commit comments

Comments
 (0)