1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Doctrine\DBAL\Tests\Functional\Driver\Mysqli; |
6
|
|
|
|
7
|
|
|
use Doctrine\DBAL\Driver\Mysqli\Driver; |
8
|
|
|
use Doctrine\DBAL\Driver\Mysqli\MysqliConnection; |
9
|
|
|
use Doctrine\DBAL\Driver\Mysqli\MysqliException; |
10
|
|
|
use Doctrine\DBAL\Tests\FunctionalTestCase; |
11
|
|
|
use function extension_loaded; |
12
|
|
|
use const MYSQLI_OPT_CONNECT_TIMEOUT; |
13
|
|
|
|
14
|
|
|
class ConnectionTest extends FunctionalTestCase |
15
|
|
|
{ |
16
|
|
|
protected function setUp() : void |
17
|
|
|
{ |
18
|
|
|
if (! extension_loaded('mysqli')) { |
19
|
|
|
self::markTestSkipped('mysqli is not installed.'); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
parent::setUp(); |
23
|
|
|
|
24
|
|
|
if ($this->connection->getDriver() instanceof Driver) { |
25
|
|
|
return; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
self::markTestSkipped('MySQLi only test.'); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
protected function tearDown() : void |
32
|
|
|
{ |
33
|
|
|
parent::tearDown(); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function testSupportedDriverOptions() : void |
37
|
|
|
{ |
38
|
|
|
$this->expectNotToPerformAssertions(); |
39
|
|
|
$this->getConnection([MYSQLI_OPT_CONNECT_TIMEOUT => 1]); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function testUnsupportedDriverOption() : void |
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) : MysqliConnection |
53
|
|
|
{ |
54
|
|
|
return new MysqliConnection( |
55
|
|
|
[ |
56
|
|
|
'host' => $GLOBALS['db_host'], |
57
|
|
|
'dbname' => $GLOBALS['db_name'], |
58
|
|
|
'port' => (int) $GLOBALS['db_port'], |
59
|
|
|
], |
60
|
|
|
$GLOBALS['db_username'], |
61
|
|
|
$GLOBALS['db_password'], |
62
|
|
|
$driverOptions |
63
|
|
|
); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|