packages/sql-semantics-postgres/tests/Unit/Statement/Utility/NotifyTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Utility;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Medium;
9use PHPUnit\Framework\TestCase;
10use SqlSemantics\Platform\PostgreSql\Model\Statement\Fact\Diagnostic;
11use SqlSemantics\Platform\PostgreSql\Semantics;
12use SqlSemantics\Platform\PostgreSql\Statement\Utility\Notify;
13
14#[CoversClass(Notify::class)]
15#[Medium]
16final class NotifyTest extends TestCase
17{
18    public function testDeriveStatementAcceptsAPayloadBelowTheLimit(): void
19    {
20        self::assertSame([], (new Semantics())->inspect("NOTIFY c, '" . str_repeat('x', 7999) . "'")->facts->diagnostics);
21    }
22
23    public function testDeriveStatementReportsAPayloadAtTheLimit(): void
24    {
25        self::assertSame(['payload string too long'], array_map(static fn (Diagnostic $diagnostic): string => $diagnostic->message(), (new Semantics())->inspect("NOTIFY c, '" . str_repeat('é', 4000) . "'")->facts->diagnostics));
26    }
27
28    public function testRenderWritesThePayloadAfterAComma(): void
29    {
30        self::assertSame(["NOTIFY c, ''", 'NOTIFY "C"'], [(new Semantics())->inspect("NOTIFY c, ''")->toString(), (new Semantics())->inspect('NOTIFY "C"')->toString()]);
31    }
32}
33