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