packages/sql-semantics-mysql/tests/Unit/Statement/Dml/DeleteTest.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\Model\Statement\Declaration\Column;
11use SqlSemantics\Platform\MySql\Model\Statement\Declaration\Table;
12use SqlSemantics\Platform\MySql\Model\Statement\Identifier\Name;
13use SqlSemantics\Platform\MySql\Model\Statement\Identifier\QualifiedName;
14use SqlSemantics\Platform\MySql\Model\Statement\Type\Nullability;
15use SqlSemantics\Platform\MySql\Semantics;
16use SqlSemantics\Platform\MySql\Statement\Dml\Delete;
17use SqlSemantics\Platform\MySql\Statement\Type\Integral;
18use SqlSemantics\Platform\MySql\Statement\Type\Kind\IntegralKind;
19
20#[CoversClass(Delete::class)]
21#[Medium]
22final class DeleteTest extends TestCase
23{
24 public function testDeriveStatementSeesTheTableUnderItsAlias(): void
25 {
26 $semantics = new Semantics();
27 $t = new Table(new QualifiedName(new Name('t'), new Name('(current)')), $semantics->profile(), [new Column(new Name('a'), new Integral(IntegralKind::Int), Nullability::NotNull), new Column(new Name('b'), new Integral(IntegralKind::BigInt))]);
28 $operation = $semantics->analyze('DELETE FROM t AS x WHERE x.a = 1 ORDER BY b LIMIT 1', [$t]);
29 self::assertInstanceOf(Delete::class, $operation->statement);
30
31 self::assertSame([], $operation->facts->diagnostics);
32 self::assertNull($operation->facts->output);
33 }
34
35 public function testRenderWritesEveryClause(): void
36 {
37 self::assertSame('DELETE LOW_PRIORITY QUICK IGNORE FROM t PARTITION (p) WHERE a = 1 ORDER BY b LIMIT 5', (new Semantics('mysql-5.6.51'))->analyze('delete low_priority quick ignore from t partition (p) where a = 1 order by b limit 5')->toString());
38 }
39}
40