Files
ludikevent_crm/tests/Security/PasswordGeneratorTest.php

37 lines
1.1 KiB
PHP
Raw Normal View History

<?php
namespace App\Tests\Security;
use App\Security\PasswordGenerator;
use PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations;
use PHPUnit\Framework\TestCase;
#[AllowMockObjectsWithoutExpectations]
class PasswordGeneratorTest extends TestCase
{
public function testGenerateLength()
{
$generator = new PasswordGenerator(16);
$password = $generator->generate();
$this->assertEquals(16, strlen($password));
}
public function testGenerateContainsRequiredCharacters()
{
$generator = new PasswordGenerator(12);
$password = $generator->generate();
$this->assertMatchesRegularExpression('/[a-z]/', $password);
$this->assertMatchesRegularExpression('/[A-Z]/', $password);
$this->assertMatchesRegularExpression('/[0-9]/', $password);
$this->assertMatchesRegularExpression('/[@#_\-]/', $password);
}
public function testInvalidLengthThrowsException()
{
$this->expectException(\InvalidArgumentException::class);
new PasswordGenerator(3);
}
}