packages/ztd-query-core/tests/Unit/Shadow/Mutation/Row/ResultSetMutationTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Shadow\Mutation\Row;
6
7use PHPUnit\Framework\Attributes\CoversNothing;
8use PHPUnit\Framework\TestCase;
9use ZtdQuery\Connection\ResultColumn;
10use ZtdQuery\Connection\ResultSet;
11use ZtdQuery\Schema\ColumnDeclaration;
12use ZtdQuery\Schema\ColumnTypeFamily;
13use ZtdQuery\Schema\TableDefinitionRegistry;
14use ZtdQuery\Shadow\Mutation\Table\CreateTableAsSelectMutation;
15use ZtdQuery\Shadow\ShadowStore;
16
17#[CoversNothing]
18final class ResultSetMutationTest extends TestCase
19{
20 public function testApplyResultSetGivesTheNewTableTheColumnsTheResultDescribed(): void
21 {
22 $registry = new TableDefinitionRegistry();
23 $mutation = new CreateTableAsSelectMutation(
24 'copy',
25 [],
26 $registry,
27 new ColumnDeclaration(ColumnTypeFamily::TEXT, 'fixture_text'),
28 );
29
30 $mutation->applyResultSet(new ShadowStore(), new ResultSet(
31 [],
32 [new ResultColumn('id', new ColumnDeclaration(ColumnTypeFamily::INTEGER, 'BIGINT'))],
33 ));
34
35 self::assertSame(['id'], $registry->get('copy')?->columns);
36 }
37
38 public function testApplyResultSetGivesTheNewTableTheRowsTheResultCarried(): void
39 {
40 $store = new ShadowStore();
41 $mutation = new CreateTableAsSelectMutation(
42 'copy',
43 ['id'],
44 new TableDefinitionRegistry(),
45 new ColumnDeclaration(ColumnTypeFamily::TEXT, 'fixture_text'),
46 );
47
48 $mutation->applyResultSet($store, new ResultSet([['id' => 1], ['id' => 2]], []));
49
50 self::assertSame([['id' => 1], ['id' => 2]], $store->get('copy'));
51 }
52}
53