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