diff --git a/src/Core/StaticConfigTrait.php b/src/Core/StaticConfigTrait.php index 9cad8477a63..268dcc015a2 100644 --- a/src/Core/StaticConfigTrait.php +++ b/src/Core/StaticConfigTrait.php @@ -237,7 +237,7 @@ public static function configured() * * @param string $dsn The DSN string to convert to a configuration array * @return array The configuration array to be stored after parsing the DSN - * @throws \InvalidArgumentException If not passed a string + * @throws \InvalidArgumentException If not passed a string, or passed an invalid string */ public static function parseDsn($dsn) { @@ -255,7 +255,7 @@ public static function parseDsn($dsn) preg_match($pattern, $dsn, $parsed); if (empty($parsed)) { - return false; + throw new InvalidArgumentException("The DSN string '{$dsn}' could not be parsed."); } foreach ($parsed as $k => $v) { if (is_int($k)) { diff --git a/tests/TestCase/Datasource/ConnectionManagerTest.php b/tests/TestCase/Datasource/ConnectionManagerTest.php index 6ec762aaf3d..93fa984e462 100644 --- a/tests/TestCase/Datasource/ConnectionManagerTest.php +++ b/tests/TestCase/Datasource/ConnectionManagerTest.php @@ -397,6 +397,18 @@ public function testParseDsn($dsn, $expected) $this->assertEquals($expected, $result); } + /** + * Test parseDsn invalid. + * + * @expectedException InvalidArgumentException + * @expectedExceptionMessage The DSN string 'bagof:nope' could not be parsed. + * @return void + */ + public function testParseDsnInvalid() + { + $result = ConnectionManager::parseDsn('bagof:nope'); + } + /** * Tests that directly setting an instance in a config, will not return a different * instance later on