From fd6609fe2e84a08b13f7ff3827bd389329d05426 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Sat, 31 Dec 2022 11:42:24 +0100 Subject: [PATCH] Fix test cases for URL parsing --- tests/DriverManagerTest.php | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/tests/DriverManagerTest.php b/tests/DriverManagerTest.php index 9df7ee534ba..7c493fd8fa1 100644 --- a/tests/DriverManagerTest.php +++ b/tests/DriverManagerTest.php @@ -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|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 $url + * @param array|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 = []; } @@ -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> */ + /** @psalm-return array, + * array|false, + * }> + */ public function databaseUrls(): iterable { $driver = $this->createMock(Driver::class);