I am trying to approve mail sent with Laravel 5.4 fakes.
My test code is:
public function setUp()
{
parent::setUp();
$this->admin = create(User::class, [
'is_admin' => true,
]);
$this->faker = Factory::create();
}
public function only_super_admin_can_create_admin()
{
$admin = [
'name' => $this->faker->name,
'email' => $this->faker->email,
];
Mail::fake();
$this->signIn($this->admin)
->post('/admins', $admin)
->assertRedirect('/admins');
Mail::assertSent(NewUser::class, function ($mail) use ($admin) {
dd($mail);
});
$this->assertDatabaseHas('users', $admin);
}
When reset $mail, I get the following:
App\Mail\NewUser {
0 => "name"
1 => "email"
2 => "password"
3 => "role"
4 => "is_admin"
5 => "id"
]
0 => "password"
1 => "remember_token"
]
+incrementing: true
+exists: true
+wasRecentlyCreated: true
"name" => "Dave Ortiz"
"email" => "prosacco.dejuan@gmail.com"
"password" => "$2y$10$OGiQJJ/HCOIlbAl/t6tbpuz4WLQenLRVZgFPN/0e0P.3Ft9542OW2"
"is_admin" => true
"updated_at" => "2017-06-03 11:06:56"
"created_at" => "2017-06-03 11:06:56"
"id" => 2
]
"name" => "Dave Ortiz"
"email" => "prosacco.dejuan@gmail.com"
"password" => "$2y$10$OGiQJJ/HCOIlbAl/t6tbpuz4WLQenLRVZgFPN/0e0P.3Ft9542OW2"
"is_admin" => true
"updated_at" => "2017-06-03 11:06:56"
"created_at" => "2017-06-03 11:06:56"
"id" => 2
]
+timestamps: true
0 => "*"
]
}
+from: []
+to: []
+cc: []
+bcc: []
+replyTo: []
+subject: null
+view: null
+textView: null
+viewData: []
+attachments: []
+rawAttachments: []
+callbacks: []
+connection: null
+queue: null
+delay: null
}
As you can see, it does not show anything in the array to, which means that when I state that Mail was sent from hasTo(), it fails:
1) Tests\Feature\SuperAdminTest::only_super_admin_can_create_admin
The expected [App\Mail\NewUser] mailable was not sent.
Failed asserting that false is true.
My Controller stores the user as follows:
public function store(StoreUserRequest $request)
{
$user = $request->storeUser(null, null, null, true);
return redirect('/admins');
}
The method is StoreUserRequestas follows:
public function storeUser($name = null, $email = null, $password = null, $admin = false)
{
$password = $password ?: str_random(10);
$user = User::create([
'name' => ($name) ?: $this->name,
'email' => ($email) ?: $this->email,
'password' => bcrypt($password),
'is_admin' => $admin,
]);
Mail::send(new NewUser($user, $password));
return $user;
}
The actual NewUserfollowing:
class NewUser extends Mailable
{
use Queueable, SerializesModels;
protected $user;
protected $password;
public function __construct($user, $password)
{
$this->user = $user;
$this->password = $password;
}
public function build()
{
return $this->view('emails.users.' . strtolower(($this->user->is_admin) ? 'Admin' : 'Client'))
->with('user', $this->user)
->with('password', $this->password)
->to($this->user->email, $this->user->name)
->subject('[' . $this->user->name . '] Your New ' . ($this->user->is_admin ? 'Admin' : 'Client') . ' Account');
}
}
Now, even more strange, when I manually create a user in the application, an email will come!

Does anyone have any ideas why this won't work?