lundi 10 juillet 2017

Laravel 5.4 using Mail fake with Mail::queue, Mail::assertSent not working

I am writing unit test for a code that sends email with Mail::queue function.

Test Function:

/** @test */
     public function send_reminder()
     {
          Mail::fake();

          $deliverable = Deliverable::first();
          $approver = Approver::first();

          $input       = [
               'deliverable_ID' => $deliverable->id,
               'subject'        => "Sample Reminder Subject",
               'message'        => "Sample Reminder Message",
          ];

          $response = $this->actingAs($this->existing_account)->json('POST', '/timeline-send-reminder', $input);

          $response->assertStatus(302);


          Mail::assertSent(ClientEmail::class, function ($mail) use ($approver) {
               return $mail->approver === $approver->id;
          });

     }

Code I'm trying to test:

Mail::to($approver->email, $approver->name)
                          ->queue(new ClientEmail(Auth::user(), $approver, $input['subject'], $input['message'], $list));

The email is sent when I manually test it.

I get the following error message:

1) TimelineTest::send_reminder
The expected [App\Mail\ClientEmail] mailable was not sent.
Failed asserting that false is true.

/Applications/MAMP/htdocs/Ashore/vendor/laravel/framework/src/Illuminate/Support/Testing/Fakes/MailFake.php:30
/Applications/MAMP/htdocs/Ashore/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:221
/Applications/MAMP/htdocs/Ashore/tests/Unit/Timeline/TimelineTest.php:72
/Applications/MAMP/htdocs/Ashore/tests/Unit/Timeline/TimelineTest.php:72

Is it because I am using Mail::queue function instead of Mail::send?

In .env file, I have

QUEUE_DRIVER=sync and MAIL_DRIVER=log

If so, how can I test Mail::queue?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2sVIWTe
via IFTTT

Aucun commentaire:

Enregistrer un commentaire