packages/ztd-query-core/tests/Unit/Shadow/Mutation/Upsert/UpsertColumnTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Shadow\Mutation\Upsert;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\UsesClass;
9use PHPUnit\Framework\TestCase;
10use ZtdQuery\Exception\UnsupportedSqlException;
11use ZtdQuery\Shadow\Mutation\Upsert\UpsertColumn;
12
13#[CoversClass(UpsertColumn::class)]
14#[UsesClass(UnsupportedSqlException::class)]
15final class UpsertColumnTest extends TestCase
16{
17    public function testOfAnswersWhatTheRowCarriesUnderTheName(): void
18    {
19        self::assertSame(7, (new UpsertColumn())->of(['id' => 7], 'id'));
20    }
21
22    public function testOfDoesNotMindHowTheNameWasCased(): void
23    {
24        self::assertSame(7, (new UpsertColumn())->of(['ID' => 7], 'id'));
25    }
26
27    public function testOfAnswersANullTheRowActuallyCarries(): void
28    {
29        self::assertNull((new UpsertColumn())->of(['note' => null], 'note'));
30    }
31
32    public function testOfRefusesANameTheRowAnswersToInNoCasing(): void
33    {
34        $this->expectException(UnsupportedSqlException::class);
35
36        (new UpsertColumn())->of(['id' => 7], 'total');
37    }
38
39    public function testOfNamesTheColumnItRefused(): void
40    {
41        try {
42            (new UpsertColumn())->of(['id' => 7], 'total');
43        } catch (UnsupportedSqlException $refusal) {
44            self::assertSame('unknown UPSERT column total', $refusal->getSql());
45
46            return;
47        }
48
49        self::fail('Reading a column the row does not carry was expected to be refused.');
50    }
51}
52