packages/sql-semantics-postgres/tests/Unit/Rules/Expression/Typing/PredicateTypingTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Rules\Expression\Typing;
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\Contract\LanguageProfile;
12use SqlSemantics\Platform\PostgreSql\Model\Statement\Type\Known;
13use SqlSemantics\Platform\PostgreSql\Platform;
14use SqlSemantics\Platform\PostgreSql\Rules\Expression\Typing\PredicateTyping;
15use SqlSemantics\Platform\PostgreSql\Statement\Expression\Operator\PatternOperator;
16use SqlSemantics\Platform\PostgreSql\Statement\Type\Descriptor\Builtin;
17
18#[CoversClass(PredicateTyping::class)]
19#[Small]
20final class PredicateTypingTest extends TestCase
21{
22 public function testPatternIsBooleanForStrings(): void
23 {
24 $context = (new Platform())->context(new LanguageProfile(GrammarRelease::PostgreSql172), null, [], true);
25 self::assertEquals(new Known(Builtin::Bool), (new PredicateTyping())->pattern($context, PatternOperator::ILike, new Known(Builtin::Varchar), new Known(Builtin::Unknown)));
26 }
27
28 public function testZoneSwapsTheTimestampTypes(): void
29 {
30 $context = (new Platform())->context(new LanguageProfile(GrammarRelease::PostgreSql172), null, [], true);
31 self::assertEquals(new Known(Builtin::Timestamptz), (new PredicateTyping())->zone($context, new Known(Builtin::Timestamp), new Known(Builtin::Text)));
32 }
33
34
35 public function testStringReadsVarcharAsText(): void
36 {
37 self::assertSame([Builtin::Text, Builtin::Name, null], [(new PredicateTyping())->string(new Known(Builtin::Varchar)), (new PredicateTyping())->string(new Known(Builtin::Name)), (new PredicateTyping())->string(new Known(Builtin::Bytea))]);
38 }
39}
40