Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test cases for URL parsing #5848

Merged
merged 1 commit into from
Dec 31, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

URLs for primary/replica have to be parsed in advance as well, so we do get the deprecation here.

$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.',
);
}
Comment on lines +188 to +192
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We currently remove an explicitly configured driver class if the URL has a scheme. That might be unexpected because for all other parameters, it works the other way round. Since with the new parser, the app is in charge of that, we need to skip the corresponding tests.


['url' => $url] = $options = $url;
unset($options['url']);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I don't unset the URL here, it's actually parsed twice which is why the driverClass tests still worked although they shouldn't have. 😓

} 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