Skip to content

Commit

Permalink
Add a test
Browse files Browse the repository at this point in the history
  • Loading branch information
dakota committed Jan 23, 2017
1 parent e8baecd commit 2f2cbbd
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions tests/TestCase/Datasource/ConnectionManagerTest.php
Expand Up @@ -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'];
}
}

/**
Expand Down Expand Up @@ -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.