Completed
Push — develop ( 347d2f...361a2b )
by Marco
24s queued 13s
created

PDOExceptionTest::testReturnsErrorCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Tests\DBAL\Driver;
6
7
use Doctrine\DBAL\Driver\PDOException;
8
use Doctrine\Tests\DbalTestCase;
9
use PHPUnit\Framework\MockObject\MockObject;
10
use function extension_loaded;
11
12
class PDOExceptionTest extends DbalTestCase
13
{
14
    public const ERROR_CODE = 666;
15
16
    public const MESSAGE = 'PDO Exception';
17
18
    public const SQLSTATE = 'HY000';
19
20
    /**
21
     * The PDO exception wrapper under test.
22
     *
23
     * @var PDOException
24
     */
25
    private $exception;
26
27
    /**
28
     * The wrapped PDO exception mock.
29
     *
30
     * @var \PDOException|MockObject
31
     */
32
    private $wrappedException;
33
34
    protected function setUp() : void
35
    {
36
        if (! extension_loaded('PDO')) {
37
            $this->markTestSkipped('PDO is not installed.');
38
        }
39
40
        parent::setUp();
41
42
        $this->wrappedException = new \PDOException(self::MESSAGE);
43
44
        $this->wrappedException->errorInfo = [self::SQLSTATE, self::ERROR_CODE];
45
46
        $this->exception = new PDOException($this->wrappedException);
47
    }
48
49
    public function testReturnsCode()
50
    {
51
        self::assertSame(self::ERROR_CODE, $this->exception->getCode());
52
    }
53
54
    public function testReturnsMessage()
55
    {
56
        self::assertSame(self::MESSAGE, $this->exception->getMessage());
57
    }
58
59
    public function testReturnsSQLState()
60
    {
61
        self::assertSame(self::SQLSTATE, $this->exception->getSQLState());
62
    }
63
64
    public function testOriginalExceptionIsInChain()
65
    {
66
        self::assertSame($this->wrappedException, $this->exception->getPrevious());
67
    }
68
}
69