mapguesser/tests/Util/UsernameGeneratorTest.php

24 lines
796 B
PHP
Raw Permalink Normal View History

2023-09-25 19:54:47 +02:00
<?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)));
}
}