41 lines
1.1 KiB
PHP
41 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace MintyPHP\Tests\Service;
|
|
|
|
use MintyPHP\Service\User\UserPasswordPolicyService;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class UserServicePasswordTest extends TestCase
|
|
{
|
|
private UserPasswordPolicyService $policy;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->policy = new UserPasswordPolicyService();
|
|
}
|
|
|
|
public function testRequiresPasswordWhenRequired(): void
|
|
{
|
|
$errors = $this->policy->validate('', '', true, 'test@example.com');
|
|
$this->assertNotEmpty($errors);
|
|
}
|
|
|
|
public function testRejectsMismatch(): void
|
|
{
|
|
$errors = $this->policy->validate('Abcd1234$efg', 'Abcd1234$xxx', true, 'test@example.com');
|
|
$this->assertNotEmpty($errors);
|
|
}
|
|
|
|
public function testAcceptsStrongPassword(): void
|
|
{
|
|
$errors = $this->policy->validate('StrongPass1!', 'StrongPass1!', true, 'test@example.com');
|
|
$this->assertSame([], $errors);
|
|
}
|
|
|
|
public function testRejectsPasswordContainingEmail(): void
|
|
{
|
|
$errors = $this->policy->validate('test@example.comA1!', 'test@example.comA1!', true, 'test@example.com');
|
|
$this->assertNotEmpty($errors);
|
|
}
|
|
}
|