packages/sql-faker/tests/Unit/PostgreSql/Generation/Value/IdentifierDomainTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\SqlFaker\PostgreSql\Generation\Value;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\UsesClass;
9use PHPUnit\Framework\TestCase;
10use SqlFaker\Generation\Value\CharacterDomain;
11use SqlFaker\PostgreSql\Generation\Value\IdentifierDomain;
12
13#[CoversClass(IdentifierDomain::class)]
14#[UsesClass(CharacterDomain::class)]
15final class IdentifierDomainTest extends TestCase
16{
17 public function testChooseKeepsTheSafePrefixAndLengthBudget(): void
18 {
19 $domain = new IdentifierDomain('a_', 'a0_', '_sf', 5);
20 self::assertSame('_sf', $domain->choose(static fn (int $count): int => 0));
21 self::assertSame('_sf__', $domain->choose(static fn (int $count): int => $count - 1));
22 }
23
24 public function testMatchUsesStartAndContinuationClassesWithoutRequiringTheSamplePrefix(): void
25 {
26 $domain = new IdentifierDomain('a_', 'a0_');
27 self::assertSame([2, 3, 4], $domain->match('!a0_ ', 1));
28 self::assertSame([], $domain->match('0a'));
29 self::assertSame([], $domain->match(''));
30 self::assertNotContains(3, (new IdentifierDomain('Ss', 'QqLl', excluded: ['SQL']))->match('sQl'));
31 }
32}
33