packages/ztd-query-postgres/tests/Unit/Schema/Reflection/Key/UniqueIndexesTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Schema\Reflection\Key;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\TestCase;
9
10#[CoversClass(\ZtdQuery\Platform\Postgres\Schema\Reflection\Key\UniqueIndexes::class)]
11#[\PHPUnit\Framework\Attributes\UsesClass(\ZtdQuery\Platform\Postgres\Schema\Reflection\Key\IndexDefinitions::class)]
12#[\PHPUnit\Framework\Attributes\UsesClass(\ZtdQuery\Platform\Postgres\Schema\Reflection\Key\IndexRows::class)]
13final class UniqueIndexesTest extends TestCase
14{
15 public function testDefinitionsReconstructsThePartialIndexPredicate(): void
16 {
17 $statement = self::createStub(\ZtdQuery\Connection\StatementInterface::class);
18 $statement->method('fetchAll')->willReturn([['constraint_name' => 'active_email', 'column_name' => 'email', 'predicate' => "status = 'active'"]]);
19 $indexes = (new \ZtdQuery\Platform\Postgres\Schema\Reflection\Key\UniqueIndexes())->definitions($statement);
20 self::assertSame([], $indexes->sql);
21 self::assertSame("status = 'active'", $indexes->partialIndexes['active_email']->predicate);
22 self::assertSame([], (new \ZtdQuery\Platform\Postgres\Schema\Reflection\Key\UniqueIndexes())->definitions(false)->partialIndexes);
23 }
24}
25