Failed Conditions
Pull Request — master (#3033)
by Aleksey
13:48
created

DriverTest::testConnectionOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
namespace Doctrine\Tests\DBAL\Driver\PDOSqlsrv;
4
5
use Doctrine\DBAL\Driver\PDOSqlsrv\Driver;
6
use Doctrine\Tests\DBAL\Driver\AbstractSQLServerDriverTest;
7
use PDO;
8
9
class DriverTest extends AbstractSQLServerDriverTest
10
{
11
    public function testReturnsName()
12
    {
13
        self::assertSame('pdo_sqlsrv', $this->driver->getName());
14
    }
15
16
    protected function createDriver()
17
    {
18
        return new Driver();
19
    }
20
21
    public function testConnectionOptions()
22
    {
23
        $connection = $this->getConnection([
24
            'APP' => 'APP_NAME',
25
            'WSID' => 'WSID_NAME',
26
        ]);
27
28
        $result = $connection->query("select APP_NAME() as app,  HOST_NAME() as host")->fetch();
29
30
        self::assertSame('APP_NAME', $result['app']);
31
        self::assertSame('WSID_NAME', $result['host']);
32
    }
33
34
    public function testDriverOptions()
35
    {
36
        $connection = $this->getConnection([
37
            PDO::ATTR_CASE => PDO::CASE_UPPER,
38
            PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
39
        ]);
40
41
        self::assertSame(PDO::CASE_UPPER, $connection->getAttribute(PDO::ATTR_CASE));
42
        self::assertSame(PDO::FETCH_ASSOC, $connection->getAttribute(PDO::ATTR_DEFAULT_FETCH_MODE));
43
    }
44
45
    private function getConnection($driverOptions) {
46
        return $this->createDriver()->connect(
47
            array(
48
                'host' => $GLOBALS['db_host'],
49
                'port' => $GLOBALS['db_port']
50
            ),
51
            $GLOBALS['db_username'],
52
            $GLOBALS['db_password'],
53
            $driverOptions
54
        );
55
    }
56
}
57