Skip to content
Permalink
Browse files

Add a test

  • Loading branch information...
dakota committed Jan 23, 2017
1 parent e8baecd commit 2f2cbbd8cce29ac6170e24bee94919dc20198612
Showing with 61 additions and 0 deletions.
  1. +61 −0 tests/TestCase/Datasource/ConnectionManagerTest.php
@@ -17,6 +17,41 @@
class FakeConnection
{
protected $_config = [];
/**
* Constructor.
*
* @param array $config configuration for connecting to database
*/
public function __construct($config)
{
$this->_config = $config;
}
/**
* Returns the set config
*
* @return array
*/
public function config()
{
return $this->_config;
}
/**
* Returns the set name
*
* @return string
*/
public function configName()
{
if (empty($this->_config['name'])) {
return '';
}
return $this->_config['name'];
}
}
/**
@@ -279,4 +314,30 @@ public function testConfigWithCallable()
ConnectionManager::config('test_variant', $callable);
$this->assertSame($connection, ConnectionManager::get('test_variant'));
}
/**
* Tests that setting a config will also correctly set the name for the connection
*
* @return void
*/
public function testSetConfigName()
{
//Set with explicit name
ConnectionManager::config('test_variant', [
'className' => __NAMESPACE__ . '\FakeConnection',
'database' => ':memory:'
]);
$result = ConnectionManager::get('test_variant');
$this->assertSame('test_variant', $result->configName());
ConnectionManager::drop('test_variant');
ConnectionManager::config([
'test_variant' => [
'className' => __NAMESPACE__ . '\FakeConnection',
'database' => ':memory:'
]
]);
$result = ConnectionManager::get('test_variant');
$this->assertSame('test_variant', $result->configName());
}
}

0 comments on commit 2f2cbbd

Please sign in to comment.
You can’t perform that action at this time.