Failed Conditions
Pull Request — master (#3033)
by Aleksey
14:15
created

DriverTest::getConnection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 1
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
    /**
58
     * @throws \PHPUnit_Framework_SkippedTestError
59
     */
60
    private function skipWhenNotUsingPdoSqlsrv()
0 ignored issues
show
Unused Code introduced by
The method skipWhenNotUsingPdoSqlsrv() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
61
    {
62
        if (! (isset($GLOBALS['db_type']) && $GLOBALS['db_type'] === 'pdo_sqlsrv')) {
63
            $this->markTestSkipped('Test enabled only when using pdo_sqlsrv specific phpunit.xml');
64
        }
65
    }
66
}
67