Skip to content

Commit

Permalink
Add exception on parse failure.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Aug 11, 2017
1 parent f13b003 commit edcb3dc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Core/StaticConfigTrait.php
Expand Up @@ -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)
{
Expand All @@ -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)) {
Expand Down
12 changes: 12 additions & 0 deletions tests/TestCase/Datasource/ConnectionManagerTest.php
Expand Up @@ -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
Expand Down

0 comments on commit edcb3dc

Please sign in to comment.