Skip to content

Commit db2f897

Browse files
author
Karl Hepler
committed
Initial commit
0 parents  commit db2f897

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/vendor/

composer.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "oldtimeguitarguy/laravel-mocks-file-uploads",
3+
"description": "A simple trait to add to your Laravel tests to mock file uploads",
4+
"license": "MIT",
5+
"authors": [
6+
{
7+
"name": "Karl Hepler",
8+
"email": "khepler@brandmovers.com"
9+
}
10+
],
11+
"minimum-stability": "stable",
12+
"require": {},
13+
"autoload": {
14+
"psr-4": {
15+
"OldTimeGuitarGuy\\Laravel\\": "src/OldTimeGuitarGuy/Laravel/"
16+
}
17+
}
18+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace OldTimeGuitarGuy\Laravel;
4+
5+
use Illuminate\Http\UploadedFile;
6+
7+
trait MocksFileUploads
8+
{
9+
/**
10+
* Get a mocked file upload.
11+
* This would be inserted into request data during a test.
12+
*
13+
* @param string $path
14+
* @return \Illuminate\Http\UploadedFile
15+
*/
16+
public function uploadedFile($path)
17+
{
18+
$this->assertFileExists($path);
19+
20+
$fileInfo = finfo_open(FILEINFO_MIME_TYPE);
21+
$mime = finfo_file($fileInfo, $path);
22+
23+
return new UploadedFile(
24+
$path, null, $mime, null, null, true
25+
);
26+
}
27+
}

0 commit comments

Comments
 (0)