我开发了一个功能来下载基于数据库生成的 CSV 文件。我已经为此创建了测试并且对我来说工作正常。但问题是在完成测试运行后文件没有被删除。
问题。一旦测试完全运行,这个使用 storage fake 创建的文件会被自动删除吗?如果是,它不会为我删除。请查看我的测试功能。
/*Test file*/
public function testAmazonDailyPendingStatusReport(){
//creating factories
Storage::fake('reportslocal');
$dailyStatus = new DailyStatus(
new FileWriter(),
new Filesystem(),
Storage::disk('reportslocal')
);
$fileExported = $dailyStatus->export();
//continuing assertions
}
/*export function*/
public function export(){
//fetch data from database.
//create file using SplFileObject
//writing files into it.
//storing to 'reportslocal' path
//sending email to client with attached this file
}
Run Code Online (Sandbox Code Playgroud)
如果文件没有自动删除,我该怎么办?或者我可以Storage::disk('reportslocal')->delete($fileExported)在我的测试功能中使用。这是正确的方法吗?
这里要检查的最佳断言是什么?我已经检查过文件存在、列号、列标题序列和值,检查文件的内容。有什么我错过的吗?
请帮我做到这一点(优先是 storage::fake() 问题。)。
提前致谢。