Skip to content
Permalink
Browse files

Move ConnectionManager tests with the other tests for that class

Remove the duplicate stub code and move the tests for ConnectionManager
code with the rest of that class' tests.
  • Loading branch information...
markstory committed Aug 9, 2017
1 parent 2b73b0a commit f5823406b4e4cc3d98acd20a47682300af03e5e2
Showing with 136 additions and 183 deletions.
  1. +0 −183 tests/TestCase/Core/StaticConfigTraitTest.php
  2. +136 −0 tests/TestCase/Datasource/ConnectionManagerTest.php
@@ -16,53 +16,6 @@
use Cake\Core\StaticConfigTrait;
use Cake\TestSuite\TestCase;
/**
* TestConnectionManagerStaticConfig
*/
class TestConnectionManagerStaticConfig
{
use StaticConfigTrait {
parseDsn as protected _parseDsn;
}
/**
* Parse a DSN
*
* @param string $config The config to parse.
* @return array
*/
public static function parseDsn($config = null)
{
$config = static::_parseDsn($config);
if (isset($config['path']) && empty($config['database'])) {
$config['database'] = substr($config['path'], 1);
}
if (empty($config['driver'])) {
$config['driver'] = $config['className'];
$config['className'] = 'Cake\Database\Connection';
}
unset($config['path']);
return $config;
}
/**
* Database driver class map.
*
* @var array
*/
protected static $_dsnClassMap = [
'mysql' => 'Cake\Database\Driver\Mysql',
'postgres' => 'Cake\Database\Driver\Postgres',
'sqlite' => 'Cake\Database\Driver\Sqlite',
'sqlserver' => 'Cake\Database\Driver\Sqlserver',
];
}
/**
* TestCacheStaticConfig
*/
@@ -178,142 +131,6 @@ public function testParseBadType()
$className::parseDsn(['url' => 'http://:80']);
}
/**
* Tests parsing different DSNs
*
* @return void
*/
public function testCustomParseDsn()
{
$dsn = 'mysql://localhost:3306/database';
$expected = [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Mysql',
'host' => 'localhost',
'database' => 'database',
'port' => 3306,
'scheme' => 'mysql',
];
$this->assertEquals($expected, TestConnectionManagerStaticConfig::parseDsn($dsn));
$dsn = 'mysql://user:password@localhost:3306/database';
$expected = [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Mysql',
'host' => 'localhost',
'password' => 'password',
'database' => 'database',
'port' => 3306,
'scheme' => 'mysql',
'username' => 'user',
];
$this->assertEquals($expected, TestConnectionManagerStaticConfig::parseDsn($dsn));
$dsn = 'sqlite:///:memory:';
$expected = [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Sqlite',
'database' => ':memory:',
'scheme' => 'sqlite',
];
$this->assertEquals($expected, TestConnectionManagerStaticConfig::parseDsn($dsn));
$dsn = 'sqlite:////absolute/path';
$expected = [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Sqlite',
'database' => '/absolute/path',
'scheme' => 'sqlite',
];
$this->assertEquals($expected, TestConnectionManagerStaticConfig::parseDsn($dsn));
$dsn = 'sqlite:///?database=:memory:';
$expected = [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Sqlite',
'database' => ':memory:',
'scheme' => 'sqlite',
];
$this->assertEquals($expected, TestConnectionManagerStaticConfig::parseDsn($dsn));
$dsn = 'sqlserver://sa:Password12!@.\SQL2012SP1/cakephp?MultipleActiveResultSets=false';
$expected = [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Sqlserver',
'host' => '.\SQL2012SP1',
'MultipleActiveResultSets' => false,
'password' => 'Password12!',
'database' => 'cakephp',
'scheme' => 'sqlserver',
'username' => 'sa',
];
$this->assertEquals($expected, TestConnectionManagerStaticConfig::parseDsn($dsn));
}
/**
* Tests className/driver value setting
*
* @return void
*/
public function testParseDsnClassnameDriver()
{
$dsn = 'mysql://localhost:3306/database';
$expected = [
'className' => 'Cake\Database\Connection',
'database' => 'database',
'driver' => 'Cake\Database\Driver\Mysql',
'host' => 'localhost',
'port' => 3306,
'scheme' => 'mysql',
];
$this->assertEquals($expected, TestConnectionManagerStaticConfig::parseDsn($dsn));
$dsn = 'mysql://user:password@localhost:3306/database';
$expected = [
'className' => 'Cake\Database\Connection',
'database' => 'database',
'driver' => 'Cake\Database\Driver\Mysql',
'host' => 'localhost',
'password' => 'password',
'port' => 3306,
'scheme' => 'mysql',
'username' => 'user',
];
$this->assertEquals($expected, TestConnectionManagerStaticConfig::parseDsn($dsn));
$dsn = 'mysql://localhost/database?className=Custom\Driver';
$expected = [
'className' => 'Cake\Database\Connection',
'database' => 'database',
'driver' => 'Custom\Driver',
'host' => 'localhost',
'scheme' => 'mysql',
];
$this->assertEquals($expected, TestConnectionManagerStaticConfig::parseDsn($dsn));
$dsn = 'mysql://localhost:3306/database?className=Custom\Driver';
$expected = [
'className' => 'Cake\Database\Connection',
'database' => 'database',
'driver' => 'Custom\Driver',
'host' => 'localhost',
'scheme' => 'mysql',
'port' => 3306,
];
$this->assertEquals($expected, TestConnectionManagerStaticConfig::parseDsn($dsn));
$dsn = 'Cake\Database\Connection://localhost:3306/database?driver=Cake\Database\Driver\Mysql';
$expected = [
'className' => 'Cake\Database\Connection',
'database' => 'database',
'driver' => 'Cake\Database\Driver\Mysql',
'host' => 'localhost',
'scheme' => 'Cake\Database\Connection',
'port' => 3306,
];
$this->assertEquals($expected, TestConnectionManagerStaticConfig::parseDsn($dsn));
}
/**
* Tests parsing querystring values
*
@@ -284,6 +284,142 @@ public function testParseDsn()
$this->assertEquals($expected, $result);
}
/**
* Tests parsing different DSNs
*
* @return void
*/
public function testParseDsnCustom()
{
$dsn = 'mysql://localhost:3306/database';
$expected = [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Mysql',
'host' => 'localhost',
'database' => 'database',
'port' => 3306,
'scheme' => 'mysql',
];
$this->assertEquals($expected, ConnectionManager::parseDsn($dsn));
$dsn = 'mysql://user:password@localhost:3306/database';
$expected = [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Mysql',
'host' => 'localhost',
'password' => 'password',
'database' => 'database',
'port' => 3306,
'scheme' => 'mysql',
'username' => 'user',
];
$this->assertEquals($expected, ConnectionManager::parseDsn($dsn));
$dsn = 'sqlite:///:memory:';
$expected = [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Sqlite',
'database' => ':memory:',
'scheme' => 'sqlite',
];
$this->assertEquals($expected, ConnectionManager::parseDsn($dsn));
$dsn = 'sqlite:////absolute/path';
$expected = [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Sqlite',
'database' => '/absolute/path',
'scheme' => 'sqlite',
];
$this->assertEquals($expected, ConnectionManager::parseDsn($dsn));
$dsn = 'sqlite:///?database=:memory:';
$expected = [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Sqlite',
'database' => ':memory:',
'scheme' => 'sqlite',
];
$this->assertEquals($expected, ConnectionManager::parseDsn($dsn));
$dsn = 'sqlserver://sa:Password12!@.\SQL2012SP1/cakephp?MultipleActiveResultSets=false';
$expected = [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Sqlserver',
'host' => '.\SQL2012SP1',
'MultipleActiveResultSets' => false,
'password' => 'Password12!',
'database' => 'cakephp',
'scheme' => 'sqlserver',
'username' => 'sa',
];
$this->assertEquals($expected, ConnectionManager::parseDsn($dsn));
}
/**
* Tests className/driver value setting
*
* @return void
*/
public function testParseDsnClassnameDriver()
{
$dsn = 'mysql://localhost:3306/database';
$expected = [
'className' => 'Cake\Database\Connection',
'database' => 'database',
'driver' => 'Cake\Database\Driver\Mysql',
'host' => 'localhost',
'port' => 3306,
'scheme' => 'mysql',
];
$this->assertEquals($expected, ConnectionManager::parseDsn($dsn));
$dsn = 'mysql://user:password@localhost:3306/database';
$expected = [
'className' => 'Cake\Database\Connection',
'database' => 'database',
'driver' => 'Cake\Database\Driver\Mysql',
'host' => 'localhost',
'password' => 'password',
'port' => 3306,
'scheme' => 'mysql',
'username' => 'user',
];
$this->assertEquals($expected, ConnectionManager::parseDsn($dsn));
$dsn = 'mysql://localhost/database?className=Custom\Driver';
$expected = [
'className' => 'Cake\Database\Connection',
'database' => 'database',
'driver' => 'Custom\Driver',
'host' => 'localhost',
'scheme' => 'mysql',
];
$this->assertEquals($expected, ConnectionManager::parseDsn($dsn));
$dsn = 'mysql://localhost:3306/database?className=Custom\Driver';
$expected = [
'className' => 'Cake\Database\Connection',
'database' => 'database',
'driver' => 'Custom\Driver',
'host' => 'localhost',
'scheme' => 'mysql',
'port' => 3306,
];
$this->assertEquals($expected, ConnectionManager::parseDsn($dsn));
$dsn = 'Cake\Database\Connection://localhost:3306/database?driver=Cake\Database\Driver\Mysql';
$expected = [
'className' => 'Cake\Database\Connection',
'database' => 'database',
'driver' => 'Cake\Database\Driver\Mysql',
'host' => 'localhost',
'scheme' => 'Cake\Database\Connection',
'port' => 3306,
];
$this->assertEquals($expected, ConnectionManager::parseDsn($dsn));
}
/**
* Tests that directly setting an instance in a config, will not return a different
* instance later on

0 comments on commit f582340

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.