packages/sql-fixture/tests/Unit/Plan/Exception/DuplicateColumnBindingExceptionTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Plan\Exception;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\UsesClass;
9use PHPUnit\Framework\TestCase;
10use SqlFixture\Plan\ColumnRef;
11
12#[CoversClass(\SqlFixture\Plan\Exception\DuplicateColumnBindingException::class)]
13#[UsesClass(ColumnRef::class)]
14#[UsesClass(\SqlFixture\Plan\PlanStructureException::class)]
15#[UsesClass(\SqlFixture\Plan\Exception\CyclicDependencyException::class)]
16#[UsesClass(\SqlFixture\Plan\Exception\UnboundedSelfReferenceException::class)]
17final class DuplicateColumnBindingExceptionTest extends TestCase
18{
19    public function testDescribesDuplicateColumnBinding(): void
20    {
21        $exception = new \SqlFixture\Plan\Exception\DuplicateColumnBindingException(
22            ColumnRef::of('b', 'x'),
23            ColumnRef::of('a', 'id'),
24            ColumnRef::of('c', 'id')
25        );
26        $message = $exception->getMessage();
27
28        self::assertSame(
29            'b.x is bound to a.id and to c.id. A column can reference one parent, so one of '
30            . 'the two relations has to go.',
31            $message
32        );
33        self::assertEquals(ColumnRef::of('b', 'x'), $exception->child);
34        self::assertEquals(ColumnRef::of('a', 'id'), $exception->first);
35        self::assertEquals(ColumnRef::of('c', 'id'), $exception->second);
36    }
37}
38