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
|
|
|
|