Make sure default datasource is not used for mock

When a non-default datasource is used for a model and no test_ version of
that datasource is available, the getMockForModel method used the
models standard datasource, rahter than 'test'.
This commit is contained in:
KullTC 2015-02-27 15:25:23 +01:00
parent bc4bca9737
commit a7c2f26599
2 changed files with 5 additions and 5 deletions

View file

@ -414,7 +414,7 @@ class CakeTestCaseTest extends CakeTestCase {
) )
), App::RESET); ), App::RESET);
$Post = $this->getMockForModel('Post'); $Post = $this->getMockForModel('Post');
$this->assertEquals('test', $Post->useDbConfig);
$this->assertInstanceOf('Post', $Post); $this->assertInstanceOf('Post', $Post);
$this->assertNull($Post->save(array())); $this->assertNull($Post->save(array()));
$this->assertNull($Post->find('all')); $this->assertNull($Post->find('all'));

View file

@ -732,12 +732,12 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
$mock = $this->getMock($name, $methods, array($config)); $mock = $this->getMock($name, $methods, array($config));
$availableDs = array_keys(ConnectionManager::enumConnectionObjects()); $availableDs = array_keys(ConnectionManager::enumConnectionObjects());
if ($mock->useDbConfig === 'default') {
$mock->useDbConfig = null;
$mock->setDataSource('test');
}
if ($mock->useDbConfig !== 'test' && in_array('test_' . $mock->useDbConfig, $availableDs)) { if ($mock->useDbConfig !== 'test' && in_array('test_' . $mock->useDbConfig, $availableDs)) {
$mock->setDataSource('test_' . $mock->useDbConfig); $mock->setDataSource('test_' . $mock->useDbConfig);
} else {
$mock->useDbConfig = 'test';
$mock->setDataSource('test');
} }
ClassRegistry::removeObject($name); ClassRegistry::removeObject($name);