lundi 25 septembre 2017

Testing file upload in lumen 5.5

I'm using Lumen 5.5, and I wrote simple app that upload files.

I wrote test like this (following this tutorial)

<?php

class UploadImageTest extends TestCase
{

    Use DatabaseMigrations;

    public function testUploadingImageSuccessfully()
    {
        $this->json('POST', '/images', [
            'image' => UploadedFile::fake()->image('image.jpg')
        ])->assertResponseOk()
    }

}

problem is that in my controller, $request->file('image') returns null.

<?php

use Illuminate\Http\Request;

class UploadController extends Controller
{

    public function upload(Request $request)
    {
        if ($request->file('image')) { // always return null
            return "File is uploaded!";
        }

        return "File is not uploaded!";
    }

}

I checked other questions (like this one) and tried given solutions with no luck!

Aucun commentaire:

Enregistrer un commentaire