Failed Conditions
Pull Request — master (#3033)
by Aleksey
22:10
created

DriverTest::testConnectionOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
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
        $this->skipWhenNotUsingPdoSqlsrv();
24
25
        $connection = $this->getConnection(['APP' => 'APP_NAME']);
26
        $result     = $connection->query('select APP_NAME() as app')->fetch();
27
28
        self::assertSame('APP_NAME', $result['app']);
29
    }
30
31
    public function testDriverOptions()
32
    {
33
        $this->skipWhenNotUsingPdoSqlsrv();
34
35
        $connection = $this->getConnection([PDO::ATTR_CASE => PDO::CASE_UPPER]);
36
37
        self::assertSame(PDO::CASE_UPPER, $connection->getAttribute(PDO::ATTR_CASE));
38
    }
39
40
    private function getConnection($driverOptions)
41
    {
42
        return $this->createDriver()->connect(
43
            [
44
                'host' => $GLOBALS['db_host'],
45
                'port' => $GLOBALS['db_port'],
46
            ],
47
            $GLOBALS['db_username'],
48
            $GLOBALS['db_password'],
49
            $driverOptions
50
        );
51
    }
52
53
    /**
54
     * @throws \PHPUnit_Framework_SkippedTestError
55
     */
56
    private function skipWhenNotUsingPdoSqlsrv()
57
    {
58
        if (isset($GLOBALS['db_type']) && $GLOBALS['db_type'] === 'pdo_sqlsrv') {
59
            return;
60
        }
61
62
        $this->markTestSkipped('Test enabled only when using pdo_sqlsrv specific phpunit.xml');
63
    }
64
}
65