Files
breadcrumb-the-shire/tests/Service/UserServicePasswordTest.php

41 lines
1.1 KiB
PHP
Raw Normal View History

2026-02-04 23:31:53 +01:00
<?php
namespace MintyPHP\Tests\Service;
2026-02-23 12:58:19 +01:00
use MintyPHP\Service\User\UserPasswordPolicyService;
2026-02-04 23:31:53 +01:00
use PHPUnit\Framework\TestCase;
class UserServicePasswordTest extends TestCase
{
2026-02-23 12:58:19 +01:00
private UserPasswordPolicyService $policy;
protected function setUp(): void
{
$this->policy = new UserPasswordPolicyService();
}
2026-02-04 23:31:53 +01:00
public function testRequiresPasswordWhenRequired(): void
{
2026-02-23 12:58:19 +01:00
$errors = $this->policy->validate('', '', true, 'test@example.com');
2026-02-04 23:31:53 +01:00
$this->assertNotEmpty($errors);
}
public function testRejectsMismatch(): void
{
2026-02-23 12:58:19 +01:00
$errors = $this->policy->validate('Abcd1234$efg', 'Abcd1234$xxx', true, 'test@example.com');
2026-02-04 23:31:53 +01:00
$this->assertNotEmpty($errors);
}
public function testAcceptsStrongPassword(): void
{
2026-02-23 12:58:19 +01:00
$errors = $this->policy->validate('StrongPass1!', 'StrongPass1!', true, 'test@example.com');
2026-02-04 23:31:53 +01:00
$this->assertSame([], $errors);
}
public function testRejectsPasswordContainingEmail(): void
{
2026-02-23 12:58:19 +01:00
$errors = $this->policy->validate('test@example.comA1!', 'test@example.comA1!', true, 'test@example.com');
2026-02-04 23:31:53 +01:00
$this->assertNotEmpty($errors);
}
}