Failed Conditions
Push — 3.0.x ( 66f057...14f5f1 )
by Sergei
36s queued 17s
created

ConnectionTest::testSupportedDriverOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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