-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
ConnectionTest.php
70 lines (56 loc) · 1.73 KB
/
ConnectionTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
namespace Doctrine\Tests\DBAL\Functional\Driver\Mysqli;
use Doctrine\DBAL\Driver\Mysqli\Driver;
use Doctrine\DBAL\Driver\Mysqli\MysqliConnection;
use Doctrine\DBAL\Driver\Mysqli\MysqliException;
use Doctrine\Tests\DbalFunctionalTestCase;
use Doctrine\Tests\TestUtil;
use function extension_loaded;
use const MYSQLI_OPT_CONNECT_TIMEOUT;
class ConnectionTest extends DbalFunctionalTestCase
{
protected function setUp() : void
{
if (! extension_loaded('mysqli')) {
$this->markTestSkipped('mysqli is not installed.');
}
parent::setUp();
if ($this->connection->getDriver() instanceof Driver) {
return;
}
$this->markTestSkipped('MySQLi only test.');
}
protected function tearDown() : void
{
parent::tearDown();
}
public function testDriverOptions() : void
{
$driverOptions = [MYSQLI_OPT_CONNECT_TIMEOUT => 1];
$connection = $this->getConnection($driverOptions);
self::assertInstanceOf(MysqliConnection::class, $connection);
}
public function testUnsupportedDriverOption() : void
{
$this->expectException(MysqliException::class);
$this->getConnection(['hello' => 'world']); // use local infile
}
public function testPing() : void
{
$conn = $this->getConnection([]);
self::assertTrue($conn->ping());
}
/**
* @param mixed[] $driverOptions
*/
private function getConnection(array $driverOptions) : MysqliConnection
{
$params = TestUtil::getConnectionParams();
return new MysqliConnection(
$params,
$params['user'] ?? '',
$params['password'] ?? '',
$driverOptions
);
}
}