我正在使用以下包:https ://github.com/Maatwebsite/Laravel-Excel版本 2 和 Laravel 版本 5.1
我有以下代码的控制器方法:
....
return Excel::create('List', function($excel) use ($list)
{
$excel->sheet('List', function($sheet) use ($list)
{
$sheet->fromModel($list);
});
})
->download('csv');
和这样的简单测试:
$this->call('GET', 'route/to/csv', [
'param' => 'value',
]);
$this->dump();
上面这行包的测试输出[ERROR]: Headers already sent
。
控制器方法工作正常,但无法测试。
我尝试使用参数运行 phpunit --stderr
。在这种情况下,不会引发错误,但它只是将 CSV 文件的输出转储到控制台并退出。我还尝试使用@runInSeparateProcess
注释运行测试并得到如下错误:
PHPUnit_Framework_Exception: PHP Notice: Constant LARAVEL_START already defined in bootstrap/autoload.php on line 3
....
PHP Fatal error: Uncaught exception 'ReflectionException' with message 'Class env does not exist' in vendor/laravel/framework/src/Illuminate/Container/Container.php:736
这可能是 Laravel-Excel 包中的错误还是我测试错了?