Ich möchte einige Unit-Tests mit Datei-Upload auf Laravel 5.2 tun.Wie Unit Testing + Code-Coverage mit Datei-Upload in Laravel 5.2
Hier ist, wie ich es auf diese answer beziehen sich:
/** app/Http/routes.php **/
Route::post('upload', function() {
$fileExists = false;
if ($_FILES['images']) {
$fileExists = true;
}
return ['result' => $fileExists];
});
/** tests/ExampleTest.php **/
public function testUploadFile()
{
$file = new \Symfony\Component\HttpFoundation\File\UploadedFile(
base_path() . '/tests/files/profile.png', 'profile.png');
$response = $this->call('POST', 'upload',
[
'firstname' => 'firstname',
'lastname' => 'lastname',
'promotion' => '2016',
'isCoop' => 1
],
[
'images' => [$file]
]
);
}
Aber, wenn ich überprüfen Sie die Code-Coverage-Ergebnis, die Linie innerhalb des if-Anweisung auf routes.php Datei wird nicht wie unten gezeigt ausgeführt.
Es scheint, die hochgeladenen Datei nicht in $_FILES
Variable eingesetzt ist, so dass er als leer erkannt.
Irgendeine Idee, wie man es repariert ..? Vielen Dank.
Hinweise: Ich habe Larave für einen API-Dienst erstellen, so dass ich nicht verwendete Form der Datei
Mögliches Duplikat von [Laravel 5.2 Mocked File Upload Unit Test schlägt fehl] (http://stackoverflow.com/questions/36196500/laravel-5-2-mocked-file-upload-unit-test-fails) – staskus