2016-03-24 2 views
1

Ich habe gerade von Laravel 5.1 auf 5.2 aktualisiert und zuvor erfolgreiche Tests sind jetzt fehlgeschlagen, mit "Vielleicht wurde eine Ausnahme geworfen?"Laravel 5.2 Mocked-Datei-Upload-Unit-Test schlägt fehl

There were 3 failures: 

1) TRP\Nps\Tests\FileHandlerControllerTest::testCSVFileUploadImportsRecipients 
Invalid JSON was returned from the route. Perhaps an exception was thrown? 

/home/vagrant/Code/nps/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php:354 
/home/vagrant/Code/nps/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php:316 
/home/vagrant/Code/nps/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php:255 
/home/vagrant/Code/nps/tests/FileHandlerControllerTest.php:56 

die tatsächliche Antwort des Testprotokollierung selbst sehe ich folgendes:

UploadedFile.php Linie 235: Die Datei "FileHandlerCSV.csv"; wurde aufgrund eines unbekannten Fehlers nicht hochgeladen.

Das ist nicht sehr hilfreich. Meine mockFileUpload Methode ist wie folgt:

/** 
* Mock a file upload 
*/ 
public function mockFileUpload($fullPathToFile, $type = null, $errorCode = 0) 
{ 
    $fs = new Filesystem(); 

    // Copy the "upload" to a temp file 
    $tmpFile = tempnam(sys_get_temp_dir(), "testupload"); 
    $fs->copy($fullPathToFile, $tmpFile); 

    // If we haven't been given it, find the Mime type of a file 
    if (!$type) { 
     $type = $fs->mimeType($fullPathToFile); 
    } 

    return new UploadedFile(
     $tmpFile, 
     $fs->name($fullPathToFile) . '.' . $fs->extension($fullPathToFile), 
     $type, 
     $fs->size($tmpFile), 
     $errorCode, 
     true // $test 
    ); 
} 

Und Symphony-Methode, die den Fehler zurückgibt (auch nicht hilfreich ...)

/** 
* Returns an informative upload error message. 
* 
* @return string The error message regarding the specified error code 
*/ 
public function getErrorMessage() 
{ 
    static $errors = array(
     UPLOAD_ERR_INI_SIZE => 'The file "%s" exceeds your upload_max_filesize ini directive (limit is %d KiB).', 
     UPLOAD_ERR_FORM_SIZE => 'The file "%s" exceeds the upload limit defined in your form.', 
     UPLOAD_ERR_PARTIAL => 'The file "%s" was only partially uploaded.', 
     UPLOAD_ERR_NO_FILE => 'No file was uploaded.', 
     UPLOAD_ERR_CANT_WRITE => 'The file "%s" could not be written on disk.', 
     UPLOAD_ERR_NO_TMP_DIR => 'File could not be uploaded: missing temporary directory.', 
     UPLOAD_ERR_EXTENSION => 'File upload was stopped by a PHP extension.', 
    ); 

    $errorCode = $this->error; 
    $maxFilesize = $errorCode === UPLOAD_ERR_INI_SIZE ? self::getMaxFilesize()/1024 : 0; 
    $message = isset($errors[$errorCode]) ? $errors[$errorCode] : 'The file "%s" was not uploaded due to an unknown error.'; 

    return sprintf($message, $this->getClientOriginalName(), $maxFilesize); 
} 

Ich habe bestätigt, dass die Datei in ist/tmp/

-rw------- 1 vagrant vagrant 88 Mar 24 08:53 testuploadA4K2MA 

Und ich habe überprüft, es ist sowohl lesen/schreiben aktiviert. Was es ist. Ich bin völlig verwirrt, warum phpunit versagt? Hat jemand schon mal so etwas gesehen? Vielleicht, bitte! :)

Antwort