Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vidhyaprakash85's avatar

laravel excel import and sending email

I have laravel excel import test case. In that i am importing an excel file after all import i am firing the email. Here is the test code but i am getting failure notice. Kindly help me.

test('superadmin can upload correct file for teacher upload', function () {
    $this->withoutExceptionHandling();
    $branches = Branch::select('id', 'name')->get();
    $response = $this->get(route('user.create'));
    $response->assertSee("Teacher User Import");
    Excel::fake();
    Storage::fake();
    Mail::fake();
    $data = [
        'teacherbranch' => $branches->first()->id,
        'teacherimportfile' => UploadedFile::fake()->create(
            base_path('tests/Files/teacher-correct-file.xlsx')),
        "submit" => 'TeacherImport',
    ];
    $response = $this->post(route('user.store'), $data);
    $response->assertStatus(302);
    $response->assertRedirect(route('user.index'));
    Mail::assertQueued(TeacherImportCompletedMail::class, function ($mail) {
        return $mail->hasTo('[email protected]');
    });
    $expectedCount = 2;
    $actualCount = User::count();
    expect($actualCount)->toBe($expectedCount);
});

and the error is

• Tests\Feature\SuperAdmin\UserTest > superadmin can upload correct file for teacher upload
  The expected [App\Mail\SuperAdmin\Imports\TeacherImportCompletedMail] mailable was not queued.
  Failed asserting that false is true.
0 likes
2 replies
rvdiwas's avatar

can you share how the data is being processed and where the mail has been queued ?

Please or to participate in this conversation.