You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
2.7 KiB
76 lines
2.7 KiB
|
11 months ago
|
<?php
|
||
|
|
|
||
|
|
namespace Tests\Feature;
|
||
|
|
|
||
|
|
use App\Models\Admin;
|
||
|
|
use App\Notifications\VisitEmailNotify;
|
||
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||
|
|
use Illuminate\Support\Facades\Mail;
|
||
|
|
use Tests\TestCase;
|
||
|
|
|
||
|
|
class RealEmailSendTest extends TestCase
|
||
|
|
{
|
||
|
|
use RefreshDatabase;
|
||
|
|
|
||
|
|
/** @test */
|
||
|
|
public function test_send_real_email_to_648753004_qq_com()
|
||
|
|
{
|
||
|
|
// 创建被访管理员,邮箱设置为指定的测试邮箱
|
||
|
|
$acceptAdmin = Admin::factory()->create([
|
||
|
|
'name' => '被访管理员',
|
||
|
|
'email' => '648753004@qq.com',
|
||
|
|
]);
|
||
|
|
|
||
|
|
// 模拟预约拜访数据
|
||
|
|
$visitData = [
|
||
|
|
'name' => '测试访客',
|
||
|
|
'date' => '2024-01-15',
|
||
|
|
'mobile' => '13800138000',
|
||
|
|
'reason' => '业务洽谈',
|
||
|
|
];
|
||
|
|
|
||
|
|
// 不使用Notification::fake(),真正发送邮件
|
||
|
|
try {
|
||
|
|
$acceptAdmin->notify(new VisitEmailNotify($visitData));
|
||
|
|
|
||
|
|
// 如果发送成功,测试通过
|
||
|
|
$this->assertTrue(true, '邮件发送成功');
|
||
|
|
|
||
|
|
// 输出成功信息
|
||
|
|
echo "\n✅ 邮件已发送到: 648753004@qq.com\n";
|
||
|
|
echo "📧 邮件主题: 新的拜访预约通知 - 测试访客\n";
|
||
|
|
echo "👤 被访人: 被访管理员\n";
|
||
|
|
echo "📅 预约日期: 2024-01-15\n";
|
||
|
|
echo "📱 访客电话: 13800138000\n";
|
||
|
|
echo "📝 拜访事由: 业务洽谈\n";
|
||
|
|
|
||
|
|
} catch (\Exception $e) {
|
||
|
|
// 如果发送失败,输出错误信息
|
||
|
|
$this->fail('邮件发送失败: ' . $e->getMessage());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/** @test */
|
||
|
|
public function test_email_configuration()
|
||
|
|
{
|
||
|
|
// 测试邮件配置是否正确
|
||
|
|
$this->assertEquals('smtp', config('mail.default'));
|
||
|
|
$this->assertEquals('smtp.exmail.qq.com', config('mail.mailers.smtp.host'));
|
||
|
|
$this->assertEquals(465, config('mail.mailers.smtp.port'));
|
||
|
|
$this->assertEquals('ssl', config('mail.mailers.smtp.encryption'));
|
||
|
|
$this->assertEquals('no-reply@langye.net', config('mail.from.address'));
|
||
|
|
|
||
|
|
echo "\n📧 邮件配置信息:\n";
|
||
|
|
echo " 发送方式: " . config('mail.default') . "\n";
|
||
|
|
echo " SMTP服务器: " . config('mail.mailers.smtp.host') . "\n";
|
||
|
|
echo " 端口: " . config('mail.mailers.smtp.port') . "\n";
|
||
|
|
echo " 加密方式: " . config('mail.mailers.smtp.encryption') . "\n";
|
||
|
|
echo " 发送邮箱: " . config('mail.from.address') . "\n";
|
||
|
|
|
||
|
|
// 验证配置不为空
|
||
|
|
$this->assertNotEmpty(config('mail.default'));
|
||
|
|
$this->assertNotEmpty(config('mail.mailers.smtp.host'));
|
||
|
|
$this->assertNotEmpty(config('mail.from.address'));
|
||
|
|
}
|
||
|
|
}
|