packages/ztd-query-core/tests/Unit/Exception/UnsupportedSqlExceptionTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Exception;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\TestCase;
9use ZtdQuery\Exception\UnsupportedSqlException;
10
11#[CoversClass(UnsupportedSqlException::class)]
12final class UnsupportedSqlExceptionTest extends TestCase
13{
14    public function testGetMessageReturnsFormattedMessage(): void
15    {
16        $exception = new UnsupportedSqlException(
17            'GRANT SELECT ON users TO admin',
18            'DCL'
19        );
20
21        self::assertSame('ZTD Write Protection: DCL SQL statement.', $exception->getMessage());
22    }
23
24    public function testGetMessageWithDefaultCategory(): void
25    {
26        $exception = new UnsupportedSqlException('SOME UNSUPPORTED SQL');
27
28        self::assertSame('ZTD Write Protection: Unsupported SQL statement.', $exception->getMessage());
29    }
30
31    public function testGetSqlReturnsOriginalSql(): void
32    {
33        $sql = 'GRANT SELECT ON users TO admin';
34        $exception = new UnsupportedSqlException($sql, 'DCL');
35
36        self::assertSame($sql, $exception->getSql());
37    }
38
39    public function testGetCategoryReturnsCategory(): void
40    {
41        $exception = new UnsupportedSqlException('sql', 'DCL');
42
43        self::assertSame('DCL', $exception->getCategory());
44    }
45
46    public function testGetCategoryReturnsDefaultCategory(): void
47    {
48        $exception = new UnsupportedSqlException('sql');
49
50        self::assertSame('Unsupported', $exception->getCategory());
51    }
52
53}
54