packages/sql-faker/tests/Unit/Compiler/Bison/BisonStartSymbolTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\SqlFaker\Compiler\Bison;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\UsesClass;
9use PHPUnit\Framework\TestCase;
10use SqlFaker\Compiler\Bison\Ast\BisonExpectDeclaration;
11use SqlFaker\Compiler\Bison\Ast\BisonRuleNode;
12use SqlFaker\Compiler\Bison\Ast\BisonStartDeclaration;
13use SqlFaker\Compiler\Bison\BisonStartSymbol;
14
15#[CoversClass(BisonStartSymbol::class)]
16#[UsesClass(BisonExpectDeclaration::class)]
17#[UsesClass(BisonRuleNode::class)]
18#[UsesClass(BisonStartDeclaration::class)]
19final class BisonStartSymbolTest extends TestCase
20{
21 public function testFromPrefersTheDeclaredStartRule(): void
22 {
23 $symbol = (new BisonStartSymbol())->from(
24 [new BisonStartDeclaration('statement')],
25 [new BisonRuleNode('first_rule', [])],
26 );
27
28 self::assertSame('statement', $symbol);
29 }
30
31 public function testFromFallsBackToTheFirstRuleWhenNoneIsDeclared(): void
32 {
33 $symbol = (new BisonStartSymbol())->from(
34 [new BisonExpectDeclaration(3)],
35 [new BisonRuleNode('first_rule', []), new BisonRuleNode('second_rule', [])],
36 );
37
38 self::assertSame('first_rule', $symbol);
39 }
40
41 public function testFromTakesTheFirstStartDeclarationWhenSeveralAreWritten(): void
42 {
43 $symbol = (new BisonStartSymbol())->from(
44 [new BisonStartDeclaration('first'), new BisonStartDeclaration('second')],
45 [new BisonRuleNode('rule', [])],
46 );
47
48 self::assertSame('first', $symbol);
49 }
50}
51