Browse Source

Add exception on parse failure.

Mark Story 8 years ago
parent
commit
edcb3dc629

+ 2 - 2
src/Core/StaticConfigTrait.php

@@ -237,7 +237,7 @@ trait StaticConfigTrait
      *
      * @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 @@ trait StaticConfigTrait
         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)) {

+ 12 - 0
tests/TestCase/Datasource/ConnectionManagerTest.php

@@ -398,6 +398,18 @@ class ConnectionManagerTest extends TestCase
     }
 
     /**
+     * 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
      *