Skip to content
Permalink
Browse files

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'.
  • Loading branch information...
kulltc committed Feb 27, 2015
1 parent bc4bca9 commit a7c2f26599e57d24b4294f5464014eaff5c71e1c
Showing with 5 additions and 5 deletions.
  1. +1 −1 lib/Cake/Test/Case/TestSuite/CakeTestCaseTest.php
  2. +4 −4 lib/Cake/TestSuite/CakeTestCase.php
@@ -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'));
@@ -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);

0 comments on commit a7c2f26

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