Mar 17, 2017
0
Level 33
Testing file uploads
Hi,
Recently this has been added to Laravel:
https://laravel.com/docs/5.4/http-tests#testing-file-uploads
But when I try this I keep getting a phpunit error:
Segmentation fault: 11
My test looks like this:
$user = factory(User::class)->create([
'email' => '[email protected]',
'active' => 2
]);
factory(Forum::class)->create();
$response = $this->actingAs($user, 'api')->json('POST', '/api/message', [
'forum_id' => 1,
'subject' => 'test',
'message' => 'test,',
'attachment[0]' => UploadedFile::fake()->image('avatar.jpg')
]);
$response->assertStatus(200);
I'm storing files like this:
if($request->hasFile('attachment')) {
foreach($request->file('attachment') as $file) {
$this->addMedia($file)
->setName($file->getClientOriginalName())
->toMediaLibrary();
}
}
What could be wrong here? When I remove this line:
'attachment[0]' => UploadedFile::fake()->image('avatar.jpg')
The test returns green.
Please or to participate in this conversation.