Skip to content

Commit

Permalink
Make sure default datasource is not used for mock
Browse files Browse the repository at this point in the history
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'.
  • Loading branch information
kulltc committed Feb 27, 2015
1 parent bc4bca9 commit a7c2f26
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/Cake/Test/Case/TestSuite/CakeTestCaseTest.php
Expand Up @@ -414,7 +414,7 @@ public function testGetMockForModel() {
)
), App::RESET);
$Post = $this->getMockForModel('Post');

$this->assertEquals('test', $Post->useDbConfig);
$this->assertInstanceOf('Post', $Post);
$this->assertNull($Post->save(array()));
$this->assertNull($Post->find('all'));
Expand Down
8 changes: 4 additions & 4 deletions lib/Cake/TestSuite/CakeTestCase.php
Expand Up @@ -732,12 +732,12 @@ public function getMockForModel($model, $methods = array(), $config = array()) {
$mock = $this->getMock($name, $methods, array($config));

$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)) {
$mock->setDataSource('test_' . $mock->useDbConfig);
} else {
$mock->useDbConfig = 'test';
$mock->setDataSource('test');
}

ClassRegistry::removeObject($name);
Expand Down

0 comments on commit a7c2f26

Please sign in to comment.