Completed
Push — master ( c7757e...39cb21 )
by Luís
16s
created

Doctrine/Tests/DBAL/Driver/PDOExceptionTest.php (1 issue)

1
<?php
2
3
namespace Doctrine\Tests\DBAL\Driver;
4
5
use Doctrine\DBAL\Driver\PDOException;
6
use Doctrine\Tests\DbalTestCase;
7
8
class PDOExceptionTest extends DbalTestCase
9
{
10
    const ERROR_CODE = 666;
11
12
    const MESSAGE = 'PDO Exception';
13
14
    const SQLSTATE = 28000;
15
16
    /**
17
     * The PDO exception wrapper under test.
18
     *
19
     * @var \Doctrine\DBAL\Driver\PDOException
20
     */
21
    private $exception;
22
23
    /**
24
     * The wrapped PDO exception mock.
25
     *
26
     * @var \PDOException|\PHPUnit_Framework_MockObject_MockObject
27
     */
28
    private $wrappedException;
29
30
    protected function setUp()
31
    {
32
        if ( ! extension_loaded('PDO')) {
33
            $this->markTestSkipped('PDO is not installed.');
34
        }
35
36
        parent::setUp();
37
38
        $this->wrappedException = new \PDOException(self::MESSAGE, self::SQLSTATE);
0 ignored issues
show
The call to PDOException::__construct() has too few arguments starting with previous. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

38
        $this->wrappedException = /** @scrutinizer ignore-call */ new \PDOException(self::MESSAGE, self::SQLSTATE);

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
39
40
        $this->wrappedException->errorInfo = array(self::SQLSTATE, self::ERROR_CODE);
41
42
        $this->exception = new PDOException($this->wrappedException);
43
    }
44
45
    public function testReturnsCode()
46
    {
47
        self::assertSame(self::SQLSTATE, $this->exception->getCode());
48
    }
49
50
    public function testReturnsErrorCode()
51
    {
52
        self::assertSame(self::ERROR_CODE, $this->exception->getErrorCode());
53
    }
54
55
    public function testReturnsMessage()
56
    {
57
        self::assertSame(self::MESSAGE, $this->exception->getMessage());
58
    }
59
60
    public function testReturnsSQLState()
61
    {
62
        self::assertSame(self::SQLSTATE, $this->exception->getSQLState());
63
    }
64
65
    public function testOriginalExceptionIsInChain()
66
    {
67
        self::assertSame($this->wrappedException, $this->exception->getPrevious());
68
    }
69
}
70