|
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() : void |
|
50
|
|
|
{ |
|
51
|
|
|
self::assertSame(self::ERROR_CODE, $this->exception->getCode()); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function testReturnsMessage() : void |
|
55
|
|
|
{ |
|
56
|
|
|
self::assertSame(self::MESSAGE, $this->exception->getMessage()); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function testReturnsSQLState() : void |
|
60
|
|
|
{ |
|
61
|
|
|
self::assertSame(self::SQLSTATE, $this->exception->getSQLState()); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function testOriginalExceptionIsInChain() : void |
|
65
|
|
|
{ |
|
66
|
|
|
self::assertSame($this->wrappedException, $this->exception->getPrevious()); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|