Completed
Pull Request — develop (#3485)
by Sergei
63:35
created

ConnectionTest::testDriverOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Doctrine\Tests\DBAL\Functional\Driver\Mysqli;
4
5
use Doctrine\DBAL\Driver\Mysqli\Driver;
6
use Doctrine\DBAL\Driver\Mysqli\MysqliConnection;
7
use Doctrine\DBAL\Driver\Mysqli\MysqliException;
8
use Doctrine\Tests\DbalFunctionalTestCase;
9
use const MYSQLI_OPT_CONNECT_TIMEOUT;
10
use function extension_loaded;
11
12
class ConnectionTest extends DbalFunctionalTestCase
13
{
14
    protected function setUp() : void
15
    {
16
        if (! extension_loaded('mysqli')) {
17
            $this->markTestSkipped('mysqli is not installed.');
18
        }
19
20
        parent::setUp();
21
22
        if ($this->connection->getDriver() instanceof Driver) {
23
            return;
24
        }
25
26
        $this->markTestSkipped('MySQLi only test.');
27
    }
28
29
    protected function tearDown() : void
30
    {
31
        parent::tearDown();
32
    }
33
34
    public function testDriverOptions()
35
    {
36
        $driverOptions = [MYSQLI_OPT_CONNECT_TIMEOUT => 1];
37
38
        $connection = $this->getConnection($driverOptions);
39
        self::assertInstanceOf(MysqliConnection::class, $connection);
40
    }
41
42
    public function testUnsupportedDriverOption()
43
    {
44
        $this->expectException(MysqliException::class);
45
46
        $this->getConnection(['hello' => 'world']); // use local infile
47
    }
48
49
    /**
50
     * @param mixed[] $driverOptions
51
     */
52
    private function getConnection(array $driverOptions)
53
    {
54
        return new MysqliConnection(
55
            [
56
                'host' => $GLOBALS['db_host'],
57
                'dbname' => $GLOBALS['db_name'],
58
                'port' => $GLOBALS['db_port'],
59
            ],
60
            $GLOBALS['db_username'],
61
            $GLOBALS['db_password'],
62
            $driverOptions
63
        );
64
    }
65
}
66