packages/ztd-query-core/tests/Unit/Schema/Key/CandidateKeyMatchTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Schema\Key;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\TestCase;
9use ZtdQuery\Schema\Key\CandidateKeyMatch;
10
11#[CoversClass(CandidateKeyMatch::class)]
12final class CandidateKeyMatchTest extends TestCase
13{
14 public function testOfReadsWhatTheRowCarriesInTheKeyColumns(): void
15 {
16 self::assertSame(
17 ['tenant' => 'acme', 'id' => 1],
18 (new CandidateKeyMatch())->of(['id' => 1, 'tenant' => 'acme', 'name' => 'a'], ['tenant', 'id']),
19 );
20 }
21
22 public function testOfAnswersNothingWhereTheRowLacksAKeyColumn(): void
23 {
24 self::assertNull((new CandidateKeyMatch())->of(['id' => 1], ['id', 'tenant']));
25 }
26
27 public function testOfAnswersNothingWhereTheRowLeavesAKeyColumnNull(): void
28 {
29 self::assertNull((new CandidateKeyMatch())->of(['id' => null], ['id']));
30 }
31
32 public function testOfAnswersNothingForAKeyMadeOfNoColumns(): void
33 {
34 self::assertNull((new CandidateKeyMatch())->of(['id' => 1], []));
35 }
36
37 public function testCarriedByReportsARowRepeatingEveryValue(): void
38 {
39 self::assertTrue((new CandidateKeyMatch())->carriedBy(['id' => 1], ['id' => 1, 'name' => 'a']));
40 }
41
42 public function testCarriedByReportsARowThatDiffersInOneOfThem(): void
43 {
44 self::assertFalse((new CandidateKeyMatch())->carriedBy(['id' => 1, 'tenant' => 'a'], ['id' => 1]));
45 }
46}
47