1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\DBAL; |
4
|
|
|
|
5
|
|
|
use Doctrine\DBAL\DBALException; |
6
|
|
|
use Doctrine\DBAL\Exception\DriverException; |
7
|
|
|
use Doctrine\DBAL\Driver\DriverException as InnerDriverException; |
8
|
|
|
use Doctrine\Tests\DbalTestCase; |
9
|
|
|
use Doctrine\DBAL\Driver; |
10
|
|
|
use function chr; |
11
|
|
|
use function fopen; |
12
|
|
|
|
13
|
|
|
class DBALExceptionTest extends DbalTestCase |
14
|
|
|
{ |
15
|
|
|
public function testDriverExceptionDuringQueryAcceptsBinaryData() |
16
|
|
|
{ |
17
|
|
|
/* @var $driver Driver */ |
18
|
|
|
$driver = $this->createMock(Driver::class); |
19
|
|
|
$e = DBALException::driverExceptionDuringQuery($driver, new \Exception, '', array('ABC', chr(128))); |
20
|
|
|
self::assertContains('with params ["ABC", "\x80"]', $e->getMessage()); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function testDriverExceptionDuringQueryAcceptsResource() |
24
|
|
|
{ |
25
|
|
|
/* @var $driver Driver */ |
26
|
|
|
$driver = $this->createMock(Driver::class); |
27
|
|
|
$e = \Doctrine\DBAL\DBALException::driverExceptionDuringQuery($driver, new \Exception, "INSERT INTO file (`content`) VALUES (?)", [1 => fopen(__FILE__, 'r')]); |
28
|
|
|
self::assertContains('Resource', $e->getMessage()); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function testAvoidOverWrappingOnDriverException() |
32
|
|
|
{ |
33
|
|
|
/* @var $driver Driver */ |
34
|
|
|
$driver = $this->createMock(Driver::class); |
35
|
|
|
$inner = new class extends \Exception implements InnerDriverException |
36
|
|
|
{ |
37
|
|
|
/** |
38
|
|
|
* {@inheritDoc} |
39
|
|
|
*/ |
40
|
|
|
public function getErrorCode() |
41
|
|
|
{ |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* {@inheritDoc} |
46
|
|
|
*/ |
47
|
|
|
public function getSQLState() |
48
|
|
|
{ |
49
|
|
|
} |
50
|
|
|
}; |
51
|
|
|
$ex = new DriverException('', $inner); |
52
|
|
|
$e = DBALException::driverExceptionDuringQuery($driver, $ex, ''); |
53
|
|
|
self::assertSame($ex, $e); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|