Laravel 如何正确设置文件post PhpUnit

Laravel 如何正确设置文件post PhpUnit,laravel,unit-testing,phpunit,laravel-5.5,Laravel,Unit Testing,Phpunit,Laravel 5.5,我正在尝试设置上载文件的测试。 在控制器中,我需要通过表单验证检查是否一切正常 问题是响应给了我一个错误$request->dataFile->getClientOriginalExtension,vendor/symfony/httpfoundation/File/UploadedFile.php 看起来像是数据文件、请求或。。。。我不知道如何设置它 /** @test @group formPostFile */ public function formP

我正在尝试设置上载文件的测试。 在控制器中,我需要通过表单验证检查是否一切正常

问题是响应给了我一个错误$request->dataFile->getClientOriginalExtension,vendor/symfony/httpfoundation/File/UploadedFile.php

看起来像是数据文件、请求或。。。。我不知道如何设置它

/** 
        @test 
        @group formPostFile
*/
public function formPostFile()
{
    $test_file_path  = base_path().'/httpdocs/test/Excel.xlsx';
    $this->assertTrue(file_exists($test_file_path), $test_file_path.' Test file does not exist');
    $_FILE = [
        'filename' => [
            'name'     => $test_file_path,
            'type'     => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
            'size'     => 10336,
            'tmp_name' => $test_file_path,
            'error'    => 0
        ]
    ];
    $data = [
        'id' => '2',
        'dataFile' => $_FILE
    ];
    $response = $this->post('/excel', $data);
    dd($response->getContent());

}
使用Symfony/Lightning类上载文件

$file = new UploadedFile(
    $test_file_path, 
    $test_file_path,
    filesize($test_file_path),
    'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
    null,
    true
);
LastParameter是testMode,应该是true,我相信这会在您的代码中实现,以类似于您已经拥有的数组的方式使用它

$data = [
    'id' => '2',
    'dataFile' => $file
];