PDOExceptionTest.php 1.58 KB
Newer Older
1 2
<?php

3
namespace Doctrine\DBAL\Tests\Driver;
4 5

use Doctrine\DBAL\Driver\PDOException;
6
use PHPUnit\Framework\MockObject\MockObject;
7
use PHPUnit\Framework\TestCase;
8

9 10 11
/**
 * @requires extension pdo
 */
12
class PDOExceptionTest extends TestCase
13
{
Sergei Morozov's avatar
Sergei Morozov committed
14
    public const ERROR_CODE = 666;
15

Sergei Morozov's avatar
Sergei Morozov committed
16
    public const MESSAGE = 'PDO Exception';
17

Sergei Morozov's avatar
Sergei Morozov committed
18
    public const SQLSTATE = 28000;
19 20 21 22

    /**
     * The PDO exception wrapper under test.
     *
Sergei Morozov's avatar
Sergei Morozov committed
23
     * @var PDOException
24 25 26 27 28 29
     */
    private $exception;

    /**
     * The wrapped PDO exception mock.
     *
30
     * @var \PDOException|MockObject
31
     */
32
    private $wrappedException;
33

34
    protected function setUp() : void
35 36 37
    {
        parent::setUp();

38
        $this->wrappedException = new \PDOException(self::MESSAGE, self::SQLSTATE);
39

Sergei Morozov's avatar
Sergei Morozov committed
40
        $this->wrappedException->errorInfo = [self::SQLSTATE, self::ERROR_CODE];
41

42
        $this->exception = new PDOException($this->wrappedException);
43 44
    }

45
    public function testReturnsCode() : void
46
    {
47
        self::assertSame(self::SQLSTATE, $this->exception->getCode());
48 49
    }

50
    public function testReturnsErrorCode() : void
51
    {
52
        self::assertSame(self::ERROR_CODE, $this->exception->getErrorCode());
53 54
    }

55
    public function testReturnsMessage() : void
56
    {
57
        self::assertSame(self::MESSAGE, $this->exception->getMessage());
58 59
    }

60
    public function testReturnsSQLState() : void
61
    {
62
        self::assertSame(self::SQLSTATE, $this->exception->getSQLState());
63
    }
64

65
    public function testOriginalExceptionIsInChain() : void
66
    {
67
        self::assertSame($this->wrappedException, $this->exception->getPrevious());
68
    }
69
}