packages/ztd-query-mysqli-adapter/tests/Unit/ZtdMysqliExceptionTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit;
6
7use Exception;
8use PHPUnit\Framework\Attributes\CoversClass;
9use PHPUnit\Framework\TestCase;
10use ZtdQuery\Adapter\Mysqli\ZtdMysqliException;
11
12#[CoversClass(ZtdMysqliException::class)]
13final class ZtdMysqliExceptionTest extends TestCase
14{
15    public function testExtendsRuntimeException(): void
16    {
17        $exception = new ZtdMysqliException('test');
18
19        self::assertSame('test', $exception->getMessage());
20    }
21
22    public function testMessageAndCode(): void
23    {
24        $exception = new ZtdMysqliException('Something went wrong', 42);
25
26        self::assertSame('Something went wrong', $exception->getMessage());
27        self::assertSame(42, $exception->getCode());
28    }
29
30    public function testPreviousException(): void
31    {
32        $previous = new Exception('original');
33        $exception = new ZtdMysqliException('wrapped', 0, $previous);
34
35        self::assertSame($previous, $exception->getPrevious());
36    }
37
38    public function testDefaultCodeIsZero(): void
39    {
40        $exception = new ZtdMysqliException('test');
41
42        self::assertSame(0, $exception->getCode());
43    }
44
45    public function testDefaultPreviousIsNull(): void
46    {
47        $exception = new ZtdMysqliException('test');
48
49        self::assertNull($exception->getPrevious());
50    }
51}
52