Skip to content

Commit

Permalink
Merge pull request #5848 from derrabus/bugfix/driver-manager-test
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabus authored Dec 31, 2022
2 parents fd8764f + fd6609f commit 186a3fb
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions tests/DriverManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use function in_array;
use function is_array;

/** @psalm-import-type Params from DriverManager */
class DriverManagerTest extends TestCase
{
use VerifyDeprecations;
Expand Down Expand Up @@ -113,6 +114,7 @@ public function testDatabaseUrlPrimaryReplica(): void
'wrapperClass' => PrimaryReadReplicaConnection::class,
];

$this->expectDeprecationWithIdentifier('https://github.com/doctrine/dbal/pull/5843');
$conn = DriverManager::getConnection($options);

$params = $conn->getParams();
Expand Down Expand Up @@ -146,8 +148,8 @@ public function testDatabaseUrlPrimaryReplica(): void
}

/**
* @param mixed $url
* @param mixed $expected
* @param array<string, mixed>|false $expected
* @psalm-param Params|string $url
*
* @dataProvider databaseUrls
*/
Expand All @@ -162,6 +164,8 @@ public function testDatabaseUrlDeprecated($url, $expected): void
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/dbal/pull/5843');
$conn = DriverManager::getConnection($options);

self::assertNotFalse($expected);

$params = $conn->getParams();
foreach ($expected as $key => $value) {
if (in_array($key, ['driver', 'driverClass'], true)) {
Expand All @@ -173,15 +177,22 @@ public function testDatabaseUrlDeprecated($url, $expected): void
}

/**
* @param mixed $url
* @param mixed $expected
* @param array<string, mixed>|string $url
* @param array<string, mixed>|false $expected
*
* @dataProvider databaseUrls
*/
public function testDatabaseUrl($url, $expected): void
{
if (is_array($url)) {
if (isset($url['driverClass'])) {
self::markTestSkipped(
'Legacy test case: Merging driverClass into the parsed parameters has to be done in userland now.',
);
}

['url' => $url] = $options = $url;
unset($options['url']);
} else {
$options = [];
}
Expand All @@ -195,6 +206,8 @@ public function testDatabaseUrl($url, $expected): void

$conn = DriverManager::getConnection($options);

self::assertNotFalse($expected);

$params = $conn->getParams();
foreach ($expected as $key => $value) {
if (in_array($key, ['driver', 'driverClass'], true)) {
Expand All @@ -205,7 +218,11 @@ public function testDatabaseUrl($url, $expected): void
}
}

/** @return array<string, list<mixed>> */
/** @psalm-return array<string, array{
* string|array<string, mixed>,
* array<string, mixed>|false,
* }>
*/
public function databaseUrls(): iterable
{
$driver = $this->createMock(Driver::class);
Expand Down

0 comments on commit 186a3fb

Please sign in to comment.