Laravel Unit Test - Test Mail


Đầu tiên về nội dung Seri này là giới thiệu cơ bản về các loại test trong Laravel

Bài này mình sẽ làm về test mail
Các bước cơ bản như sau:
1. Thêm thư viện cần dùng: use Illuminate\Support\Facades\Mail;

2. Làm theo hướng dẫn:
```
public function testEmail() {
    Mail::fake();

    // Your post call here(API or JOB or COMMAND)
    // Example call a command here 
    $this->artisan('command:commandname', [
            'argurment' => 'test@testcommand.com',
            '--option' => 'test.com'
        ]);
    Mail::assertSent(CommentPosted::class); // This is a mailable class
    
    // You can also check if the correct email was send
    // by checking the data that was send to it
    Mail::assertSent(CommentPosted::class, function ($mail) use ($user) {

    return $mail->hasTo($user->email) &&
                $mail->hasCc('...') &&
                $mail->hasBcc('...'); }); }
        }); }
});
}
```

Comments

Bài đăn phổ biến

Deploy website lên VPS hoặc Hosting với Gitlab CI/CD

MỞ CAMERA VÀ CHỤP ẢNH BẰNG PHP

Tính Bình Phương 1 Số Trong Python

Đường dẫn tương đối trong Java