-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
use function in_array; | ||
use function is_array; | ||
|
||
/** @psalm-import-type Params from DriverManager */ | ||
class DriverManagerTest extends TestCase | ||
{ | ||
use VerifyDeprecations; | ||
|
@@ -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(); | ||
|
@@ -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 | ||
*/ | ||
|
@@ -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)) { | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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']); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
} else { | ||
$options = []; | ||
} | ||
|
@@ -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)) { | ||
|
@@ -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); | ||
|
There was a problem hiding this comment.
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.