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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
<?php
declare(strict_types=1);
namespace Doctrine\DBAL\Tests\Driver\AbstractOracleDriver;
use Doctrine\DBAL\Driver\AbstractOracleDriver\EasyConnectString;
use Doctrine\Deprecations\PHPUnit\VerifyDeprecations;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class EasyConnectStringTest extends TestCase
{
use VerifyDeprecations;
/** @param mixed[] $params */
#[DataProvider('connectionParametersProvider')]
public function testFromConnectionParameters(array $params, string $expected): void
{
$string = EasyConnectString::fromConnectionParameters($params);
self::assertSame($expected, (string) $string);
}
/** @return iterable<string, array<int, mixed>> */
public static function connectionParametersProvider(): iterable
{
return [
'empty-params' => [[],''],
'common-params' => [
[
'host' => 'oracle.example.com',
'port' => 1521,
'dbname' => 'XE',
],
'(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=oracle.example.com)(PORT=1521))(CONNECT_DATA=(SID=XE)))',
],
'no-db-name' => [
['host' => 'localhost'],
'(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))',
],
'service' => [
[
'host' => 'localhost',
'port' => 1521,
'service' => true,
'servicename' => 'BILLING',
],
'(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))'
. '(CONNECT_DATA=(SERVICE_NAME=BILLING)))',
],
'advanced-params' => [
[
'host' => 'localhost',
'port' => 41521,
'dbname' => 'XE',
'instancename' => 'SALES',
'pooled' => true,
],
'(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=41521))'
. '(CONNECT_DATA=(SID=XE)(INSTANCE_NAME=SALES)(SERVER=POOLED)))',
],
'tcps-params' => [
[
'host' => 'localhost',
'port' => 41521,
'dbname' => 'XE',
'instancename' => 'SALES',
'pooled' => true,
'driverOptions' => ['protocol' => 'TCPS'],
],
'(DESCRIPTION=(ADDRESS=(PROTOCOL=TCPS)(HOST=localhost)(PORT=41521))'
. '(CONNECT_DATA=(SID=XE)(INSTANCE_NAME=SALES)(SERVER=POOLED)))',
],
];
}
/** @param array<string, mixed> $parameters */
#[DataProvider('getConnectionParameters')]
public function testParameterDeprecation(
array $parameters,
string $expectedConnectString,
bool $expectDeprecation,
): void {
if ($expectDeprecation) {
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/dbal/pull/7042');
} else {
$this->expectNoDeprecationWithIdentifier('https://github.com/doctrine/dbal/pull/7042');
}
$string = EasyConnectString::fromConnectionParameters($parameters);
self::assertSame($expectedConnectString, (string) $string);
}
/** @return iterable<string, array{array<string, mixed>, string, bool}> */
public static function getConnectionParameters(): iterable
{
$serviceNameString = '(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))'
. '(CONNECT_DATA=(SERVICE_NAME=BILLING)))';
yield 'dbname-and-service' => [
[
'host' => 'localhost',
'port' => 1521,
'dbname' => 'BILLING',
'service' => true,
],
$serviceNameString,
true,
];
yield 'servicename' => [
[
'host' => 'localhost',
'port' => 1521,
'servicename' => 'BILLING',
],
$serviceNameString,
false,
];
}
}
|