packages/ztd-query-core/tests/Unit/Shadow/Row/RowPairingTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Shadow\Row;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\UsesClass;
9use PHPUnit\Framework\TestCase;
10use ZtdQuery\Shadow\Row\RowChange;
11use ZtdQuery\Shadow\Row\RowPairing;
12
13#[CoversClass(RowPairing::class)]
14#[UsesClass(RowChange::class)]
15final class RowPairingTest extends TestCase
16{
17    public function testPairRecordsBothPositionsAndTheChangeWhereTheRowsDiffer(): void
18    {
19        $pairing = new RowPairing();
20
21        $pairing->pair(0, 2, ['id' => 1], ['id' => 2]);
22
23        self::assertSame(
24            [[0], [2], [[['id' => 1], ['id' => 2]]]],
25            [
26                $pairing->beforePositions(),
27                $pairing->afterPositions(),
28                [[$pairing->changes()[0]->before, $pairing->changes()[0]->after]],
29            ],
30        );
31    }
32
33    public function testPairRecordsNoChangeWhereTheRowIsWhatItWas(): void
34    {
35        $pairing = new RowPairing();
36
37        $pairing->pair(0, 0, ['id' => 1], ['id' => 1]);
38
39        self::assertSame([[0], []], [$pairing->beforePositions(), $pairing->changes()]);
40    }
41
42    public function testBeforePositionsAnswersNothingWhereNothingWasPaired(): void
43    {
44        self::assertSame([], (new RowPairing())->beforePositions());
45    }
46
47    public function testAfterPositionsAnswersNothingWhereNothingWasPaired(): void
48    {
49        self::assertSame([], (new RowPairing())->afterPositions());
50    }
51
52    public function testChangesAnswersNothingWhereNothingWasPaired(): void
53    {
54        self::assertSame([], (new RowPairing())->changes());
55    }
56}
57