packages/sql-semantics-postgres/tests/Unit/Statement/Option/AlteredOptionTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Option;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Small;
9use PHPUnit\Framework\TestCase;
10use SqlSemantics\Platform\PostgreSql\Model\Contract\GrammarRelease;
11use SqlSemantics\Platform\PostgreSql\Model\Rendering\Lexical;
12use SqlSemantics\Platform\PostgreSql\Model\Rendering\Output;
13use SqlSemantics\Platform\PostgreSql\Model\Statement\Identifier\Name;
14use SqlSemantics\Platform\PostgreSql\Rendering\Codec;
15use SqlSemantics\Platform\PostgreSql\Statement\Literal\StringConstant;
16use SqlSemantics\Platform\PostgreSql\Statement\Option\AlteredOption;
17use SqlSemantics\Platform\PostgreSql\Statement\Option\OptionAction;
18
19#[CoversClass(AlteredOption::class)]
20#[Small]
21final class AlteredOptionTest extends TestCase
22{
23 public function testRenderWritesTheActionNameAndValue(): void
24 {
25 $out = new Output(new Codec(GrammarRelease::PostgreSql172));
26 (new AlteredOption(OptionAction::Set, new Name('host'), new StringConstant('db2')))->render($out);
27 self::assertSame("SET host 'db2'", (new Lexical())->join($out->pieces()));
28 $second = new Output(new Codec(GrammarRelease::PostgreSql172));
29 (new AlteredOption(OptionAction::Drop, new Name('host')))->render($second);
30 self::assertSame('DROP host', (new Lexical())->join($second->pieces()));
31 }
32
33 public function testRejectsADroppedOptionWithAValue(): void
34 {
35 $this->expectExceptionMessage('An option has a value exactly when it is added or set.');
36 new AlteredOption(OptionAction::Drop, new Name('host'), new StringConstant('x'));
37 }
38}
39