Skip to content

Commit

Permalink
Fixed more failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Oct 29, 2014
1 parent 3a1bb52 commit 4be9997
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 27 deletions.
12 changes: 10 additions & 2 deletions src/Core/StaticConfigTrait.php
Expand Up @@ -172,6 +172,14 @@ public static function configured() {
* @return mixed null when adding configuration and an array of configuration data when reading.
*/
public static function parseDsn($dsn) {
if (empty($dsn)) {
return [];
}

if (!is_string($dsn)) {
return $dsn;
}

if (preg_match("/^([\w\\\]+)/", $dsn, $matches)) {
$scheme = $matches[1];
$dsn = preg_replace("/^([\w\\\]+)/", 'file', $dsn);
Expand All @@ -180,7 +188,7 @@ public static function parseDsn($dsn) {
$parsed = parse_url($dsn);

if ($parsed === false) {
return $config;
return $dsn;
}

$parsed['scheme'] = $scheme;
Expand Down Expand Up @@ -211,7 +219,7 @@ public static function parseDsn($dsn) {
$parsed['password'] = $parsed['pass'];
}

unset($parsed['pass'], $parsed['used']);
unset($parsed['pass'], $parsed['user']);
$parsed = $queryArgs + $parsed;

if (empty($parsed['className']) && method_exists(get_called_class(), 'getClassMap')) {
Expand Down
45 changes: 20 additions & 25 deletions tests/TestCase/Core/StaticConfigTraitTest.php
Expand Up @@ -128,12 +128,7 @@ public function tearDown() {
public function testSimpleParseDsn() {
$klassName = get_class($this->subject);

$this->assertInternalType('string', $klassName::parseDsn(''));
$this->assertEquals('', $klassName::parseDsn(''));

$this->assertInternalType('array', $klassName::parseDsn(['key' => 'value']));
$this->assertEquals(['key' => 'value'], $klassName::parseDsn(['key' => 'value']));

$this->assertSame([], $klassName::parseDsn(''));
$this->assertInternalType('array', $klassName::parseDsn(['url' => 'http://:80']));
$this->assertEquals(['url' => 'http://:80'], $klassName::parseDsn(['url' => 'http://:80']));

Expand All @@ -151,7 +146,7 @@ public function testCustomParseDsn() {
'port' => 3306,
'scheme' => 'mysql',
];
$this->assertEquals($expected, TestConnectionManagerStaticConfig::parseDsn(['url' => $dsn]));
$this->assertEquals($expected, TestConnectionManagerStaticConfig::parseDsn($dsn));

$dsn = 'mysql://user:password@localhost:3306/database';
$expected = [
Expand All @@ -164,7 +159,7 @@ public function testCustomParseDsn() {
'scheme' => 'mysql',
'username' => 'user',
];
$this->assertEquals($expected, TestConnectionManagerStaticConfig::parseDsn(['url' => $dsn]));
$this->assertEquals($expected, TestConnectionManagerStaticConfig::parseDsn($dsn));

$dsn = 'sqlite:///memory:';
$expected = [
Expand All @@ -173,7 +168,7 @@ public function testCustomParseDsn() {
'database' => 'memory:',
'scheme' => 'sqlite',
];
$this->assertEquals($expected, TestConnectionManagerStaticConfig::parseDsn(['url' => $dsn]));
$this->assertEquals($expected, TestConnectionManagerStaticConfig::parseDsn($dsn));

$dsn = 'sqlite:///?database=memory:';
$expected = [
Expand All @@ -182,7 +177,7 @@ public function testCustomParseDsn() {
'database' => 'memory:',
'scheme' => 'sqlite',
];
$this->assertEquals($expected, TestConnectionManagerStaticConfig::parseDsn(['url' => $dsn]));
$this->assertEquals($expected, TestConnectionManagerStaticConfig::parseDsn($dsn));

$dsn = 'sqlserver://sa:Password12!@.\SQL2012SP1/cakephp?MultipleActiveResultSets=false';
$expected = [
Expand All @@ -195,7 +190,7 @@ public function testCustomParseDsn() {
'scheme' => 'sqlserver',
'username' => 'sa',
];
$this->assertEquals($expected, TestConnectionManagerStaticConfig::parseDsn(['url' => $dsn]));
$this->assertEquals($expected, TestConnectionManagerStaticConfig::parseDsn($dsn));
}

/**
Expand All @@ -213,7 +208,7 @@ public function testParseDsnClassnameDriver() {
'port' => 3306,
'scheme' => 'mysql',
];
$this->assertEquals($expected, TestConnectionManagerStaticConfig::parseDsn(['url' => $dsn]));
$this->assertEquals($expected, TestConnectionManagerStaticConfig::parseDsn($dsn));

$dsn = 'mysql://user:password@localhost:3306/database';
$expected = [
Expand All @@ -226,7 +221,7 @@ public function testParseDsnClassnameDriver() {
'scheme' => 'mysql',
'username' => 'user',
];
$this->assertEquals($expected, TestConnectionManagerStaticConfig::parseDsn(['url' => $dsn]));
$this->assertEquals($expected, TestConnectionManagerStaticConfig::parseDsn($dsn));

$dsn = 'mysql://localhost/database?className=Custom\Driver';
$expected = [
Expand All @@ -236,7 +231,7 @@ public function testParseDsnClassnameDriver() {
'host' => 'localhost',
'scheme' => 'mysql',
];
$this->assertEquals($expected, TestConnectionManagerStaticConfig::parseDsn(['url' => $dsn]));
$this->assertEquals($expected, TestConnectionManagerStaticConfig::parseDsn($dsn));

$dsn = 'mysql://localhost:3306/database?className=Custom\Driver';
$expected = [
Expand All @@ -247,7 +242,7 @@ public function testParseDsnClassnameDriver() {
'scheme' => 'mysql',
'port' => 3306,
];
$this->assertEquals($expected, TestConnectionManagerStaticConfig::parseDsn(['url' => $dsn]));
$this->assertEquals($expected, TestConnectionManagerStaticConfig::parseDsn($dsn));

$dsn = 'Cake\Database\Connection://localhost:3306/database?driver=Cake\Database\Driver\Mysql';
$expected = [
Expand All @@ -258,7 +253,7 @@ public function testParseDsnClassnameDriver() {
'scheme' => 'Cake\Database\Connection',
'port' => 3306,
];
$this->assertEquals($expected, TestConnectionManagerStaticConfig::parseDsn(['url' => $dsn]));
$this->assertEquals($expected, TestConnectionManagerStaticConfig::parseDsn($dsn));
}

/**
Expand All @@ -274,7 +269,7 @@ public function testParseDsnQuerystring() {
'scheme' => 'file',
'url' => 'test',
];
$this->assertEquals($expected, TestLogStaticConfig::parseDsn(['url' => $dsn]));
$this->assertEquals($expected, TestLogStaticConfig::parseDsn($dsn));

$dsn = 'file:///?file=debug&key=value';
$expected = [
Expand All @@ -284,7 +279,7 @@ public function testParseDsnQuerystring() {
'path' => '/',
'scheme' => 'file',
];
$this->assertEquals($expected, TestLogStaticConfig::parseDsn(['url' => $dsn]));
$this->assertEquals($expected, TestLogStaticConfig::parseDsn($dsn));

$dsn = 'file:///tmp?file=debug&types[]=notice&types[]=info&types[]=debug';
$expected = [
Expand All @@ -294,7 +289,7 @@ public function testParseDsnQuerystring() {
'scheme' => 'file',
'types' => ['notice', 'info', 'debug'],
];
$this->assertEquals($expected, TestLogStaticConfig::parseDsn(['url' => $dsn]));
$this->assertEquals($expected, TestLogStaticConfig::parseDsn($dsn));

$dsn = 'mail:///?timeout=30&key=true&key2=false&client=null&tls=null';
$expected = [
Expand All @@ -307,7 +302,7 @@ public function testParseDsnQuerystring() {
'timeout' => '30',
'tls' => null,
];
$this->assertEquals($expected, TestEmailStaticConfig::parseDsn(['url' => $dsn]));
$this->assertEquals($expected, TestEmailStaticConfig::parseDsn($dsn));

$dsn = 'mail://true:false@null/1?timeout=30&key=true&key2=false&client=null&tls=null';
$expected = [
Expand All @@ -323,7 +318,7 @@ public function testParseDsnQuerystring() {
'tls' => null,
'username' => 'true',
];
$this->assertEquals($expected, TestEmailStaticConfig::parseDsn(['url' => $dsn]));
$this->assertEquals($expected, TestEmailStaticConfig::parseDsn($dsn));

$dsn = 'mail://user:secret@localhost:25?timeout=30&client=null&tls=null';
$expected = [
Expand All @@ -337,7 +332,7 @@ public function testParseDsnQuerystring() {
'tls' => null,
'username' => 'user',
];
$this->assertEquals($expected, TestEmailStaticConfig::parseDsn(['url' => $dsn]));
$this->assertEquals($expected, TestEmailStaticConfig::parseDsn($dsn));

$dsn = 'file:///?prefix=myapp_cake_core_&serialize=true&duration=%2B2 minutes';
$expected = [
Expand All @@ -348,7 +343,7 @@ public function testParseDsnQuerystring() {
'scheme' => 'file',
'serialize' => true,
];
$this->assertEquals($expected, TestLogStaticConfig::parseDsn(['url' => $dsn]));
$this->assertEquals($expected, TestLogStaticConfig::parseDsn($dsn));
}

/**
Expand All @@ -363,15 +358,15 @@ public function testParseDsnPathSetting() {
'path' => '/',
'scheme' => 'file',
];
$this->assertEquals($expected, TestLogStaticConfig::parseDsn(['url' => $dsn]));
$this->assertEquals($expected, TestLogStaticConfig::parseDsn($dsn));

$dsn = 'file:///?path=/tmp/persistent/';
$expected = [
'className' => 'Cake\Log\Engine\FileLog',
'path' => '/tmp/persistent/',
'scheme' => 'file',
];
$this->assertEquals($expected, TestLogStaticConfig::parseDsn(['url' => $dsn]));
$this->assertEquals($expected, TestLogStaticConfig::parseDsn($dsn));
}

}
Expand Down

0 comments on commit 4be9997

Please sign in to comment.