packages/sql-semantics-postgres/tests/Unit/Statement/Catalog/Access/Role/RoleConnectionLimitTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Catalog\Access\Role;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Medium;
9use PHPUnit\Framework\TestCase;
10
11#[CoversClass(\SqlSemantics\Platform\PostgreSql\Statement\Catalog\Access\Role\RoleConnectionLimit::class)]
12#[Medium]
13final class RoleConnectionLimitTest extends TestCase
14{
15 public function testOption(): void
16 {
17 self::assertSame('connectionlimit', (new \SqlSemantics\Platform\PostgreSql\Statement\Catalog\Access\Role\RoleConnectionLimit(new \SqlSemantics\Platform\PostgreSql\Statement\Literal\SignedNumber(false, new \SqlSemantics\Platform\PostgreSql\Statement\Literal\IntegerConstant('5'))))->option());
18 }
19
20 public function testAcceptableFromMinusOne(): void
21 {
22 self::assertTrue((new \SqlSemantics\Platform\PostgreSql\Statement\Catalog\Access\Role\RoleConnectionLimit(new \SqlSemantics\Platform\PostgreSql\Statement\Literal\SignedNumber(true, new \SqlSemantics\Platform\PostgreSql\Statement\Literal\IntegerConstant('1'))))->acceptable());
23 self::assertTrue((new \SqlSemantics\Platform\PostgreSql\Statement\Catalog\Access\Role\RoleConnectionLimit(new \SqlSemantics\Platform\PostgreSql\Statement\Literal\SignedNumber(false, new \SqlSemantics\Platform\PostgreSql\Statement\Literal\IntegerConstant('7'))))->acceptable());
24 self::assertFalse((new \SqlSemantics\Platform\PostgreSql\Statement\Catalog\Access\Role\RoleConnectionLimit(new \SqlSemantics\Platform\PostgreSql\Statement\Literal\SignedNumber(true, new \SqlSemantics\Platform\PostgreSql\Statement\Literal\IntegerConstant('2'))))->acceptable());
25 }
26
27 public function testRenderWritesTheSignedLimit(): void
28 {
29 self::assertSame('CREATE ROLE r CONNECTION LIMIT - 1', (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('CREATE ROLE r CONNECTION LIMIT -1')->toString());
30 }
31
32 public function testRejectsAFraction(): void
33 {
34 $this->expectExceptionMessage('A connection limit is an integer.');
35 new \SqlSemantics\Platform\PostgreSql\Statement\Catalog\Access\Role\RoleConnectionLimit(new \SqlSemantics\Platform\PostgreSql\Statement\Literal\SignedNumber(false, new \SqlSemantics\Platform\PostgreSql\Statement\Literal\NumericConstant('1.5')));
36 }
37}
38