0

Background: I have created a test class, which worked fine in laravel 5.1; but doesn't in laravel 5.2. This is because the "test" parameter for the file is lost.

I use a code below to create file request:

$this->dataFile = new \Symfony\Component\HttpFoundation\File\UploadedFile(
    base_path('tests/files/datafiles/A.csv'), 'A.csv', 'text/csv', 13071, null, true
);

and I send it using $this->call()

$this->call('POST', '/uploadFile?token=' . $this->token, $params, [], ['file' => [$this->dataFile]], []);

The problem that I am having is that on receiving end the "test" parameters comes through us being false:

[0] => Illuminate\Http\UploadedFile Object
        (
            [test:Symfony\Component\HttpFoundation\File\UploadedFile:private] =>
            [originalName:Symfony\Component\HttpFoundation\File\UploadedFile:private] => A.csv
            [mimeType:Symfony\Component\HttpFoundation\File\UploadedFile:private] => text/csv
            [size:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 13071
            [error:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 0
            [pathName:SplFileInfo:private] => D:\tests/files/datafiles/A.csv
            [fileName:SplFileInfo:private] => A.csv
        )
Vlad Vladimir Hercules
  • 1,781
  • 2
  • 20
  • 37

1 Answers1

1

You should use:

\Illuminate\Http\UploadedFile

To create the uploaded file instead of:

\Symfony\Component\HttpFoundation\File\UploadedFile

See this answer for more details: https://stackoverflow.com/a/37306881/1835484

Björn
  • 5,696
  • 1
  • 24
  • 34