Completed
Pull Request — master (#3065)
by Laurence
19:52
created

DBAL2369Test   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 110
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 62
dl 0
loc 110
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 25 3
A testSelectOnId() 0 29 1
A testInsert() 0 17 1
A testSelectOnParameter() 0 31 1
1
<?php
2
3
namespace Doctrine\Tests\DBAL\Functional\Ticket;
4
5
use Doctrine\DBAL\ParameterType;
6
7
/**
8
 * @group DBAL-2369
9
 */
10
class DBAL2369Test extends \Doctrine\Tests\DbalFunctionalTestCase
11
{
12
    protected function setUp()
13
    {
14
15
        parent::setUp();
16
17
        $platform = $this->_conn->getDatabasePlatform()->getName();
18
19
        if (!in_array($platform, ['sqlsrv', 'mssql'])) {
20
            $this->markTestSkipped('Related to SQLSRV only');
21
        }
22
23
        try {
24
            /* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */
25
            $table = new \Doctrine\DBAL\Schema\Table('interger_string_table');
26
            $table->addColumn('id', 'integer');
27
            $table->addColumn('textfield', 'string');
28
            $table->addColumn('number_as_string_field', 'string');
29
            $table->setPrimaryKey(['id']);
30
31
            $sm = $this->_conn->getSchemaManager();
32
            $sm->createTable($table);
33
        } catch (\Exception $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
34
35
        }
36
        $this->_conn->exec($this->_conn->getDatabasePlatform()->getTruncateTableSQL('interger_string_table'));
37
    }
38
39
    public function testInsert()
40
    {
41
        $ret = $this->_conn->insert(
42
            'interger_string_table',
43
            [
44
                'id'                     => 1,
45
                'textfield'              => 'test',
46
                'number_as_string_field' => '2',
47
            ],
48
            [
49
                ParameterType::INTEGER,
50
                ParameterType::STRING,
51
                ParameterType::STRING,
52
            ]
53
        );
54
55
        self::assertEquals(1, $ret);
56
    }
57
58
    public function testSelectOnId()
59
    {
60
        $this->_conn->insert(
61
            'interger_string_table',
62
            [
63
                'id'                     => 1,
64
                'textfield'              => 'test',
65
                'number_as_string_field' => '2',
66
            ],
67
            [
68
                ParameterType::INTEGER,
69
                ParameterType::STRING,
70
                ParameterType::STRING,
71
            ]
72
        );
73
74
        $query = 'SELECT id, textfield, number_as_string_field FROM interger_string_table WHERE id = ?';
75
        $stmt  = $this->_conn->prepare($query);
76
        $stmt->bindValue(1, 1, ParameterType::STRING);
77
        $stmt->execute();
78
79
        $ret = $stmt->fetch();
80
81
        self::assertArrayHasKey('id', $ret);
82
        self::assertEquals($ret['id'], 1);
83
        self::assertArrayHasKey('textfield', $ret);
84
        self::assertEquals($ret['textfield'], 'test');
85
        self::assertArrayHasKey('number_as_string_field', $ret);
86
        self::assertEquals($ret['number_as_string_field'], '2');
87
    }
88
89
    public function testSelectOnParameter()
90
    {
91
        $this->_conn->insert(
92
            'interger_string_table',
93
            [
94
                'id'                     => 2,
95
                'textfield'              => 'test2',
96
                'number_as_string_field' => '3',
97
            ],
98
            [
99
                ParameterType::INTEGER,
100
                ParameterType::STRING,
101
                ParameterType::STRING,
102
            ]
103
        );
104
105
        $query = 'SELECT id, textfield, number_as_string_field FROM interger_string_table WHERE number_as_string_field = ?';
106
        $stmt  = $this->_conn->prepare($query);
107
        $stmt->bindValue(1, (int) 3, ParameterType::STRING);
108
        $stmt->execute();
109
110
        $ret = $stmt->fetch();
111
112
//        var_dump($ret);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
113
114
        self::assertArrayHasKey('id', $ret);
115
        self::assertEquals($ret['id'], 2);
116
        self::assertArrayHasKey('textfield', $ret);
117
        self::assertEquals($ret['textfield'], 'test2');
118
        self::assertArrayHasKey('number_as_string_field', $ret);
119
        self::assertEquals($ret['number_as_string_field'], '3');
120
    }
121
}
122