packages/sql-semantics-mysql/tests/Unit/Statement/Dml/EvaluationTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Dml;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Medium;
9use PHPUnit\Framework\TestCase;
10use SqlSemantics\Platform\MySql\Semantics;
11use SqlSemantics\Platform\MySql\Statement\Dml\Evaluation;
12
13#[CoversClass(Evaluation::class)]
14#[Medium]
15final class EvaluationTest extends TestCase
16{
17    public function testDeriveStatementDerivesTheItemsWithoutOutput(): void
18    {
19        $operation = (new Semantics())->inspect('DO 1 + 1, @a := 2');
20        self::assertInstanceOf(Evaluation::class, $operation->statement);
21
22        self::assertCount(2, $operation->statement->items);
23        self::assertNull($operation->facts->output);
24    }
25
26    public function testDeriveStatementReportsAStarWithoutTables(): void
27    {
28        $operation = (new Semantics())->inspect('DO *');
29
30        self::assertSame('No tables used', $operation->facts->diagnostics[0]->message());
31    }
32
33    public function testRenderWritesTheItems(): void
34    {
35        self::assertSame('DO 1, 2', (new Semantics('mysql-5.6.51'))->inspect('do 1, 2')->toString());
36        self::assertSame('DO 1 x', (new Semantics('mysql-5.7.44'))->inspect('do 1 x')->toString());
37    }
38
39    public function testRenderRejectsAnEmptyList(): void
40    {
41        $this->expectExceptionMessage('DO evaluates at least one expression.');
42
43        new Evaluation([]);
44    }
45}
46