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 71 72 73 74 75
|
<?php
declare(strict_types=1);
namespace Doctrine\DBAL\Tests\Functional\Driver\Mysqli;
use Doctrine\DBAL\Driver\Exception;
use Doctrine\DBAL\Driver\Mysqli\Connection;
use Doctrine\DBAL\Driver\Mysqli\Driver;
use Doctrine\DBAL\Tests\FunctionalTestCase;
use Doctrine\DBAL\Tests\TestUtil;
use function array_merge;
use const MYSQLI_OPT_CONNECT_TIMEOUT;
/** @require extension mysqli */
class ConnectionTest extends FunctionalTestCase
{
protected function setUp(): void
{
if (TestUtil::isDriverOneOf('mysqli')) {
return;
}
self::markTestSkipped('This test requires the mysqli driver.');
}
public function testSupportedDriverOptions(): void
{
$this->expectNotToPerformAssertions();
$this->getConnection([MYSQLI_OPT_CONNECT_TIMEOUT => 1]);
}
public function testUnsupportedDriverOption(): void
{
$this->expectException(Exception::class);
$this->getConnection([12345 => 'world']);
}
public function testInvalidCharset(): void
{
$params = TestUtil::getConnectionParams();
$this->expectException(Exception::class);
(new Driver())->connect(
array_merge(
$params,
['charset' => 'invalid'],
),
);
}
/** @param array<string, mixed> $driverOptions */
private function getConnection(array $driverOptions): Connection
{
$params = TestUtil::getConnectionParams();
if (isset($params['driverOptions'])) {
// Currently, MySQLi driver options may be either numeric MYSQLI_* keys
// or the {@link Connection::OPTION_FLAGS} string key.
// The options should be merged using array union instead of array_merge()
// to preserve the numeric keys.
$driverOptions += $params['driverOptions'];
}
return (new Driver())->connect(
array_merge(
$params,
['driverOptions' => $driverOptions],
),
);
}
}
|