2

I tried this:

public function test_import_cards_job_created()
{
    Excel::fake();

    $file = new UploadedFile(
        base_path('tests/data/import/test_file.csv'),
        'test_file.csv',
        'text/csv',
        null,
        true
    );

    $this->actingAs(User::first())
        ->post('/api/import', [
            'csvFile' => $file
        ]);

    Excel::assertQueued('test_file.csv');
}

But the test fails saying, test_file.csv is not queued for export on disk default

So, how to write Laravel Excel Import test with custom file?

user3563059
  • 320
  • 7
  • 19

1 Answers1

0

You're not pointing to the explicit filePath in Excel::assertQueued('test_file.csv');. What you need to do, like what you're doing in new UploadFile is use the base_path in Excel::assertQueued.

For example:

Excel::assertQueued(base_path('tests/data/import/test_file.csv'), function(UsersImport $import) {
    dd($import);
});

This should work.

Richard Skinner
  • 738
  • 3
  • 10
  • 26