|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\DBAL; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\DBAL\DBALException; |
|
6
|
|
|
use Doctrine\DBAL\Driver; |
|
7
|
|
|
use Doctrine\DBAL\Driver\DriverException as InnerDriverException; |
|
8
|
|
|
use Doctrine\DBAL\Exception\DriverException; |
|
9
|
|
|
use Doctrine\Tests\DbalTestCase; |
|
10
|
|
|
use Exception; |
|
11
|
|
|
use stdClass; |
|
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(), '', ['ABC', chr(128)]); |
|
23
|
|
|
self::assertStringContainsString('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 = DBALException::driverExceptionDuringQuery($driver, new Exception(), 'INSERT INTO file (`content`) VALUES (?)', [1 => fopen(__FILE__, 'r')]); |
|
31
|
|
|
self::assertStringContainsString('Resource', $e->getMessage()); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function testAvoidOverWrappingOnDriverException() |
|
35
|
|
|
{ |
|
36
|
|
|
/** @var Driver $driver */ |
|
37
|
|
|
$driver = $this->createMock(Driver::class); |
|
38
|
|
|
|
|
39
|
|
|
/** @var InnerDriverException $inner */ |
|
40
|
|
|
$inner = $this->createMock(InnerDriverException::class); |
|
41
|
|
|
|
|
42
|
|
|
$ex = new DriverException('', $inner); |
|
43
|
|
|
$e = DBALException::driverExceptionDuringQuery($driver, $ex, ''); |
|
44
|
|
|
self::assertSame($ex, $e); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function testDriverRequiredWithUrl() |
|
48
|
|
|
{ |
|
49
|
|
|
$url = 'mysql://localhost'; |
|
50
|
|
|
$exception = DBALException::driverRequired($url); |
|
51
|
|
|
|
|
52
|
|
|
self::assertInstanceOf(DBALException::class, $exception); |
|
53
|
|
|
self::assertSame( |
|
54
|
|
|
sprintf( |
|
55
|
|
|
"The options 'driver' or 'driverClass' are mandatory if a connection URL without scheme " . |
|
56
|
|
|
'is given to DriverManager::getConnection(). Given URL: %s', |
|
57
|
|
|
$url |
|
58
|
|
|
), |
|
59
|
|
|
$exception->getMessage() |
|
60
|
|
|
); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @group #2821 |
|
65
|
|
|
*/ |
|
66
|
|
|
public function testInvalidPlatformTypeObject() : void |
|
67
|
|
|
{ |
|
68
|
|
|
$exception = DBALException::invalidPlatformType(new stdClass()); |
|
69
|
|
|
|
|
70
|
|
|
self::assertSame( |
|
71
|
|
|
"Option 'platform' must be a subtype of 'Doctrine\DBAL\Platforms\AbstractPlatform', instance of 'stdClass' given", |
|
72
|
|
|
$exception->getMessage() |
|
73
|
|
|
); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @group #2821 |
|
78
|
|
|
*/ |
|
79
|
|
|
public function testInvalidPlatformTypeScalar() : void |
|
80
|
|
|
{ |
|
81
|
|
|
$exception = DBALException::invalidPlatformType('some string'); |
|
82
|
|
|
|
|
83
|
|
|
self::assertSame( |
|
84
|
|
|
"Option 'platform' must be an object and subtype of 'Doctrine\DBAL\Platforms\AbstractPlatform'. Got 'string'", |
|
85
|
|
|
$exception->getMessage() |
|
86
|
|
|
); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|