Completed
Pull Request — 2.10.x (#4009)
by Grégoire
08:50
created

UtilTest::dataConvertPositionalToNamedParameters()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 55

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 55
rs 8.9818
c 0
b 0
f 0
cc 1
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;
4
5
use Doctrine\DBAL\Driver\OCI8\OCI8Statement;
6
use Doctrine\Tests\DbalTestCase;
7
8
class UtilTest extends DbalTestCase
9
{
10
    /**
11
     * @return mixed[][]
12
     */
13
    public static function dataConvertPositionalToNamedParameters() : iterable
14
    {
15
        return [
16
            [
17
                'SELECT name FROM users WHERE id = ?',
18
                'SELECT name FROM users WHERE id = :param1',
19
                [1 => ':param1'],
20
            ],
21
            [
22
                'SELECT name FROM users WHERE id = ? AND status = ?',
23
                'SELECT name FROM users WHERE id = :param1 AND status = :param2',
24
                [1 => ':param1', 2 => ':param2'],
25
            ],
26
            [
27
                "UPDATE users SET name = '???', status = ?",
28
                "UPDATE users SET name = '???', status = :param1",
29
                [1 => ':param1'],
30
            ],
31
            [
32
                "UPDATE users SET status = ?, name = '???'",
33
                "UPDATE users SET status = :param1, name = '???'",
34
                [1 => ':param1'],
35
            ],
36
            [
37
                "UPDATE users SET foo = ?, name = '???', status = ?",
38
                "UPDATE users SET foo = :param1, name = '???', status = :param2",
39
                [1 => ':param1', 2 => ':param2'],
40
            ],
41
            [
42
                'UPDATE users SET name = "???", status = ?',
43
                'UPDATE users SET name = "???", status = :param1',
44
                [1 => ':param1'],
45
            ],
46
            [
47
                'UPDATE users SET status = ?, name = "???"',
48
                'UPDATE users SET status = :param1, name = "???"',
49
                [1 => ':param1'],
50
            ],
51
            [
52
                'UPDATE users SET foo = ?, name = "???", status = ?',
53
                'UPDATE users SET foo = :param1, name = "???", status = :param2',
54
                [1 => ':param1', 2 => ':param2'],
55
            ],
56
            [
57
                'SELECT * FROM users WHERE id = ? AND name = "" AND status = ?',
58
                'SELECT * FROM users WHERE id = :param1 AND name = "" AND status = :param2',
59
                [1 => ':param1', 2 => ':param2'],
60
            ],
61
            [
62
                "SELECT * FROM users WHERE id = ? AND name = '' AND status = ?",
63
                "SELECT * FROM users WHERE id = :param1 AND name = '' AND status = :param2",
64
                [1 => ':param1', 2 => ':param2'],
65
            ],
66
        ];
67
    }
68
69
    /**
70
     * @param mixed[] $expectedOutputParamsMap
71
     *
72
     * @dataProvider dataConvertPositionalToNamedParameters
73
     */
74
    public function testConvertPositionalToNamedParameters(string $inputSQL, string $expectedOutputSQL, array $expectedOutputParamsMap) : void
75
    {
76
        [$statement, $params] = OCI8Statement::convertPositionalToNamedPlaceholders($inputSQL);
0 ignored issues
show
Bug introduced by
The variable $statement does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The variable $params does not exist. Did you mean $expectedOutputParamsMap?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
77
78
        self::assertEquals($expectedOutputSQL, $statement);
79
        self::assertEquals($expectedOutputParamsMap, $params);
0 ignored issues
show
Bug introduced by
The variable $params does not exist. Did you mean $expectedOutputParamsMap?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
80
    }
81
}
82