Completed
Push — master ( 09e072...c7757e )
by Luís
15s
created

getExceptionConversionData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 74
Code Lines 62

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 74
rs 9.0335
c 0
b 0
f 0
cc 1
eloc 62
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Doctrine\Tests\DBAL\Driver;
4
5
use Doctrine\DBAL\Connection;
6
use Doctrine\DBAL\Platforms\MySqlPlatform;
7
use Doctrine\DBAL\Schema\MySqlSchemaManager;
8
9
class AbstractMySQLDriverTest extends AbstractDriverTest
10
{
11
    public function testReturnsDatabaseName()
12
    {
13
        parent::testReturnsDatabaseName();
14
15
        $database = 'bloo';
16
        $params   = array(
17
            'user'     => 'foo',
18
            'password' => 'bar',
19
        );
20
21
        $statement = $this->createMock('Doctrine\Tests\Mocks\DriverResultStatementMock');
22
23
        $statement->expects($this->once())
24
            ->method('fetchColumn')
25
            ->will($this->returnValue($database));
26
27
        $connection = $this->getConnectionMock();
28
29
        $connection->expects($this->once())
30
            ->method('getParams')
31
            ->will($this->returnValue($params));
32
33
        $connection->expects($this->once())
34
            ->method('query')
35
            ->will($this->returnValue($statement));
36
37
        self::assertSame($database, $this->driver->getDatabase($connection));
38
    }
39
40
    protected function createDriver()
41
    {
42
        return $this->getMockForAbstractClass('Doctrine\DBAL\Driver\AbstractMySQLDriver');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getMockFor...r\AbstractMySQLDriver') returns the type PHPUnit_Framework_MockObject_MockObject which is incompatible with the return type mandated by Doctrine\Tests\DBAL\Driv...verTest::createDriver() of Doctrine\DBAL\Driver.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
43
    }
44
45
    protected function createPlatform()
46
    {
47
        return new MySqlPlatform();
48
    }
49
50
    protected function createSchemaManager(Connection $connection)
51
    {
52
        return new MySqlSchemaManager($connection);
53
    }
54
55
    protected function getDatabasePlatformsForVersions()
56
    {
57
        return array(
58
            array('5.6.9', 'Doctrine\DBAL\Platforms\MySqlPlatform'),
59
            array('5.7', 'Doctrine\DBAL\Platforms\MySQL57Platform'),
60
            array('5.7.0', 'Doctrine\DBAL\Platforms\MySqlPlatform'),
61
            array('5.7.8', 'Doctrine\DBAL\Platforms\MySqlPlatform'),
62
            array('5.7.9', 'Doctrine\DBAL\Platforms\MySQL57Platform'),
63
            array('5.7.10', 'Doctrine\DBAL\Platforms\MySQL57Platform'),
64
            array('6', 'Doctrine\DBAL\Platforms\MySQL57Platform'),
65
            array('10.0.15-MariaDB-1~wheezy', 'Doctrine\DBAL\Platforms\MySqlPlatform'),
66
            array('10.1.2a-MariaDB-a1~lenny-log', 'Doctrine\DBAL\Platforms\MySqlPlatform'),
67
            array('5.5.40-MariaDB-1~wheezy', 'Doctrine\DBAL\Platforms\MySqlPlatform'),
68
        );
69
    }
70
71
    protected function getExceptionConversionData()
72
    {
73
        return array(
74
            self::EXCEPTION_CONNECTION => array(
75
                array('1044', null, null),
76
                array('1045', null, null),
77
                array('1046', null, null),
78
                array('1049', null, null),
79
                array('1095', null, null),
80
                array('1142', null, null),
81
                array('1143', null, null),
82
                array('1227', null, null),
83
                array('1370', null, null),
84
                array('2002', null, null),
85
                array('2005', null, null),
86
            ),
87
            self::EXCEPTION_FOREIGN_KEY_CONSTRAINT_VIOLATION => array(
88
                array('1216', null, null),
89
                array('1217', null, null),
90
                array('1451', null, null),
91
                array('1452', null, null),
92
            ),
93
            self::EXCEPTION_INVALID_FIELD_NAME => array(
94
                array('1054', null, null),
95
                array('1166', null, null),
96
                array('1611', null, null),
97
            ),
98
            self::EXCEPTION_NON_UNIQUE_FIELD_NAME => array(
99
                array('1052', null, null),
100
                array('1060', null, null),
101
                array('1110', null, null),
102
            ),
103
            self::EXCEPTION_NOT_NULL_CONSTRAINT_VIOLATION => array(
104
                array('1048', null, null),
105
                array('1121', null, null),
106
                array('1138', null, null),
107
                array('1171', null, null),
108
                array('1252', null, null),
109
                array('1263', null, null),
110
                array('1364', null, null),
111
                array('1566', null, null),
112
            ),
113
            self::EXCEPTION_SYNTAX_ERROR => array(
114
                array('1064', null, null),
115
                array('1149', null, null),
116
                array('1287', null, null),
117
                array('1341', null, null),
118
                array('1342', null, null),
119
                array('1343', null, null),
120
                array('1344', null, null),
121
                array('1382', null, null),
122
                array('1479', null, null),
123
                array('1541', null, null),
124
                array('1554', null, null),
125
                array('1626', null, null),
126
            ),
127
            self::EXCEPTION_TABLE_EXISTS => array(
128
                array('1050', null, null),
129
            ),
130
            self::EXCEPTION_TABLE_NOT_FOUND => array(
131
                array('1051', null, null),
132
                array('1146', null, null),
133
            ),
134
            self::EXCEPTION_UNIQUE_CONSTRAINT_VIOLATION => array(
135
                array('1062', null, null),
136
                array('1557', null, null),
137
                array('1569', null, null),
138
                array('1586', null, null),
139
            ),
140
            self::EXCEPTION_DEADLOCK => array(
141
                array('1213', null, null),
142
            ),
143
            self::EXCEPTION_LOCK_WAIT_TIMEOUT => array(
144
                array('1205', null, null),
145
            ),
146
        );
147
    }
148
}
149