Passed
Push — master ( 0a7ead...c8e6c9 )
by Michael
10:47 queued 02:29
created

DBALExceptionTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 82
Duplicated Lines 35.37 %

Importance

Changes 0
Metric Value
wmc 6
dl 29
loc 82
rs 10
c 0
b 0
f 0

12 Methods

Rating   Name   Duplication   Size   Complexity  
testInvalidPlatformTypeScalar() 0 7 ?
testAvoidOverWrappingOnDriverException() 0 23 ?
A hp$0 ➔ testInvalidPlatformTypeObject() 0 7 1
A hp$0 ➔ testInvalidPlatformTypeScalar() 0 7 1
A hp$0 ➔ testDriverRequiredWithUrl() 13 13 1
A hp$0 ➔ getSQLState() 0 2 1
A hp$0 ➔ testAvoidOverWrappingOnDriverException() 0 23 1
A testDriverExceptionDuringQueryAcceptsBinaryData() 6 6 1
testInvalidPlatformTypeObject() 0 7 ?
testDriverRequiredWithUrl() 13 13 ?
A testDriverExceptionDuringQueryAcceptsResource() 6 6 1
A hp$0 ➔ getErrorCode() 0 2 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
11
class DBALExceptionTest extends DbalTestCase
12
{
13 View Code Duplication
    public function testDriverExceptionDuringQueryAcceptsBinaryData()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
14
    {
15
        /* @var $driver Driver */
16
        $driver = $this->createMock(Driver::class);
17
        $e = DBALException::driverExceptionDuringQuery($driver, new \Exception, '', array('ABC', chr(128)));
18
        self::assertContains('with params ["ABC", "\x80"]', $e->getMessage());
19
    }
20
    
21 View Code Duplication
    public function testDriverExceptionDuringQueryAcceptsResource()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
22
    {
23
        /* @var $driver Driver */
24
        $driver = $this->createMock(Driver::class);
25
        $e = \Doctrine\DBAL\DBALException::driverExceptionDuringQuery($driver, new \Exception, "INSERT INTO file (`content`) VALUES (?)", [1 => fopen(__FILE__, 'r')]);
26
        self::assertContains('Resource', $e->getMessage());
27
    }
28
29
    public function testAvoidOverWrappingOnDriverException()
30
    {
31
        /* @var $driver Driver */
32
        $driver = $this->createMock(Driver::class);
33
        $inner = new class extends \Exception implements InnerDriverException
34
        {
35
            /**
36
             * {@inheritDoc}
37
             */
38
            public function getErrorCode()
39
            {
40
            }
41
42
            /**
43
             * {@inheritDoc}
44
             */
45
            public function getSQLState()
46
            {
47
            }
48
        };
49
        $ex = new DriverException('', $inner);
50
        $e = DBALException::driverExceptionDuringQuery($driver, $ex, '');
51
        self::assertSame($ex, $e);
52
    }
53
54 View Code Duplication
    public function testDriverRequiredWithUrl()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
55
    {
56
        $url = 'mysql://localhost';
57
        $exception = DBALException::driverRequired($url);
58
59
        self::assertInstanceOf(DBALException::class, $exception);
60
        self::assertSame(
61
            sprintf(
62
                "The options 'driver' or 'driverClass' are mandatory if a connection URL without scheme " .
63
                'is given to DriverManager::getConnection(). Given URL: %s',
64
                $url
65
            ),
66
            $exception->getMessage()
67
        );
68
    }
69
70
    /**
71
     * @group #2821
72
     */
73
    public function testInvalidPlatformTypeObject(): void
74
    {
75
        $exception = DBALException::invalidPlatformType(new \stdClass());
76
77
        self::assertSame(
78
            "Option 'platform' must be a subtype of 'Doctrine\DBAL\Platforms\AbstractPlatform', instance of 'stdClass' given",
79
            $exception->getMessage()
80
        );
81
    }
82
83
    /**
84
     * @group #2821
85
     */
86
    public function testInvalidPlatformTypeScalar(): void
87
    {
88
        $exception = DBALException::invalidPlatformType('some string');
89
90
        self::assertSame(
91
            "Option 'platform' must be an object and subtype of 'Doctrine\DBAL\Platforms\AbstractPlatform'. Got 'string'",
92
            $exception->getMessage()
93
        );
94
    }
95
}
96