2017-04-05 58 views
1

这是我的测试案例测试情况下删除原始文件,同时通过测试的情况下上传文件

public function testSelfieFileUpload() 
{ 
    $path = public_path().'/uploads/sample1.jpg'; 
    $name = 'sample1.jpg'; 
    $file = new UploadedFile($path, $name, 'image/png', filesize($path), null, true); 
    $response = $this->post($this->endpoint, ['file' => $file], $this->setHeaders()); 
    $response->assertStatus(200) 
     ->assertJsonFragment(array("status" => "success")); 
} 

但问题是,它是从删除的文件夹,即sample1.jpg

帮助原始文件我出去了。我在这里错过了什么吗?虽然测试用例运行良好。

+0

您是否对这些文件使用** unset **? –

+0

什么是未设置..?如果你的意思是删除。那么我不明确这样做 – Dherya

+0

如果你想删除存储的文件,然后你必须使用PHP未设置功能删除它 –

回答

0

当遇到同样的问题时,在查看源代码后,我找不到修复它的标志。

由于我的解决方法是,我在运行测试时创建了一个副本,该副本被删除但不再是问题。

$temporaryFilePath = $this->createTempFile($this->testFilePath); 
$file = new \Illuminate\Http\UploadedFile($path, $name, $mime, filesize($path), null, true); 
//do your test logic 

... 

private function createTempFile($path) { 

    $tempFilePath = $this->basePath . 'temp.xlsx'; 
    copy($path, $tempFilePath); 

    return $tempFilePath; 
} 

您可能需要根据自己的需要进行优化。

相关问题