1
我面臨兩個我想解決/理解的情況。Laravel 5上的單元測試郵件隊列
1st - 我如何測試Laravel的郵件隊列類?
,我想測試的代碼是這樣的:
// Create new customer record
$account = $this->create(['account_id' => $account->id]);
// Get email address to send welcome email.
$email = $data['email'];
// Email Subject
$subject = $this->word('emails.welcome.subject');
$this->mailQueue->queue('emails.welcome',
['some_data' => 'data'],
function ($message) use ($email, $subject) {
$message->to($email)->subject($subject);
}, true);
return $account;
我想知道哪裏是shouldReceive
方法將使用Illuminate\Contracts\Mail\MailQueue
類時爲我工作。
現在我對這個這個單元測試:
/**
* @tests
*/
public function it_should_sign_up_a_new_user() {
// MailQueue::shouldReceive() does not exist.
list($account, $email) = $this->getAccountData();
$request = array_merge($account, $email);
$account['password'] = $this->hash($account['password']);
$this->post('/signup', $request, $this->header)
->assertResponseOk()
->seeInDatabase('account', $account)
->seeInDatabase('email', $email);
}
2日 - 爲什麼單元測試不需要php artisan queue:listen
或queue:work
?
每次運行單元測試時,即使我沒有運行queue:listen
,也會分派電子郵件。我想了解這個令人敬畏的魔法是如何發生的。
[使用模擬單元測試Laravel 5郵件]的可能的複製(HTTP ://stackoverflow.com/questions/31120567/unittesting-laravel-5-mail-using-mock) –