PDOExceptionTest.php 1.64 KB
Newer Older
1 2 3 4 5 6
<?php

namespace Doctrine\Tests\DBAL\Driver;

use Doctrine\DBAL\Driver\PDOException;
use Doctrine\Tests\DbalTestCase;
7
use function extension_loaded;
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28

class PDOExceptionTest extends DbalTestCase
{
    const ERROR_CODE = 666;

    const MESSAGE = 'PDO Exception';

    const SQLSTATE = 28000;

    /**
     * The PDO exception wrapper under test.
     *
     * @var \Doctrine\DBAL\Driver\PDOException
     */
    private $exception;

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

    protected function setUp()
    {
33 34 35 36
        if ( ! extension_loaded('PDO')) {
            $this->markTestSkipped('PDO is not installed.');
        }

37 38
        parent::setUp();

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

41
        $this->wrappedException->errorInfo = array(self::SQLSTATE, self::ERROR_CODE);
42

43
        $this->exception = new PDOException($this->wrappedException);
44 45 46 47
    }

    public function testReturnsCode()
    {
48
        self::assertSame(self::SQLSTATE, $this->exception->getCode());
49 50 51 52
    }

    public function testReturnsErrorCode()
    {
53
        self::assertSame(self::ERROR_CODE, $this->exception->getErrorCode());
54 55 56 57
    }

    public function testReturnsMessage()
    {
58
        self::assertSame(self::MESSAGE, $this->exception->getMessage());
59 60 61 62
    }

    public function testReturnsSQLState()
    {
63
        self::assertSame(self::SQLSTATE, $this->exception->getSQLState());
64
    }
65 66 67

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