Passed
Push — master ( 047d0e...5cefa4 )
by Marco
06:53
created

DBALExceptionTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 29.41 %

Importance

Changes 0
Metric Value
wmc 4
dl 15
loc 51
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A hp$0 ➔ getErrorCode() 0 3 1
A hp$0 ➔ getSQLState() 0 3 1
A testDriverExceptionDuringQueryAcceptsBinaryData() 0 7 1
B testAvoidOverWrappingOnDriverException() 0 24 1
A testDriverRequiredWithUrl() 15 15 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
    public function testDriverExceptionDuringQueryAcceptsBinaryData()
14
    {
15
        /* @var $driver Driver */
16
        $driver = $this->createMock(Driver::class);
17
        $e = DBALException::driverExceptionDuringQuery($driver, new \Exception, '', array('ABC', chr(128)));
18
        $this->assertContains('with params ["ABC", "\x80"]', $e->getMessage());
19
    }
20
21
    public function testAvoidOverWrappingOnDriverException()
22
    {
23
        /* @var $driver Driver */
24
        $driver = $this->createMock(Driver::class);
25
        $inner = new class extends \Exception implements InnerDriverException
26
        {
27
            /**
28
             * {@inheritDoc}
29
             */
30
            public function getErrorCode()
31
            {
32
            }
33
34
            /**
35
             * {@inheritDoc}
36
             */
37
            public function getSQLState()
38
            {
39
            }
40
        };
41
        $ex = new DriverException('', $inner);
42
        $e = DBALException::driverExceptionDuringQuery($driver, $ex, '');
43
        $this->assertSame($ex, $e);
44
    }
45
46 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...
47
    {
48
        $url = 'mysql://localhost';
49
        $exception = DBALException::driverRequired($url);
50
51
        $this->assertInstanceOf(DBALException::class, $exception);
52
        $this->assertSame(
53
            sprintf(
54
                "The options 'driver' or 'driverClass' are mandatory if a connection URL without scheme " .
55
                'is given to DriverManager::getConnection(). Given URL: %s',
56
                $url
57
            ),
58
            $exception->getMessage()
59
        );
60
    }
61
}
62