Mailtrapを使った方法と
メールの受け取り先を共通にする方法の2つを紹介します
Mailtrapを使った方法
.envファイルの修正
Mialtrapの設定を見ながらsmtpサーバの設定をenvファイルに反映する
MAIL_DRIVER=smtp
MAIL_USERNAME=xxxxxxxxxxxxxx
MAIL_PASSWORD=xxxxxxxxxxxxx
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
phpunit.xml
一時的にphpunitを使ったメール送信をMailtrapでキャッチしたい場合はMAIL_DRIVER
の値が上書きされてしまうので注意
MAIL_DRIVERの値をsmtpにする
ただ戻しておかないとCircleCIとかでテストを回すたびにMailtrapにメールが飛んでMailtrapの制限にいっちゃうので注意
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./app</directory>
</whitelist>
</filter>
<php>
<server name="APP_ENV" value="local"/>
<server name="BCRYPT_ROUNDS" value="4"/>
<server name="CACHE_DRIVER" value="redis"/>
<server name="MAIL_DRIVER" value="smtp"/>
<server name="QUEUE_CONNECTION" value="sync"/>
<server name="SESSION_DRIVER" value="array"/>
</php>
</phpunit>
宛先のメールアドレスを変えて自分のメールボックスでメールを受けて確認する方法
config/mail.phpにtoを設定すると全てのメールが指定されたアドレスに送信されます
'to' => [
'address' => 'example@example.com',
'name' => 'Example'
],