Passed
Push — amo/scrutinizer-new-engine ( 927449 )
by Andreas
10:16
created

ConnectionTestCase   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 29
c 1
b 0
f 0
dl 0
loc 60
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testStatement() 0 6 1
A testGetDriver() 0 3 1
A testGetConnection() 0 4 1
A tearDown() 0 4 1
A testBasicAuthConnection() 0 15 1
A testConnect() 0 9 1
A setUp() 0 4 1
1
<?php
2
/**
3
 * Licensed to CRATE Technology GmbH("Crate") under one or more contributor
4
 * license agreements.  See the NOTICE file distributed with this work for
5
 * additional information regarding copyright ownership.  Crate licenses
6
 * this file to you under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.  You may
8
 * obtain a copy of the License at
9
 *
10
 * http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
15
 * License for the specific language governing permissions and limitations
16
 * under the License.
17
 *
18
 * However, if you have executed another commercial license agreement
19
 * with Crate these terms will supersede the license and you may use the
20
 * software solely pursuant to the terms of the relevant commercial agreement.
21
 */
22
namespace Crate\Test\DBAL\Functional;
23
24
use Crate\Test\DBAL\DBALFunctionalTestCase;
25
use Crate\PDO\PDO;
26
27
class ConnectionTestCase extends DBALFunctionalTestCase
28
{
29
    public function setUp() : void
30
    {
31
        $this->resetSharedConn();
32
        parent::setUp();
33
    }
34
35
    public function tearDown() : void
36
    {
37
        parent::tearDown();
38
        $this->resetSharedConn();
39
    }
40
41
    public function testBasicAuthConnection()
42
    {
43
        $auth = ['crate', 'secret'];
44
        $params = array(
45
            'driverClass' => 'Crate\DBAL\Driver\PDOCrate\Driver',
46
            'host' => 'localhost',
47
            'port' => 4200,
48
            'user' => $auth[0],
49
            'password' => $auth[1],
50
        );
51
        $conn = \Doctrine\DBAL\DriverManager::getConnection($params);
52
        $this->assertEquals($auth[0], $conn->getUsername());
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\DBAL\Connection::getUsername() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

52
        $this->assertEquals($auth[0], /** @scrutinizer ignore-deprecated */ $conn->getUsername());
Loading history...
53
        $this->assertEquals($auth[1], $conn->getPassword());
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\DBAL\Connection::getPassword() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

53
        $this->assertEquals($auth[1], /** @scrutinizer ignore-deprecated */ $conn->getPassword());
Loading history...
54
        $auth_attr = $conn->getWrappedConnection()->getAttribute(PDO::CRATE_ATTR_HTTP_BASIC_AUTH);
0 ignored issues
show
Bug introduced by
The method getAttribute() does not exist on Doctrine\DBAL\Driver\Connection. It seems like you code against a sub-type of Doctrine\DBAL\Driver\Connection such as Doctrine\DBAL\Driver\PDOConnection. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

54
        $auth_attr = $conn->getWrappedConnection()->/** @scrutinizer ignore-call */ getAttribute(PDO::CRATE_ATTR_HTTP_BASIC_AUTH);
Loading history...
55
        $this->assertEquals($auth_attr, $auth);
56
    }
57
58
    public function testGetConnection()
59
    {
60
      $this->assertInstanceOf('Doctrine\DBAL\Connection', $this->_conn);
61
      $this->assertInstanceOf('Crate\DBAL\Driver\PDOCrate\PDOConnection', $this->_conn->getWrappedConnection());
62
    }
63
64
    public function testGetDriver()
65
    {
66
        $this->assertInstanceOf('Crate\DBAL\Driver\PDOCrate\Driver', $this->_conn->getDriver());
67
    }
68
69
    public function testStatement()
70
    {
71
        $sql = 'SELECT * FROM sys.cluster';
72
        $stmt = $this->_conn->prepare($sql);
73
        $this->assertInstanceOf('Doctrine\DBAL\Statement', $stmt);
74
        $this->assertInstanceOf('Crate\PDO\PDOStatement', $stmt->getWrappedStatement());
75
76
    }
77
78
    public function testConnect()
79
    {
80
        $this->assertTrue($this->_conn->connect());
81
82
        $stmt = $this->_conn->query('select * from sys.cluster');
83
        $this->assertEquals(1, $stmt->rowCount());
84
85
        $row = $stmt->fetch();
86
        $this->assertEquals('crate', $row['name']);
87
    }
88
89
}
90
91