packages/ztd-query-postgres/tests/Unit/Sql/Partition/BoundPredicateTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Sql\Partition;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\TestCase;
9
10#[CoversClass(\ZtdQuery\Platform\Postgres\Sql\Partition\BoundPredicate::class)]
11#[\PHPUnit\Framework\Attributes\UsesClass(\ZtdQuery\Platform\Postgres\Sql\PgSqlLexerProfile::class)]
12#[\PHPUnit\Framework\Attributes\UsesClass(\ZtdQuery\Platform\Postgres\Sql\Partition\ClauseTokens::class)]
13final class BoundPredicateTest extends TestCase
14{
15 public function testRangePredicate(): void
16 {
17 $sql = 'FROM (10) TO (20)';
18 $stream = \ZtdQuery\Sql\SqlTokenStream::tokenize($sql, \ZtdQuery\Platform\Postgres\Sql\PgSqlLexerProfile::create());
19 $tokens = $stream->significantTokens();
20 $key = new \ZtdQuery\Schema\Partition\TablePartitionKey(\ZtdQuery\Schema\Partition\TablePartitionStrategy::Range, ['id']);
21
22 self::assertSame('(id) >= 10 AND (id) < 20', (new \ZtdQuery\Platform\Postgres\Sql\Partition\BoundPredicate())->rangePredicate($sql, $tokens, 0, $key));
23 }
24
25 public function testListPredicate(): void
26 {
27 $sql = 'IN (1, 2, NULL)';
28 $stream = \ZtdQuery\Sql\SqlTokenStream::tokenize($sql, \ZtdQuery\Platform\Postgres\Sql\PgSqlLexerProfile::create());
29 $tokens = $stream->significantTokens();
30 $key = new \ZtdQuery\Schema\Partition\TablePartitionKey(\ZtdQuery\Schema\Partition\TablePartitionStrategy::Range, ['id']);
31
32 self::assertSame('((id) IN (1, 2) OR (id) IS NULL)', (new \ZtdQuery\Platform\Postgres\Sql\Partition\BoundPredicate())->listPredicate($sql, $tokens, 0, $key));
33 }
34
35 public function testRangeBoundary(): void
36 {
37 self::assertSame('(id) >= 10', (new \ZtdQuery\Platform\Postgres\Sql\Partition\BoundPredicate())->rangeBoundary(['id'], ['10'], '>=', 'MINVALUE'));
38 }
39}
40