framework: Argument #1 ($manager) must be of type Illuminate\Mail\MailManager

  • Laravel Version: 10.0.3
  • PHP Version: 8.2.0
  • Database Driver & Version:

Description:

We are using Mail::fake in a test and since we upgraded to Laravel 10 it’s failing with following exception:

Illuminate\Support\Testing\Fakes\MailFake::__construct(): Argument #1 ($manager) must be of type Illuminate\Mail\MailManager, Illuminate\Support\Testing\Fakes\MailFake given, called in /var/www/vendor/laravel/framework/src/Illuminate/Support/Facades/Mail.php on line 68
Mail::fake();
Mail::assertNothingSent();
expect(fn () => $votingCard->approveRequest())->not()->toThrow(\Symfony\Component\Mime\Exception\LogicException::class);

Steps To Reproduce:

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 25 (16 by maintainers)

Most upvoted comments

@driesvints this issue raises a good point about testing with facades though. If a facade implements a fake method that then builds an object based on that facade’s root and returns it, any test suit that calls Facade::fake() more than once (like the example @maloun96 provided above within setUp and then testItDoesX) will break.

@taylorotwell Might it be worth covering this use-case in the testing docs?

@alexgaal @driesvints I’m working on a PR to ~fix~ improve this

Oh, thank you Dries! I fixed that, it’s working now. Thanks to all of you.

I’ve raised a PR covering this, too