|
|
@@ -17,53 +17,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
|
|
|
*/
|
|
|
class TestCacheStaticConfig
|
|
|
@@ -179,142 +132,6 @@ class StaticConfigTraitTest extends TestCase
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 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
|
|
|
*
|
|
|
* @return void
|