24 lines
796 B
PHP
24 lines
796 B
PHP
|
<?php namespace MapGuesser\Tests\Util;
|
||
|
|
||
|
use MapGuesser\Util\UsernameGenerator;
|
||
|
use PHPUnit\Framework\TestCase;
|
||
|
|
||
|
final class UsernameGeneratorTest extends TestCase
|
||
|
{
|
||
|
public function testCanGenerateRandomUsernameFromComponents(): void
|
||
|
{
|
||
|
$generator = new UsernameGenerator();
|
||
|
$parts = $this->getUsernameParts($generator->generate());
|
||
|
|
||
|
$this->assertEquals(3, count($parts));
|
||
|
$this->assertContains($parts[0], UsernameGenerator::ADJECTIVES);
|
||
|
$this->assertContains($parts[1], UsernameGenerator::ADJECTIVES);
|
||
|
$this->assertContains($parts[2], UsernameGenerator::NOUNS);
|
||
|
}
|
||
|
|
||
|
private function getUsernameParts(string $username): array
|
||
|
{
|
||
|
return explode('-', strtolower(preg_replace('/([a-z])([A-Z])/', '$1-$2', $username)));
|
||
|
}
|
||
|
}
|