beyondcode / helo-laravel

HELO Laravel helper package to add
MIT License
87 stars 26 forks source link

Updated Service Provider to not register the Mailer if tests are running #20

Closed jpeters8889 closed 3 years ago

jpeters8889 commented 4 years ago

I recently had an issue where some tests were failing that used the Mail::fake() and Mail::assert...() methods.

Rather than using the Mail facade or anything in the controller I was injecting Illuminate\Contracts\Mail\Mailerand then using that to send my emails. After a lot of debugging I found that when I was using dd() in the controller on the Mailer variable while running the failing test, it was actually an instance of the Helo Mailer rather than the MailFake I was expecting.

I fixed this by updating my phpunit.xml to set the HELO_ENABLED env variable to false. At first, it wasn't immediately obvious that Helo was causing the issue and that I could stop the Helo Mailer getting instantiated by adding the variable, which is why I created this PR just to update the Service Provider to return early if $this->app->runningUnitTests() is true for anyone else that runs into this issue and to save a couple of hours of trying to figure out why!

mpociot commented 3 years ago

Thank you!