packages/sql-semantics-mysql/tests/Unit/Statement/Query/Clause/ProgramVariableTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Query\Clause;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Medium;
9use PHPUnit\Framework\TestCase;
10use SqlSemantics\Platform\MySql\Model\Statement\Type\Dependent;
11use SqlSemantics\Platform\MySql\Semantics;
12use SqlSemantics\Platform\MySql\Statement\Query\Clause\ProgramVariable;
13use SqlSemantics\Platform\MySql\Statement\Query\Clause\RowLimit;
14use SqlSemantics\Platform\MySql\Statement\Query\Select;
15
16#[CoversClass(ProgramVariable::class)]
17#[Medium]
18final class ProgramVariableTest extends TestCase
19{
20    public function testDeriveScalarDependsOnTheStoredProgram(): void
21    {
22        $operation = (new Semantics())->inspect('SELECT a FROM t LIMIT n');
23
24        self::assertInstanceOf(Select::class, $operation->statement);
25        self::assertInstanceOf(RowLimit::class, $operation->statement->limit);
26        $type = $operation->facts->scalar($operation->statement->limit->count)->type;
27        self::assertInstanceOf(Dependent::class, $type);
28        self::assertSame('the session state: stored program variable n', $type->missing[0]->describe());
29    }
30
31    public function testRenderWritesTheName(): void
32    {
33        self::assertSame('SELECT a FROM t INTO x, `select`', (new Semantics())->inspect("SELECT a FROM t INTO x, 'select'")->toString());
34    }
35}
36