CaiWuXiTong/tests/Feature/Email/TooManyEmailsSentTest.php
WuYongJie 9595267ee7
Some checks failed
Tests / PHP 8.1 (push) Has been cancelled
Tests / PHP 8.2 (push) Has been cancelled
Tests / PHP 8.3 (push) Has been cancelled
chore: 导入 Akaunting 初始源码与团队协作规则
2026-07-20 18:20:25 +08:00

52 lines
1.3 KiB
PHP

<?php
namespace Tests\Feature\Email;
use App\Events\Email\TooManyEmailsSent;
use Tests\Feature\FeatureTestCase;
class TooManyEmailsSentTest extends FeatureTestCase
{
public function testItShouldNotBlockIpDueToTooManyEmailsSent()
{
$this->loginAs();
config(['firewall.middleware.too_many_emails_sent.enabled' => true]);
for ($i = 0; $i < 19; $i++) {
event(new TooManyEmailsSent(user_id()));
}
$this->assertDatabaseHas('firewall_logs', [
'user_id' => user_id(),
'middleware' => 'too_many_emails_sent',
]);
$this->assertDatabaseCount('firewall_logs', 19);
$this->assertDatabaseEmpty('firewall_ips');
}
public function testItShouldBlockIpDueToTooManyEmailsSent()
{
$this->loginAs();
config(['firewall.middleware.too_many_emails_sent.enabled' => true]);
for ($i = 0; $i < 20; $i++) {
event(new TooManyEmailsSent(user_id()));
}
$this->assertDatabaseHas('firewall_logs', [
'user_id' => user_id(),
'middleware' => 'too_many_emails_sent',
]);
$this->assertDatabaseCount('firewall_logs', 20);
$this->assertDatabaseHas('firewall_ips', [
'ip' => request()->ip(),
]);
}
}