d6cc1cbca9
Run Tests / test (pull_request) Failing after 1m8s
BookingTransitionTest:驗證 canTransitionTo() 所有合法/非法轉換與終態不可逃脫(18 案例) BookingStatusTest:驗證 7 個狀態完整性、from/tryFrom、VALID_TRANSITIONS 覆蓋一致性(10 案例) NormalizesEmailTest:驗證大小寫與空白正規化邏輯(5 案例) 全部使用 PHPUnit 原生 TestCase,不需要資料庫連線,執行 1.82s。 全套件 187 passed / 464 assertions,零 regression。 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
58 lines
1.7 KiB
PHP
58 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\Traits;
|
|
|
|
use App\Traits\NormalizesEmail;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
/**
|
|
* NormalizesEmail::normalizeEmail() 是純字串邏輯。
|
|
* 帳號鎖定計數器(AuthLockoutTest)依賴此邏輯確保大小寫與空白
|
|
* 不會被視為不同帳號而繞過鎖定——這裡驗證邏輯本身,
|
|
* 而非驗證它被正確呼叫(那是 AuthLockoutTest 的職責)。
|
|
*/
|
|
class NormalizesEmailTest extends TestCase
|
|
{
|
|
private object $subject;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
// normalizeEmail 是 private,透過匿名類別暴露供測試
|
|
$this->subject = new class {
|
|
use NormalizesEmail;
|
|
|
|
public function normalize(string $email): string
|
|
{
|
|
return $this->normalizeEmail($email);
|
|
}
|
|
};
|
|
}
|
|
|
|
public function test_uppercase_is_lowercased(): void
|
|
{
|
|
$this->assertSame('user@example.com', $this->subject->normalize('USER@EXAMPLE.COM'));
|
|
}
|
|
|
|
public function test_leading_and_trailing_whitespace_is_trimmed(): void
|
|
{
|
|
$this->assertSame('user@example.com', $this->subject->normalize(' user@example.com '));
|
|
}
|
|
|
|
public function test_mixed_case_and_whitespace_are_both_normalized(): void
|
|
{
|
|
$this->assertSame('user@example.com', $this->subject->normalize(' User@Example.COM '));
|
|
}
|
|
|
|
public function test_already_normalized_email_is_unchanged(): void
|
|
{
|
|
$this->assertSame('user@example.com', $this->subject->normalize('user@example.com'));
|
|
}
|
|
|
|
public function test_tab_whitespace_is_trimmed(): void
|
|
{
|
|
$this->assertSame('user@example.com', $this->subject->normalize("\tuser@example.com\t"));
|
|
}
|
|
}
|