packages/sql-fixture/tests/Unit/Schema/SchemaParseExceptionTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Schema;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Test;
9use PHPUnit\Framework\TestCase;
10use SqlFixture\Schema\SchemaParseException;
11
12#[CoversClass(SchemaParseException::class)]
13#[\PHPUnit\Framework\Attributes\UsesClass(\SqlFixture\Schema\Exception\InvalidSqlException::class)]
14#[\PHPUnit\Framework\Attributes\UsesClass(\SqlFixture\Schema\Exception\ExpectedCreateTableException::class)]
15#[\PHPUnit\Framework\Attributes\UsesClass(\SqlFixture\Schema\Exception\MissingColumnDefinitionsException::class)]
16final class SchemaParseExceptionTest extends TestCase
17{
18    #[Test]
19    public function testInvalidSql(): void
20    {
21        $exception = new \SqlFixture\Schema\Exception\InvalidSqlException('SELECT 1', 'Not a CREATE TABLE');
22        self::assertSame('Failed to parse SQL: Not a CREATE TABLE. SQL: SELECT 1', $exception->getMessage());
23    }
24
25    #[Test]
26    public function testNotCreateTable(): void
27    {
28        $exception = new \SqlFixture\Schema\Exception\ExpectedCreateTableException('SELECT 1');
29        self::assertSame('Expected CREATE TABLE statement, got: SELECT 1', $exception->getMessage());
30    }
31
32    #[Test]
33    public function testNoColumns(): void
34    {
35        $exception = new \SqlFixture\Schema\Exception\MissingColumnDefinitionsException('users');
36        self::assertSame('No columns found in table: users', $exception->getMessage());
37    }
38}
39