packages/ztd-query-postgres/tests/Unit/Shadow/Mutation/Upsert/Expression/ComparisonOperatorTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Shadow\Mutation\Upsert\Expression;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\TestCase;
9
10#[CoversClass(\ZtdQuery\Platform\Postgres\Shadow\Mutation\Upsert\Expression\ComparisonOperator::class)]
11#[\PHPUnit\Framework\Attributes\UsesClass(\ZtdQuery\Platform\Postgres\Shadow\Mutation\Upsert\Expression\ExpressionCursor::class)]
12#[\PHPUnit\Framework\Attributes\UsesClass(\ZtdQuery\Platform\Postgres\Shadow\Mutation\Upsert\Expression\ExpressionLexeme::class)]
13#[\PHPUnit\Framework\Attributes\UsesClass(\ZtdQuery\Platform\Postgres\Sql\PgSqlLexerProfile::class)]
14final class ComparisonOperatorTest extends TestCase
15{
16    public function testComparisonOperatorConsumesBothCharacters(): void
17    {
18        $sql = '>= 2';
19        $tokens = \ZtdQuery\Sql\SqlTokenStream::tokenize($sql, \ZtdQuery\Platform\Postgres\Sql\PgSqlLexerProfile::create())->significantTokens();
20        $cursor = new \ZtdQuery\Platform\Postgres\Shadow\Mutation\Upsert\Expression\ExpressionCursor($sql, 'users', $tokens);
21        self::assertSame(\ZtdQuery\Shadow\Mutation\UpsertExpressionKind::GreaterOrEqual, (new \ZtdQuery\Platform\Postgres\Shadow\Mutation\Upsert\Expression\ComparisonOperator($cursor))->comparisonOperator());
22        self::assertSame(2, $cursor->index);
23    }
24
25    public function testComparisonOperatorLeavesOtherTokensUntouched(): void
26    {
27        $sql = 'word';
28        $tokens = \ZtdQuery\Sql\SqlTokenStream::tokenize($sql, \ZtdQuery\Platform\Postgres\Sql\PgSqlLexerProfile::create())->significantTokens();
29        $cursor = new \ZtdQuery\Platform\Postgres\Shadow\Mutation\Upsert\Expression\ExpressionCursor($sql, 'users', $tokens);
30        self::assertNull((new \ZtdQuery\Platform\Postgres\Shadow\Mutation\Upsert\Expression\ComparisonOperator($cursor))->comparisonOperator());
31        self::assertSame(0, $cursor->index);
32    }
33}
34