Failed Conditions
Pull Request — develop (#3131)
by Michael
12:37
created

DBALExceptionTest.php$0 ➔ testDriverRequiredWithUrl()   A

Complexity

Conditions 1

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
cc 1
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