packages/ztd-query-postgres/tests/Unit/Sql/Sampling/PgSqlTableSampleTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Sql\Sampling;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\TestCase;
9use ZtdQuery\Platform\Postgres\Sql\Sampling\PgSqlTableSample;
10use ZtdQuery\Platform\Postgres\Sql\Sampling\PgSqlTableSampleMethod;
11
12#[CoversClass(PgSqlTableSample::class)]
13#[\PHPUnit\Framework\Attributes\UsesClass(PgSqlTableSampleMethod::class)]
14final class PgSqlTableSampleTest extends TestCase
15{
16    public function testStoresParsedSampleFields(): void
17    {
18        $sample = new PgSqlTableSample(
19            'data',
20            'public.data',
21            'AS sampled',
22            PgSqlTableSampleMethod::Bernoulli,
23            '$1',
24            '42.5',
25            14,
26            78,
27        );
28
29        self::assertSame('data', $sample->tableName);
30        self::assertSame('public.data', $sample->sourceSql);
31        self::assertSame('AS sampled', $sample->aliasSql);
32        self::assertSame(PgSqlTableSampleMethod::Bernoulli, $sample->method);
33        self::assertSame('$1', $sample->percentageSql);
34        self::assertSame('42.5', $sample->seedSql);
35        self::assertSame(14, $sample->startOffset);
36        self::assertSame(78, $sample->endOffset);
37    }
38
39
40
41
42
43
44
45
46
47
48
49    public function testAcceptsZeroStartOffset(): void
50    {
51        $sample = new PgSqlTableSample('data', 'data', '', PgSqlTableSampleMethod::System, '10', null, 0, 1);
52
53        self::assertSame(0, $sample->startOffset);
54    }
55}
56