Jul 24, 2017
0
Level 8
How to test file download using maatwebsite/excel
I am using maatwebsite/excel to return an excel file. This works fine but I want to be able to test this using phpunit.
I have a controller method which returns the excel file.
public function usersAll(){
$users = User::all();
return Excel::create('users', function($excel) use ($users) {
$excel->sheet('Users', function($sheet) use ($users) {
$sheet->loadView('csv.users')->with('users', $users);
});
})->export('xls');
}
I want to use phpunit to hit a route and assert that the response is ok. Something like this:
/** @test */
public function test_csv()
{
$response = $this->call('GET','/csv/users/all');
$this->assertResponseOk();
}
What is the best way to test this, I receive error that headers are already sent. I have been digging around google for a solution but cant find anything to solve this.
Does anybody else test for this using this package? I would love to know the best way forward.
Thanks.
Please or to participate in this conversation.