packages/sql-semantics-postgres/tests/Unit/Rules/Invocation/CoalescingTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Rules\Invocation;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Small;
9use PHPUnit\Framework\TestCase;
10use SqlSemantics\Platform\PostgreSql\Model\Statement\Fact\ScalarFact;
11use SqlSemantics\Platform\PostgreSql\Model\Statement\Type\Known;
12use SqlSemantics\Platform\PostgreSql\Model\Statement\Type\Nullability;
13use SqlSemantics\Platform\PostgreSql\Model\Statement\Type\NullOnly;
14use SqlSemantics\Platform\PostgreSql\Rules\Invocation\Coalescing;
15use SqlSemantics\Platform\PostgreSql\Statement\Type\Descriptor\Builtin;
16
17#[CoversClass(Coalescing::class)]
18#[Small]
19final class CoalescingTest extends TestCase
20{
21    public function testNullabilityIsNotNullWhenAnOperandIsNotNull(): void
22    {
23        $coalescing = new Coalescing();
24        self::assertSame(Nullability::NotNull, $coalescing->nullability([new ScalarFact(new NullOnly(), Nullability::NotNull), new ScalarFact(new Known(Builtin::Int4), Nullability::NotNull)]));
25        self::assertSame(Nullability::Nullable, $coalescing->nullability([new ScalarFact(new Known(Builtin::Int4), Nullability::Nullable)]));
26        self::assertSame(Nullability::Dependent, $coalescing->nullability([new ScalarFact(new Known(Builtin::Int4), Nullability::Nullable), new ScalarFact(new Known(Builtin::Int4), Nullability::Dependent)]));
27    }
28}
29